Skip to content

Commit

Permalink
Reset action provider's selection for Vue files
Browse files Browse the repository at this point in the history
Otherwise, the selection is offset twice and we can't refactor.

Closes #1072
  • Loading branch information
nicoespeon committed Oct 23, 2024
1 parent 61a662b commit 61596c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Abracadabra was not working well with Vue files with content above the script tag. This has been fixed and refactorings should work fine again! Thanks @yinluobing and @acabreragnz for reporting 🙏

## [9.4.6]

### Fixed
Expand Down
12 changes: 11 additions & 1 deletion src/editor/adapters/vue-and-svelte-vscode-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class VueAndSvelteVSCodeEditor extends VSCodeEditor {
withSelection(selection: Selection): VueAndSvelteVSCodeEditor {
return new VueAndSvelteVSCodeEditor(
this.editor,
toVSCodeSelection(selection)
// Input selection was offset already. Reset it so we don't do it twice.
toVSCodeSelection(this.resetEditorSelection(selection))
);
}

Expand Down Expand Up @@ -78,6 +79,15 @@ export class VueAndSvelteVSCodeEditor extends VSCodeEditor {
);
}

private resetEditorSelection(selection: Selection): Selection {
const offsetLinesCount = this.toOffsetLinesCount(this.openingTagOffset);

return Selection.fromPositions(
selection.start.addLines(offsetLinesCount),
selection.end.addLines(offsetLinesCount)
);
}

private offsetSelection(selection: Selection): Selection {
const offsetLinesCount = this.toOffsetLinesCount(this.openingTagOffset);

Expand Down

0 comments on commit 61596c1

Please sign in to comment.