Skip to content

Commit e713d45

Browse files
committed
Update codeit.js
1 parent b6357a1 commit e713d45

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/codeit.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,17 @@ class CodeitElement extends HTMLElement {
639639
// wrap the text with matching opening and closing chars
640640
const wrappedText = event.key + textToWrap + close[open.indexOf(event.key)];
641641

642+
// delete current selection
643+
cd.deleteCurrentSelection();
644+
642645
// insert wrapped text
643-
cd.insert(wrappedText);
646+
cd.insert(wrappedText, { moveToEnd: false });
647+
648+
// get caret pos in text
649+
const pos = cd.getSelection();
650+
651+
// restore pos in text
652+
cd.setSelection(pos.start, (pos.start + wrappedText.length));
644653

645654
} else {
646655

0 commit comments

Comments
 (0)