Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in "Wrap selection in tag" command with empty lines #387

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
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
Loading