diff --git a/src/services/cledit/cleditCore.js b/src/services/cledit/cleditCore.js index ae5cf5f1..44b9b265 100644 --- a/src/services/cledit/cleditCore.js +++ b/src/services/cledit/cleditCore.js @@ -90,7 +90,8 @@ function cledit(contentElt, scrollEltOpt, isMarkdown = false) { function replace(selectionStart, selectionEnd, replacement) { undoMgr.setDefaultMode('single'); replaceContent(selectionStart, selectionEnd, replacement); - const endOffset = selectionStart + replacement.length; + const startOffset = Math.min(selectionStart, selectionEnd); + const endOffset = startOffset + replacement.length; selectionMgr.setSelectionStartEnd(endOffset, endOffset); selectionMgr.updateCursorCoordinates(true); }