Skip to content

Commit

Permalink
Fix newStartCursor position to ignore leading spaces when single line…
Browse files Browse the repository at this point in the history
… select
  • Loading branch information
felixhabib committed Jan 31, 2024
1 parent fd4e603 commit a42c9d2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Playroom/CodeEditor/keymaps/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const wrapInTag = (cm: Editor) => {
const existingContent = cm.getRange(from, to);
const existingIndent =
existingContent.length - existingContent.trimStart().length;
const leadingWhitespace = existingContent.match(/^[ \t]+/)?.[0].length ?? 0;

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

Expand All @@ -38,7 +39,10 @@ export const wrapInTag = (cm: Editor) => {

const newStartCursor = new Pos(
from.line + linesAdded,
from.ch + existingIndent + 1
from.ch +
existingIndent +
1 -
(isMultiLineSelection ? 0 : leadingWhitespace)
);
const newEndCursor = isMultiLineSelection
? new Pos(to.line + linesAdded + 2, from.ch + existingIndent + 2)
Expand Down

0 comments on commit a42c9d2

Please sign in to comment.