Skip to content

Commit

Permalink
Fix bug in "Wrap selection in tag" command with empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib committed Jan 3, 2025
1 parent 6095dc4 commit e4b1673
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-countries-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Fix bug in "Wrap selection in tag" command that caused the start cursor to sometimes be in the wrong position when selecting an empty line.
21 changes: 21 additions & 0 deletions cypress/e2e/keymaps.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,27 @@ describe('Keymaps', () => {
<div>Third line</div>
`);
});

it('should wrap a two-line multi-line selection when the last selected line is empty', () => {
loadPlayroom(`
<div>First line</div>
`);

moveToEndOfLine();
typeCode(`{enter}`);

// Select all
typeCode(`{${modifierKey}+a}`);

typeCode(`{shift+${modifierKey}+,}`);
typeCode('a');

assertCodePaneContains(dedent`
<a>
<div>First line</div>
</a>\n
`);
});
});

describe('find and replace', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/Playroom/CodeEditor/keymaps/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const wrapInTag = (cm: Editor) => {
const from = range.from();
let to = range.to();

const isMultiLineSelection = to.line !== from.line;

if (to.line !== from.line && to.ch === 0) {
to = new Pos(to.line - 1);
}
Expand All @@ -27,8 +29,6 @@ export const wrapInTag = (cm: Editor) => {
const existingIndent =
existingContent.length - existingContent.trimStart().length;

const isMultiLineSelection = to.line !== from.line;

tagRanges.push({
from,
to,
Expand Down

0 comments on commit e4b1673

Please sign in to comment.