From b770fd110153c0c8c78a114ff2a7709305bd4429 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 28 Sep 2016 18:49:24 -0400 Subject: [PATCH] Fix delete not working correctly in the middle of lines --- main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index d8155b1..8f123dd 100644 --- a/main.js +++ b/main.js @@ -51,7 +51,7 @@ document.addEventListener("keydown", (event) => { moveToEndOfPreviousLine(); } else { // move back 1 char let line = editor.doc.getLine(pos.line); - if (line.hasPreceedingWhiteSpace()) { + if (line.hasOnlyWhiteSpaceBeforeIndex(pos.ch)) { moveToEndOfPreviousLine(); } else { editor.setCursor({ line: pos.line, ch: pos.ch - 1 }); @@ -126,6 +126,6 @@ function updateIncompleteMark() { }); } -String.prototype.hasPreceedingWhiteSpace = function() { - return this.indexOf(this.trim()) != 0; +String.prototype.hasOnlyWhiteSpaceBeforeIndex = function(index) { + return this.substring(index) == this.trim(); };