diff --git a/.changeset/silver-countries-prove.md b/.changeset/silver-countries-prove.md new file mode 100644 index 00000000..260b2202 --- /dev/null +++ b/.changeset/silver-countries-prove.md @@ -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. diff --git a/cypress/e2e/keymaps.cy.ts b/cypress/e2e/keymaps.cy.ts index 8ab3dd2e..488e2278 100644 --- a/cypress/e2e/keymaps.cy.ts +++ b/cypress/e2e/keymaps.cy.ts @@ -348,6 +348,27 @@ describe('Keymaps', () => {
Third line
`); }); + + it('should wrap a two-line multi-line selection when the last selected line is empty', () => { + loadPlayroom(` +
First line
+ `); + + moveToEndOfLine(); + typeCode(`{enter}`); + + // Select all + typeCode(`{${modifierKey}+a}`); + + typeCode(`{shift+${modifierKey}+,}`); + typeCode('a'); + + assertCodePaneContains(dedent` + +
First line
+
\n + `); + }); }); describe('find and replace', () => { diff --git a/src/Playroom/CodeEditor/keymaps/wrap.ts b/src/Playroom/CodeEditor/keymaps/wrap.ts index f5702d89..c42a0c05 100644 --- a/src/Playroom/CodeEditor/keymaps/wrap.ts +++ b/src/Playroom/CodeEditor/keymaps/wrap.ts @@ -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); } @@ -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,