diff --git a/static/code-editor.js b/static/code-editor.js index 086c9cd..431e0df 100644 --- a/static/code-editor.js +++ b/static/code-editor.js @@ -257,21 +257,25 @@ export class CodeEditor extends HTMLElement { this.pushHistory({ allowMerge: true }); let selection = this.getSelection(); + if (selection.start != selection.end) { + this.replace(selection, ""); + } else { + selection.collapse(); + + let start = getLineStart(this.code, selection.start); + let leading = this.code.substring(start, selection.cursor); + let isAtIndent = /^ +$/.test(leading); + let positionInLine = selection.cursor - start; + let charactersToRemove = isAtIndent + ? this.indentWidth - (positionInLine % this.indentWidth) + : 1; + + selection.cursor -= charactersToRemove; + selection.clampCursor(this.code); + this.replace(selection, ""); + } + selection.collapse(); - - let start = getLineStart(this.code, selection.start); - let leading = this.code.substring(start, selection.cursor); - let isAtIndent = /^ +$/.test(leading); - let positionInLine = selection.cursor - start; - let charactersToRemove = isAtIndent - ? this.indentWidth - (positionInLine % this.indentWidth) - : 1; - - selection.cursor -= charactersToRemove; - selection.clampCursor(this.code); - this.replace(selection, ""); - selection.collapse(); - this.setSelection(selection); }