diff --git a/lib/ace/document.js b/lib/ace/document.js index 3dbb438e..dc2389fb 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -160,6 +160,10 @@ var Document = function(text, mode) { this.getTabSize = function() { return this.$tabSize; }; + + this.isTabStop = function(position) { + return this.$useSoftTabs && (position.column % this.$tabSize == 0); + }; this.getBreakpoints = function() { return this.$breakpoints; diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 2fd404b7..1e7da684 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -590,9 +590,9 @@ var Editor =function(renderer, doc) { if (this.$readOnly) return; - if (this.selection.isEmpty()) { + if (this.selection.isEmpty()) this.selection.selectLeft(); - } + this.moveCursorToPosition(this.doc.remove(this.getSelectionRange())); this.clearSelection(); }; diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 236d546e..eb326c97 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -265,13 +265,20 @@ var Selection = function(doc) { this.moveCursorLeft = function() { if (this.selectionLead.column == 0) { + // cursor is a line start if (this.selectionLead.row > 0) { this.moveCursorTo(this.selectionLead.row - 1, this.doc .getLine(this.selectionLead.row - 1).length); } } else { - this.moveCursorBy(0, -1); + var doc = this.doc; + var tabSize = doc.getTabSize(); + var cursor = this.selectionLead; + if (doc.isTabStop(cursor) && doc.getLine(cursor.row).slice(cursor.column-tabSize, cursor.column).split(" ").length-1 == tabSize) + this.moveCursorBy(0, -tabSize); + else + this.moveCursorBy(0, -1); } }; @@ -282,7 +289,13 @@ var Selection = function(doc) { } } else { - this.moveCursorBy(0, 1); + var doc = this.doc; + var tabSize = doc.getTabSize(); + var cursor = this.selectionLead; + if (doc.isTabStop(cursor) && doc.getLine(cursor.row).slice(cursor.column, cursor.column+tabSize).split(" ").length-1 == tabSize) + this.moveCursorBy(0, tabSize); + else + this.moveCursorBy(0, 1); } }; diff --git a/lib/ace/test/text_edit_test.js b/lib/ace/test/text_edit_test.js index 85807405..69801a5a 100644 --- a/lib/ace/test/text_edit_test.js +++ b/lib/ace/test/text_edit_test.js @@ -408,7 +408,37 @@ var Test = { undoManager.undo(); doc.$informUndoManager.call(); assert.equal(doc.toString(), initialText); - } + }, + + "test: remove left should remove character left of the cursor" : function() { + var doc = new Document(["123", "456"]); + + var editor = new Editor(new MockRenderer(), doc); + editor.moveCursorTo(1, 1); + editor.removeLeft(); + assert.equal(doc.toString(), "123\n56"); + }, + + "test: remove left should remove line break if cursor is at line start" : function() { + var doc = new Document(["123", "456"]); + + var editor = new Editor(new MockRenderer(), doc); + editor.moveCursorTo(1, 0); + editor.removeLeft(); + assert.equal(doc.toString(), "123456"); + }, + + "test: remove left should remove tabsize spaces if cursor is on a tab stop and preceeded by spaces" : function() { + var doc = new Document(["123", " 456"]); + doc.setUseSoftTabs(true); + doc.setTabSize(4); + + var editor = new Editor(new MockRenderer(), doc); + editor.moveCursorTo(1, 8); + editor.removeLeft(); + assert.equal(doc.toString(), "123\n 456"); + }, + }; module.exports = require("async/test").testcase(Test);