diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index e9e2a66a..7fbf4517 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -56,9 +56,9 @@ var EditSession = function(text, mode) { if (mode) { this.setMode(mode); } - + if (text instanceof Document) { - this.setDocument(text) + this.setDocument(text); } else { this.setDocument(new Document(text)); } @@ -72,15 +72,15 @@ var EditSession = function(text, mode) { this.setDocument = function(doc) { if (this.doc) throw new Error("Document is already set"); - + this.doc = doc; doc.on("change", this.onChange.bind(this)); }; - + this.getDocument = function() { return this.doc; }; - + this.onChange = function(e) { var delta = e.data; this.$modified = true; @@ -100,7 +100,7 @@ var EditSession = function(text, mode) { this.toString = function() { return this.doc.getValue(); }; - + this.getSelection = function() { return this.selection; }; @@ -166,7 +166,7 @@ var EditSession = function(text, mode) { this.getTabSize = function() { return this.$tabSize; }; - + this.isTabStop = function(position) { return this.$useSoftTabs && (position.column % this.$tabSize == 0); }; @@ -206,13 +206,13 @@ var EditSession = function(text, mode) { this.$autoNewLine = "\n"; } }; - + this.tokenRe = /^[\w\d]+/g; this.nonTokenRe = /^[^\w\d]+/g; - + this.getWordRange = function(row, column) { var line = this.getLine(row); - + var inToken = false; if (column > 0) { inToken = !!line.charAt(column - 1).match(this.tokenRe); @@ -311,12 +311,12 @@ var EditSession = function(text, mode) { }; /** - * Get a verbatim copy of the given line as it is in the document + * Get a verbatim copy of the given line as it is in the document */ this.getLine = function(row) { return this.doc.getLine(row); }; - + /** * Get a line as it is displayed on screen. Tabs are replaced by spaces. */ @@ -432,16 +432,16 @@ var EditSession = function(text, mode) { this.insert = function(position, text) { return this.doc.insert(position, text); }; - + /** * @param rows Array[Integer] sorted list of rows */ - this.multiRowInsert = function(rows, column, text) { + this.multiRowInsert = function(rows, column, text) { for (var i=rows.length-1; i>=0; i--) { var row = rows[i]; if (row >= this.doc.getLength()) continue; - + var diff = column - this.doc.getLine(row).length; if ( diff > 0) { var padded = lang.stringRepeat(" ", diff) + text; @@ -451,14 +451,14 @@ var EditSession = function(text, mode) { padded = text; offset = 0; } - + var end = this.insert({row: row, column: column+offset}, padded); } - + return { rows: end ? end.row - rows[0] : 0, columns: end ? end.column - column : 0 - } + }; }; this.remove = function(range) { @@ -468,52 +468,52 @@ var EditSession = function(text, mode) { this.multiRowRemove = function(rows, range) { if (range.start.row !== rows[0]) throw new TypeError("range must start in the first row!"); - + var height = range.end.row - rows[0]; for (var i=rows.length-1; i>=0; i--) { var row = rows[i]; if (row >= this.doc.getLength()) continue; - + var end = this.remove(new Range(row, range.start.column, row+height, range.end.column)); } }; - + this.undoChanges = function(deltas) { if (!deltas.length) return; - + this.$fromUndo = true; this.doc.revertDeltas(deltas); this.$fromUndo = false; - + // update the selection var firstDelta = deltas[0]; var lastDelta = deltas[deltas.length-1]; - + this.selection.clearSelection(); - if (firstDelta.action == "insertText" || firstDelta.action == "insertLines") + if (firstDelta.action == "insertText" || firstDelta.action == "insertLines") this.selection.moveCursorToPosition(firstDelta.range.start); - if (firstDelta.action == "removeText" || firstDelta.action == "removeLines") + if (firstDelta.action == "removeText" || firstDelta.action == "removeLines") this.selection.setSelectionRange(Range.fromPoints(firstDelta.range.start, lastDelta.range.end)); }, this.redoChanges = function(deltas) { if (!deltas.length) return; - + this.$fromUndo = true; this.doc.applyDeltas(deltas); this.$fromUndo = false; - + // update the selection var firstDelta = deltas[0]; var lastDelta = deltas[deltas.length-1]; - + this.selection.clearSelection(); - if (firstDelta.action == "insertText" || firstDelta.action == "insertLines") + if (firstDelta.action == "insertText" ||firstDelta.action == "insertLines") this.selection.setSelectionRange(Range.fromPoints(firstDelta.range.start, lastDelta.range.end)); - if (firstDelta.action == "removeText" || firstDelta.action == "removeLines") + if (firstDelta.action == "removeText" ||firstDelta.action == "removeLines") this.selection.moveCursorToPosition(firstDelta.range.start); }, @@ -533,15 +533,15 @@ var EditSession = function(text, mode) { var rowRange = range.collapseRows(); var deleteRange = new Range(0, 0, 0, 0); var size = this.getTabSize(); - + for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) { var line = this.getLine(i); - + deleteRange.start.row = i; deleteRange.end.row = i; for (var j = 0; j < size; ++j) if (line.charAt(j) != ' ') - break; + break; if (j < size && line.charAt(j) == '\t') { deleteRange.start.column = j; deleteRange.end.column = j + 1; @@ -556,7 +556,7 @@ var EditSession = function(text, mode) { this.remove(deleteRange); } return range; - } + }; this.moveLinesUp = function(firstRow, lastRow) { if (firstRow <= 0) return 0;