fix selection on tab key
This commit is contained in:
parent
e52c8c69a0
commit
2e8923e2e7
@ -48,7 +48,7 @@ const codeTabState = {
|
|||||||
},
|
},
|
||||||
indent(indentString: string) {
|
indent(indentString: string) {
|
||||||
const lines = this.code.split("\n");
|
const lines = this.code.split("\n");
|
||||||
const {focusY, anchorY} = this;
|
const {focusX, focusY, anchorX, anchorY} = this;
|
||||||
const newLines = lines.map((line, i) => {
|
const newLines = lines.map((line, i) => {
|
||||||
console.log(i, Math.min(focusY, anchorY), Math.max(focusY, anchorY));
|
console.log(i, Math.min(focusY, anchorY), Math.max(focusY, anchorY));
|
||||||
if (i >= Math.min(focusY, anchorY) && i <= Math.max(focusY, anchorY)) {
|
if (i >= Math.min(focusY, anchorY) && i <= Math.max(focusY, anchorY)) {
|
||||||
@ -59,10 +59,11 @@ const codeTabState = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.code = newLines.join("\n");
|
this.code = newLines.join("\n");
|
||||||
|
this.setSelection({x: anchorX+1, y: anchorY}, {x: focusX+1, y: focusY});
|
||||||
},
|
},
|
||||||
outdent(outdentRegex: RegExp) {
|
outdent(outdentRegex: RegExp) {
|
||||||
const lines = this.code.split("\n");
|
const lines = this.code.split("\n");
|
||||||
const {focusY, anchorY} = this;
|
const {focusX, focusY, anchorX, anchorY} = this;
|
||||||
const newLines = lines.map((line, i) => {
|
const newLines = lines.map((line, i) => {
|
||||||
const match = line.match(outdentRegex);
|
const match = line.match(outdentRegex);
|
||||||
if (i >= Math.min(focusY, anchorY) && i <= Math.max(focusY, anchorY) && match) {
|
if (i >= Math.min(focusY, anchorY) && i <= Math.max(focusY, anchorY) && match) {
|
||||||
@ -72,6 +73,7 @@ const codeTabState = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.code = newLines.join("\n");
|
this.code = newLines.join("\n");
|
||||||
|
this.setSelection({x: Math.max(0,anchorX-1), y: anchorY}, {x: Math.max(0,focusX-1), y: focusY});
|
||||||
},
|
},
|
||||||
backspace() {
|
backspace() {
|
||||||
const {code, focus} = this;
|
const {code, focus} = this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user