fixing funky spaces to be ascii 32
This commit is contained in:
parent
96966f5035
commit
a87c219c30
1 changed files with 35 additions and 35 deletions
|
|
@ -56,9 +56,9 @@ var EditSession = function(text, mode) {
|
||||||
if (mode) {
|
if (mode) {
|
||||||
this.setMode(mode);
|
this.setMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text instanceof Document) {
|
if (text instanceof Document) {
|
||||||
this.setDocument(text)
|
this.setDocument(text);
|
||||||
} else {
|
} else {
|
||||||
this.setDocument(new Document(text));
|
this.setDocument(new Document(text));
|
||||||
}
|
}
|
||||||
|
|
@ -72,15 +72,15 @@ var EditSession = function(text, mode) {
|
||||||
this.setDocument = function(doc) {
|
this.setDocument = function(doc) {
|
||||||
if (this.doc)
|
if (this.doc)
|
||||||
throw new Error("Document is already set");
|
throw new Error("Document is already set");
|
||||||
|
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
doc.on("change", this.onChange.bind(this));
|
doc.on("change", this.onChange.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getDocument = function() {
|
this.getDocument = function() {
|
||||||
return this.doc;
|
return this.doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onChange = function(e) {
|
this.onChange = function(e) {
|
||||||
var delta = e.data;
|
var delta = e.data;
|
||||||
this.$modified = true;
|
this.$modified = true;
|
||||||
|
|
@ -100,7 +100,7 @@ var EditSession = function(text, mode) {
|
||||||
this.toString = function() {
|
this.toString = function() {
|
||||||
return this.doc.getValue();
|
return this.doc.getValue();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getSelection = function() {
|
this.getSelection = function() {
|
||||||
return this.selection;
|
return this.selection;
|
||||||
};
|
};
|
||||||
|
|
@ -166,7 +166,7 @@ var EditSession = function(text, mode) {
|
||||||
this.getTabSize = function() {
|
this.getTabSize = function() {
|
||||||
return this.$tabSize;
|
return this.$tabSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.isTabStop = function(position) {
|
this.isTabStop = function(position) {
|
||||||
return this.$useSoftTabs && (position.column % this.$tabSize == 0);
|
return this.$useSoftTabs && (position.column % this.$tabSize == 0);
|
||||||
};
|
};
|
||||||
|
|
@ -206,13 +206,13 @@ var EditSession = function(text, mode) {
|
||||||
this.$autoNewLine = "\n";
|
this.$autoNewLine = "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.tokenRe = /^[\w\d]+/g;
|
this.tokenRe = /^[\w\d]+/g;
|
||||||
this.nonTokenRe = /^[^\w\d]+/g;
|
this.nonTokenRe = /^[^\w\d]+/g;
|
||||||
|
|
||||||
this.getWordRange = function(row, column) {
|
this.getWordRange = function(row, column) {
|
||||||
var line = this.getLine(row);
|
var line = this.getLine(row);
|
||||||
|
|
||||||
var inToken = false;
|
var inToken = false;
|
||||||
if (column > 0) {
|
if (column > 0) {
|
||||||
inToken = !!line.charAt(column - 1).match(this.tokenRe);
|
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) {
|
this.getLine = function(row) {
|
||||||
return this.doc.getLine(row);
|
return this.doc.getLine(row);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a line as it is displayed on screen. Tabs are replaced by spaces.
|
* 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) {
|
this.insert = function(position, text) {
|
||||||
return this.doc.insert(position, text);
|
return this.doc.insert(position, text);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rows Array[Integer] sorted list of rows
|
* @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--) {
|
for (var i=rows.length-1; i>=0; i--) {
|
||||||
var row = rows[i];
|
var row = rows[i];
|
||||||
if (row >= this.doc.getLength())
|
if (row >= this.doc.getLength())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var diff = column - this.doc.getLine(row).length;
|
var diff = column - this.doc.getLine(row).length;
|
||||||
if ( diff > 0) {
|
if ( diff > 0) {
|
||||||
var padded = lang.stringRepeat(" ", diff) + text;
|
var padded = lang.stringRepeat(" ", diff) + text;
|
||||||
|
|
@ -451,14 +451,14 @@ var EditSession = function(text, mode) {
|
||||||
padded = text;
|
padded = text;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var end = this.insert({row: row, column: column+offset}, padded);
|
var end = this.insert({row: row, column: column+offset}, padded);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
rows: end ? end.row - rows[0] : 0,
|
rows: end ? end.row - rows[0] : 0,
|
||||||
columns: end ? end.column - column : 0
|
columns: end ? end.column - column : 0
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.remove = function(range) {
|
this.remove = function(range) {
|
||||||
|
|
@ -468,52 +468,52 @@ var EditSession = function(text, mode) {
|
||||||
this.multiRowRemove = function(rows, range) {
|
this.multiRowRemove = function(rows, range) {
|
||||||
if (range.start.row !== rows[0])
|
if (range.start.row !== rows[0])
|
||||||
throw new TypeError("range must start in the first row!");
|
throw new TypeError("range must start in the first row!");
|
||||||
|
|
||||||
var height = range.end.row - rows[0];
|
var height = range.end.row - rows[0];
|
||||||
for (var i=rows.length-1; i>=0; i--) {
|
for (var i=rows.length-1; i>=0; i--) {
|
||||||
var row = rows[i];
|
var row = rows[i];
|
||||||
if (row >= this.doc.getLength())
|
if (row >= this.doc.getLength())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var end = this.remove(new Range(row, range.start.column, row+height, range.end.column));
|
var end = this.remove(new Range(row, range.start.column, row+height, range.end.column));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.undoChanges = function(deltas) {
|
this.undoChanges = function(deltas) {
|
||||||
if (!deltas.length)
|
if (!deltas.length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.$fromUndo = true;
|
this.$fromUndo = true;
|
||||||
this.doc.revertDeltas(deltas);
|
this.doc.revertDeltas(deltas);
|
||||||
this.$fromUndo = false;
|
this.$fromUndo = false;
|
||||||
|
|
||||||
// update the selection
|
// update the selection
|
||||||
var firstDelta = deltas[0];
|
var firstDelta = deltas[0];
|
||||||
var lastDelta = deltas[deltas.length-1];
|
var lastDelta = deltas[deltas.length-1];
|
||||||
|
|
||||||
this.selection.clearSelection();
|
this.selection.clearSelection();
|
||||||
if (firstDelta.action == "insertText" || firstDelta.action == "insertLines")
|
if (firstDelta.action == "insertText" || firstDelta.action == "insertLines")
|
||||||
this.selection.moveCursorToPosition(firstDelta.range.start);
|
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.selection.setSelectionRange(Range.fromPoints(firstDelta.range.start, lastDelta.range.end));
|
||||||
},
|
},
|
||||||
|
|
||||||
this.redoChanges = function(deltas) {
|
this.redoChanges = function(deltas) {
|
||||||
if (!deltas.length)
|
if (!deltas.length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.$fromUndo = true;
|
this.$fromUndo = true;
|
||||||
this.doc.applyDeltas(deltas);
|
this.doc.applyDeltas(deltas);
|
||||||
this.$fromUndo = false;
|
this.$fromUndo = false;
|
||||||
|
|
||||||
// update the selection
|
// update the selection
|
||||||
var firstDelta = deltas[0];
|
var firstDelta = deltas[0];
|
||||||
var lastDelta = deltas[deltas.length-1];
|
var lastDelta = deltas[deltas.length-1];
|
||||||
|
|
||||||
this.selection.clearSelection();
|
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));
|
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);
|
this.selection.moveCursorToPosition(firstDelta.range.start);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -533,15 +533,15 @@ var EditSession = function(text, mode) {
|
||||||
var rowRange = range.collapseRows();
|
var rowRange = range.collapseRows();
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
var deleteRange = new Range(0, 0, 0, 0);
|
||||||
var size = this.getTabSize();
|
var size = this.getTabSize();
|
||||||
|
|
||||||
for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
|
for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
|
||||||
var line = this.getLine(i);
|
var line = this.getLine(i);
|
||||||
|
|
||||||
deleteRange.start.row = i;
|
deleteRange.start.row = i;
|
||||||
deleteRange.end.row = i;
|
deleteRange.end.row = i;
|
||||||
for (var j = 0; j < size; ++j)
|
for (var j = 0; j < size; ++j)
|
||||||
if (line.charAt(j) != ' ')
|
if (line.charAt(j) != ' ')
|
||||||
break;
|
break;
|
||||||
if (j < size && line.charAt(j) == '\t') {
|
if (j < size && line.charAt(j) == '\t') {
|
||||||
deleteRange.start.column = j;
|
deleteRange.start.column = j;
|
||||||
deleteRange.end.column = j + 1;
|
deleteRange.end.column = j + 1;
|
||||||
|
|
@ -556,7 +556,7 @@ var EditSession = function(text, mode) {
|
||||||
this.remove(deleteRange);
|
this.remove(deleteRange);
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.moveLinesUp = function(firstRow, lastRow) {
|
this.moveLinesUp = function(firstRow, lastRow) {
|
||||||
if (firstRow <= 0) return 0;
|
if (firstRow <= 0) return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue