Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

### Changed

- `Revert Tree String to Text` now only reverts selected text when a selection exists, instead of always reverting the entire file

## [2.0.0] - 2024-12-22

Finally found my vscode market account😭. This version mainly improve configuration names, docs and coding styles, with some breaking changes([!15](https://github.com/aprilandjan/vscode-ascii-tree-generator/pull/15) by [@mahyarmirrashed](https://github.com/mahyarmirrashed)).
Expand Down
30 changes: 21 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,28 @@ export function activate(context: vscode.ExtensionContext) {
);
return;
}
const text = editor.document.getText();

let text: string;
let range: vscode.Range;

if (editor.selection.isEmpty) {
// No selection: revert entire document
text = editor.document.getText();
const firstLine = editor.document.lineAt(0);
const lastLine = editor.document.lineAt(editor.document.lineCount - 1);
range = new vscode.Range(
0,
firstLine.range.start.character,
editor.document.lineCount - 1,
lastLine.range.end.character
);
} else {
// Selection exists: revert only selected text
text = editor.document.getText(editor.selection);
range = editor.selection;
}

const reverted = revertTreeString(text);
const firstLine = editor.document.lineAt(0);
const lastLine = editor.document.lineAt(editor.document.lineCount - 1);
const range = new vscode.Range(
0,
firstLine.range.start.character,
editor.document.lineCount - 1,
lastLine.range.end.character
);
editor.edit((edit) => {
edit.replace(range, reverted);
});
Expand Down