Skip to content

Commit

Permalink
Refactor solution
Browse files Browse the repository at this point in the history
This reverts commit a42c9d2.
  • Loading branch information
felixhabib committed Jan 31, 2024
1 parent 069f4fd commit f54b624
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Playroom/CodeEditor/keymaps/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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 @@ -37,13 +36,13 @@ export const wrapInTag = (cm: Editor) => {
existingIndent,
});

const startCursorCharacterPosition =
from.ch + 1 + (isMultiLineSelection ? existingIndent : 0);
const newStartCursor = new Pos(
from.line + linesAdded,
from.ch +
existingIndent +
1 -
(isMultiLineSelection ? 0 : leadingWhitespace)
startCursorCharacterPosition
);

const newEndCursor = isMultiLineSelection
? new Pos(to.line + linesAdded + 2, from.ch + existingIndent + 2)
: new Pos(to.line + linesAdded, to.ch + 4);
Expand Down

0 comments on commit f54b624

Please sign in to comment.