make Backspace delete the current selection correctly (#108)
This commit is contained in:
parent
7727e62655
commit
c4f6f80166
1 changed files with 18 additions and 14 deletions
|
@ -257,21 +257,25 @@ export class CodeEditor extends HTMLElement {
|
||||||
this.pushHistory({ allowMerge: true });
|
this.pushHistory({ allowMerge: true });
|
||||||
|
|
||||||
let selection = this.getSelection();
|
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();
|
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);
|
this.setSelection(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue