backspace should eat 4 spaces when the cursor is positioned after a tab
(also for navigation and selection)
This commit is contained in:
parent
16b12da3e3
commit
b6bd3fb726
4 changed files with 52 additions and 5 deletions
|
|
@ -161,6 +161,10 @@ var Document = function(text, mode) {
|
||||||
return this.$tabSize;
|
return this.$tabSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.isTabStop = function(position) {
|
||||||
|
return this.$useSoftTabs && (position.column % this.$tabSize == 0);
|
||||||
|
};
|
||||||
|
|
||||||
this.getBreakpoints = function() {
|
this.getBreakpoints = function() {
|
||||||
return this.$breakpoints;
|
return this.$breakpoints;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -590,9 +590,9 @@ var Editor =function(renderer, doc) {
|
||||||
if (this.$readOnly)
|
if (this.$readOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.selection.isEmpty()) {
|
if (this.selection.isEmpty())
|
||||||
this.selection.selectLeft();
|
this.selection.selectLeft();
|
||||||
}
|
|
||||||
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
|
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -265,13 +265,20 @@ var Selection = function(doc) {
|
||||||
|
|
||||||
this.moveCursorLeft = function() {
|
this.moveCursorLeft = function() {
|
||||||
if (this.selectionLead.column == 0) {
|
if (this.selectionLead.column == 0) {
|
||||||
|
// cursor is a line start
|
||||||
if (this.selectionLead.row > 0) {
|
if (this.selectionLead.row > 0) {
|
||||||
this.moveCursorTo(this.selectionLead.row - 1, this.doc
|
this.moveCursorTo(this.selectionLead.row - 1, this.doc
|
||||||
.getLine(this.selectionLead.row - 1).length);
|
.getLine(this.selectionLead.row - 1).length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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 {
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -408,7 +408,37 @@ var Test = {
|
||||||
undoManager.undo();
|
undoManager.undo();
|
||||||
doc.$informUndoManager.call();
|
doc.$informUndoManager.call();
|
||||||
assert.equal(doc.toString(), initialText);
|
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);
|
module.exports = require("async/test").testcase(Test);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue