toggleFold must fold strings and comments as well
This commit is contained in:
parent
92a3369bdb
commit
7ade415f25
2 changed files with 58 additions and 17 deletions
|
|
@ -91,7 +91,7 @@ var EditSession = function(text, mode) {
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
doc.on("change", this.onChange.bind(this));
|
doc.on("change", this.onChange.bind(this));
|
||||||
this.on("changeFold", this.onChangeFold.bind(this));
|
this.on("changeFold", this.onChangeFold.bind(this));
|
||||||
|
|
||||||
if (this.bgTokenizer) {
|
if (this.bgTokenizer) {
|
||||||
this.bgTokenizer.setDocument(this.getDocument());
|
this.bgTokenizer.setDocument(this.getDocument());
|
||||||
this.bgTokenizer.start(0);
|
this.bgTokenizer.start(0);
|
||||||
|
|
@ -136,7 +136,7 @@ var EditSession = function(text, mode) {
|
||||||
folds: removedFolds
|
folds: removedFolds
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$informUndoManager.schedule();
|
this.$informUndoManager.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,7 +148,7 @@ var EditSession = function(text, mode) {
|
||||||
this.doc.setValue(text);
|
this.doc.setValue(text);
|
||||||
this.selection.moveCursorTo(0, 0);
|
this.selection.moveCursorTo(0, 0);
|
||||||
this.selection.clearSelection();
|
this.selection.clearSelection();
|
||||||
|
|
||||||
this.$resetRowCache(0);
|
this.$resetRowCache(0);
|
||||||
this.$deltas = [];
|
this.$deltas = [];
|
||||||
this.$deltasDoc = [];
|
this.$deltasDoc = [];
|
||||||
|
|
@ -173,6 +173,27 @@ var EditSession = function(text, mode) {
|
||||||
return this.bgTokenizer.getTokens(firstRow, lastRow);
|
return this.bgTokenizer.getTokens(firstRow, lastRow);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getTokenAt = function(row, column) {
|
||||||
|
var tokens = this.bgTokenizer.getTokens(row, row)[0].tokens;
|
||||||
|
var token, c = 0;
|
||||||
|
if (column == null) {
|
||||||
|
i = tokens.length - 1;
|
||||||
|
c = this.getLine(row).length;
|
||||||
|
} else {
|
||||||
|
for (var i = 0; i < tokens.length; i++) {
|
||||||
|
c += tokens[i].value.length;
|
||||||
|
if (c >= column)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
token = tokens[i];
|
||||||
|
if (!token)
|
||||||
|
return null;
|
||||||
|
token.index = i;
|
||||||
|
token.start = c - token.value.length;
|
||||||
|
return token;
|
||||||
|
};
|
||||||
|
|
||||||
this.setUndoManager = function(undoManager) {
|
this.setUndoManager = function(undoManager) {
|
||||||
this.$undoManager = undoManager;
|
this.$undoManager = undoManager;
|
||||||
this.$resetRowCache(0);
|
this.$resetRowCache(0);
|
||||||
|
|
@ -187,7 +208,7 @@ var EditSession = function(text, mode) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$syncInformUndoManager = function() {
|
this.$syncInformUndoManager = function() {
|
||||||
self.$informUndoManager.cancel();
|
self.$informUndoManager.cancel();
|
||||||
|
|
||||||
if (self.$deltasFold.length) {
|
if (self.$deltasFold.length) {
|
||||||
self.$deltas.push({
|
self.$deltas.push({
|
||||||
group: "fold",
|
group: "fold",
|
||||||
|
|
@ -195,7 +216,7 @@ var EditSession = function(text, mode) {
|
||||||
});
|
});
|
||||||
self.$deltasFold = [];
|
self.$deltasFold = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.$deltasDoc.length) {
|
if (self.$deltasDoc.length) {
|
||||||
self.$deltas.push({
|
self.$deltas.push({
|
||||||
group: "doc",
|
group: "doc",
|
||||||
|
|
@ -203,14 +224,14 @@ var EditSession = function(text, mode) {
|
||||||
});
|
});
|
||||||
self.$deltasDoc = [];
|
self.$deltasDoc = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.$deltas.length > 0) {
|
if (self.$deltas.length > 0) {
|
||||||
undoManager.execute({
|
undoManager.execute({
|
||||||
action: "aceupdate",
|
action: "aceupdate",
|
||||||
args: [self.$deltas, self]
|
args: [self.$deltas, self]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self.$deltas = [];
|
self.$deltas = [];
|
||||||
}
|
}
|
||||||
this.$informUndoManager =
|
this.$informUndoManager =
|
||||||
|
|
@ -479,7 +500,7 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
this.bgTokenizer.setDocument(this.getDocument());
|
this.bgTokenizer.setDocument(this.getDocument());
|
||||||
this.bgTokenizer.start(0);
|
this.bgTokenizer.start(0);
|
||||||
|
|
||||||
this.tokenRe = mode.tokenRe;
|
this.tokenRe = mode.tokenRe;
|
||||||
this.nonTokenRe = mode.nonTokenRe;
|
this.nonTokenRe = mode.nonTokenRe;
|
||||||
|
|
||||||
|
|
@ -894,7 +915,7 @@ var EditSession = function(text, mode) {
|
||||||
this.$clipRowToDocument = function(row) {
|
this.$clipRowToDocument = function(row) {
|
||||||
return Math.max(0, Math.min(row, this.doc.getLength()-1));
|
return Math.max(0, Math.min(row, this.doc.getLength()-1));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$clipPositionToDocument = function(row, column) {
|
this.$clipPositionToDocument = function(row, column) {
|
||||||
column = Math.max(0, column);
|
column = Math.max(0, column);
|
||||||
|
|
||||||
|
|
@ -910,7 +931,7 @@ var EditSession = function(text, mode) {
|
||||||
column = Math.min(this.doc.getLine(row).length, column);
|
column = Math.min(this.doc.getLine(row).length, column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
row: row,
|
row: row,
|
||||||
column: column
|
column: column
|
||||||
|
|
@ -1433,7 +1454,7 @@ var EditSession = function(text, mode) {
|
||||||
column: 0
|
column: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var line;
|
var line;
|
||||||
var docRow = 0;
|
var docRow = 0;
|
||||||
var docColumn = 0;
|
var docColumn = 0;
|
||||||
|
|
@ -1453,7 +1474,7 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var doCache = !rowCache.length || i == rowCache.length;
|
var doCache = !rowCache.length || i == rowCache.length;
|
||||||
|
|
||||||
// clamp row before clamping column, for selection on last line
|
// clamp row before clamping column, for selection on last line
|
||||||
var maxRow = this.getLength() - 1;
|
var maxRow = this.getLength() - 1;
|
||||||
|
|
||||||
|
|
@ -1521,7 +1542,7 @@ var EditSession = function(text, mode) {
|
||||||
if (foldLine) {
|
if (foldLine) {
|
||||||
return foldLine.idxToPosition(docColumn);
|
return foldLine.idxToPosition(docColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
row: docRow,
|
row: docRow,
|
||||||
column: docColumn
|
column: docColumn
|
||||||
|
|
@ -1532,12 +1553,12 @@ var EditSession = function(text, mode) {
|
||||||
// Normalize the passed in arguments.
|
// Normalize the passed in arguments.
|
||||||
if (typeof docColumn === "undefined")
|
if (typeof docColumn === "undefined")
|
||||||
var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
|
var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
|
||||||
else
|
else
|
||||||
pos = this.$clipPositionToDocument(docRow, docColumn);
|
pos = this.$clipPositionToDocument(docRow, docColumn);
|
||||||
|
|
||||||
docRow = pos.row;
|
docRow = pos.row;
|
||||||
docColumn = pos.column;
|
docColumn = pos.column;
|
||||||
|
|
||||||
var LL = this.$rowCache.length;
|
var LL = this.$rowCache.length;
|
||||||
|
|
||||||
var wrapData;
|
var wrapData;
|
||||||
|
|
@ -1596,7 +1617,7 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
screenRow += this.getRowLength(row);
|
screenRow += this.getRowLength(row);
|
||||||
row = rowEnd;
|
row = rowEnd;
|
||||||
|
|
||||||
if (doCache) {
|
if (doCache) {
|
||||||
rowCache.push({
|
rowCache.push({
|
||||||
docRow: row,
|
docRow: row,
|
||||||
|
|
|
||||||
|
|
@ -494,7 +494,7 @@ function Folding() {
|
||||||
var selection = this.selection;
|
var selection = this.selection;
|
||||||
var range = selection.getRange();
|
var range = selection.getRange();
|
||||||
|
|
||||||
if(range.isEmpty()) {
|
if (range.isEmpty()) {
|
||||||
var cursor = range.start
|
var cursor = range.start
|
||||||
var fold = this.getFoldAt(cursor.row, cursor.column);
|
var fold = this.getFoldAt(cursor.row, cursor.column);
|
||||||
var bracketPos, column;
|
var bracketPos, column;
|
||||||
|
|
@ -517,6 +517,26 @@ function Folding() {
|
||||||
range.start = bracketPos;
|
range.start = bracketPos;
|
||||||
|
|
||||||
range.start.column++;
|
range.start.column++;
|
||||||
|
} else {
|
||||||
|
var token = this.getTokenAt(cursor.row, cursor.column);
|
||||||
|
if (token && /^comment|string/.test(token.type)) {
|
||||||
|
var startRow = cursor.row;
|
||||||
|
var endRow = cursor.row;
|
||||||
|
var t = token;
|
||||||
|
while ((t = this.getTokenAt(startRow - 1)) && t.type == token.type) {
|
||||||
|
startRow --;
|
||||||
|
token = t;
|
||||||
|
}
|
||||||
|
range.start.row = startRow;
|
||||||
|
range.start.column = token.start + 2;
|
||||||
|
|
||||||
|
while ((t = this.getTokenAt(endRow + 1, 0)) && t.type == token.type) {
|
||||||
|
endRow ++;
|
||||||
|
token = t;
|
||||||
|
}
|
||||||
|
range.end.row = endRow;
|
||||||
|
range.end.column = token.start + token.value.length - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var folds = this.getFoldsInRange(range);
|
var folds = this.getFoldsInRange(range);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue