- Fixed the issue where indenting a single line would always insert <tab size> spaces when in soft tabbing mode. What should happen instead is that the line is indented to the next tab stop.
This commit is contained in:
parent
87d0a83796
commit
ddf5f6f138
4 changed files with 26 additions and 13 deletions
|
|
@ -97,7 +97,7 @@ var Document = function(text, mode) {
|
|||
|
||||
this.getTabString = function() {
|
||||
if (this.getUseSoftTabs()) {
|
||||
return new Array(this.getTabSize()+1).join(" ");
|
||||
return lang.stringRepeat(" ", this.getTabSize());
|
||||
} else {
|
||||
return "\t";
|
||||
}
|
||||
|
|
@ -545,7 +545,8 @@ var Document = function(text, mode) {
|
|||
};
|
||||
|
||||
this.indentRows = function(range, indentString) {
|
||||
for (var row=range.start.row; row<= range.end.row; row++) {
|
||||
indentString.replace("\t", this.getTabString());
|
||||
for (var row=range.start.row; row<=range.end.row; row++) {
|
||||
this.$insert({row: row, column:0}, indentString);
|
||||
}
|
||||
this.fireChangeEvent(range.start.row, range.end.row);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ require.def("ace/Editor",
|
|||
[
|
||||
"ace/ace",
|
||||
"ace/lib/event",
|
||||
"ace/lib/lang",
|
||||
"ace/TextInput",
|
||||
"ace/KeyBinding",
|
||||
"ace/Document",
|
||||
|
|
@ -16,7 +17,7 @@ require.def("ace/Editor",
|
|||
"ace/BackgroundTokenizer",
|
||||
"ace/Range",
|
||||
"ace/MEventEmitter"
|
||||
], function(ace, event, TextInput, KeyBinding, Document, Search, BackgroundTokenizer, Range, MEventEmitter) {
|
||||
], function(ace, event, lang, TextInput, KeyBinding, Document, Search, BackgroundTokenizer, Range, MEventEmitter) {
|
||||
|
||||
var Editor = function(renderer, doc) {
|
||||
var container = renderer.getContainerElement();
|
||||
|
|
@ -524,14 +525,26 @@ var Editor = function(renderer, doc) {
|
|||
this.clearSelection();
|
||||
};
|
||||
|
||||
this.blockIndent = function(indentString) {
|
||||
this.indent = function() {
|
||||
if (this.$readOnly)
|
||||
return;
|
||||
|
||||
var indentString = indentString || this.doc.getTabString();
|
||||
var addedColumns = this.doc.indentRows(this.getSelectionRange(), indentString);
|
||||
if (this.selection.isMultiLine()) {
|
||||
var addedColumns = this.doc.indentRows(this.getSelectionRange(), "\t");
|
||||
this.selection.shiftSelection(addedColumns);
|
||||
} else {
|
||||
if (!this.doc.getUseSoftTabs())
|
||||
return this.onTextInput("\t");
|
||||
|
||||
var cursor = this.doc.remove(this.getSelectionRange());
|
||||
this.clearSelection();
|
||||
|
||||
this.selection.shiftSelection(addedColumns);
|
||||
// compute indent string
|
||||
var indentString = lang.stringRepeat(" ", this.doc.getTabSize() - (cursor.column % this.doc.getTabSize()));
|
||||
var addedColumns = this.doc.indentRows(this.getSelectionRange(), indentString);
|
||||
cursor.column += addedColumns;
|
||||
this.moveCursorToPosition(cursor);
|
||||
}
|
||||
this.$updateDesiredColumn();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -151,12 +151,7 @@ PluginManager.registerCommand("outdent", function(editor, selection) {
|
|||
editor.blockOutdent();
|
||||
});
|
||||
PluginManager.registerCommand("indent", function(editor, selection) {
|
||||
if (selection.isMultiLine()) {
|
||||
editor.blockIndent();
|
||||
}
|
||||
else {
|
||||
editor.onTextInput("\t");
|
||||
}
|
||||
editor.indent();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -16,6 +16,10 @@ require.def("ace/lib/lang", function() {
|
|||
return string.split("").reverse().join("");
|
||||
};
|
||||
|
||||
lang.stringRepeat = function (string, count) {
|
||||
return new Array(count + 1).join(string);
|
||||
}
|
||||
|
||||
if (Array.prototype.indexOf) {
|
||||
lang.arrayIndexOf = function(array, searchElement) {
|
||||
return array.indexOf(searchElement);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue