Merge branch 'master' of github.com:ajaxorg/ace

This commit is contained in:
Fabian Jakobs 2011-11-02 13:15:17 +01:00
commit 22274e4d4c
24 changed files with 337 additions and 186 deletions

View file

@ -11860,9 +11860,26 @@ var Selection = function(session) {
this.selectionLead.row,
this.selectionLead.column
);
var screenCol = (chars == 0 && this.$desiredColumn) || screenPos.column;
var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column;
// so here is the deal. First checkout what the content of ur current and ur target line is
var currentLine = (this.session.getLines(screenPos.row, screenPos.row) || [""])[0],
targetLine = (this.session.getLines(screenPos.row + rows, screenPos.row + rows) || [""])[0];
// if you are at the EOL of your current line, and your targetline is all whitespace
if (currentLine && targetLine &&
currentLine.length === screenPos.column && targetLine.match(/^\s*$/)) {
// set the new column to the EOL of the target line
screenCol = this.session.getTabString(targetLine).length;
// update the chars so we are sure that the desired column will be updated
chars = 1;
};
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0);
// move the cursor and update the desired column
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
};
this.moveCursorToPosition = function(position) {

View file

@ -548,95 +548,6 @@ exports.launch = function(env) {
}
});
canon.addCommand({
name: "fold",
bindKey: {
win: "Alt-L",
mac: "Alt-L",
sender: "editor"
},
exec: function(env) {
toggleFold(env, false);
}
});
canon.addCommand({
name: "unfold",
bindKey: {
win: "Alt-Shift-L",
mac: "Alt-Shift-L",
sender: "editor"
},
exec: function(env) {
toggleFold(env, true);
}
});
function isCommentRow(row) {
var session = env.editor.session;
var token;
var tokens = session.getTokens(row, row)[0].tokens;
var c = 0;
for (var i = 0; i < tokens.length; i++) {
token = tokens[i];
if (/^comment/.test(token.type)) {
return c;
} else if (!/^text/.test(token.type)) {
return false;
}
c += token.value.length;
}
return false;
}
function toggleFold(env, tryToUnfold) {
var session = env.editor.session;
var selection = env.editor.selection;
var range = selection.getRange();
var addFold;
if(range.isEmpty()) {
var br = session.findMatchingBracket(range.start);
var fold = session.getFoldAt(range.start.row, range.start.column);
var column;
if (fold) {
session.expandFold(fold);
selection.setSelectionRange(fold.range);
} else if (br) {
if (range.compare(br.row, br.column) == 1)
range.end = br;
else
range.start = br;
addFold = true;
} else if ((column = isCommentRow(range.start.row)) !== false) {
var firstCommentRow = range.start.row;
var lastCommentRow = range.start.row;
var t;
while ((t = isCommentRow(firstCommentRow - 1)) !== false) {
firstCommentRow --;
column = t;
}
while (isCommentRow(lastCommentRow + 1) !== false) {
lastCommentRow ++;
}
range.start.row = firstCommentRow;
range.start.column = column + 2;
range.end.row = lastCommentRow;
range.end.column = session.getLine(lastCommentRow).length - 1;
addFold = true;
}
} else {
addFold = true;
}
if (addFold) {
var placeHolder = session.getTextRange(range);
if(placeHolder.length < 3)
return;
placeHolder = placeHolder.trim().substring(0, 3).replace(' ','','g') + "...";
session.addFold(placeHolder, range);
}
}
};
var themes = {};

View file

@ -55,6 +55,8 @@
<li><a href="http://neutronide.com/">Neutron IDE</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/acebug/">Acebug</a></li>
<li><a href="http://www.weecod.com">Weecod</a></li>
<li><a href="http://www.applaudcloud.com">AppLaud Cloud</a></li>
<li><a href='http://rubymonk.com'>RubyMonk</a></li>
</ul>
<h4>Syntax Highlighters</h4>
<ul class="menu-list">

View file

@ -365,4 +365,33 @@ canon.addCommand({
exec: function(env, args, request) { env.editor.transposeLetters(); }
});
canon.addCommand({
name: "fold",
bindKey: bindKey("Alt-L", "Alt-L"),
exec: function(env) {
env.editor.session.toggleFold(false);
}
});
canon.addCommand({
name: "unfold",
bindKey: bindKey("Alt-Shift-L", "Alt-Shift-L"),
exec: function(env) {
env.editor.session.toggleFold(true);
}
});
canon.addCommand({
name: "foldall",
bindKey: bindKey("Alt-Shift-0", "Alt-Shift-0"),
exec: function(env) {
env.editor.session.foldAll();
}
});
canon.addCommand({
name: "unfoldall",
bindKey: bindKey("Alt-Shift-0", "Alt-Shift-0"),
exec: function(env) {
env.editor.session.unFoldAll();
}
});
});

View file

@ -91,7 +91,7 @@ var EditSession = function(text, mode) {
this.doc = doc;
doc.on("change", this.onChange.bind(this));
this.on("changeFold", this.onChangeFold.bind(this));
if (this.bgTokenizer) {
this.bgTokenizer.setDocument(this.getDocument());
this.bgTokenizer.start(0);
@ -136,7 +136,7 @@ var EditSession = function(text, mode) {
folds: removedFolds
});
}
this.$informUndoManager.schedule();
}
@ -148,7 +148,7 @@ var EditSession = function(text, mode) {
this.doc.setValue(text);
this.selection.moveCursorTo(0, 0);
this.selection.clearSelection();
this.$resetRowCache(0);
this.$deltas = [];
this.$deltasDoc = [];
@ -173,6 +173,27 @@ var EditSession = function(text, mode) {
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.$undoManager = undoManager;
this.$resetRowCache(0);
@ -187,7 +208,7 @@ var EditSession = function(text, mode) {
var self = this;
this.$syncInformUndoManager = function() {
self.$informUndoManager.cancel();
if (self.$deltasFold.length) {
self.$deltas.push({
group: "fold",
@ -195,7 +216,7 @@ var EditSession = function(text, mode) {
});
self.$deltasFold = [];
}
if (self.$deltasDoc.length) {
self.$deltas.push({
group: "doc",
@ -203,14 +224,14 @@ var EditSession = function(text, mode) {
});
self.$deltasDoc = [];
}
if (self.$deltas.length > 0) {
undoManager.execute({
action: "aceupdate",
args: [self.$deltas, self]
});
}
self.$deltas = [];
}
this.$informUndoManager =
@ -479,7 +500,7 @@ var EditSession = function(text, mode) {
this.bgTokenizer.setDocument(this.getDocument());
this.bgTokenizer.start(0);
this.tokenRe = mode.tokenRe;
this.nonTokenRe = mode.nonTokenRe;
@ -894,7 +915,7 @@ var EditSession = function(text, mode) {
this.$clipRowToDocument = function(row) {
return Math.max(0, Math.min(row, this.doc.getLength()-1));
};
this.$clipPositionToDocument = function(row, column) {
column = Math.max(0, column);
@ -910,7 +931,7 @@ var EditSession = function(text, mode) {
column = Math.min(this.doc.getLine(row).length, column);
}
}
return {
row: row,
column: column
@ -1176,6 +1197,7 @@ var EditSession = function(text, mode) {
CHAR_EXT = 2,
PLACEHOLDER_START = 3,
PLACEHOLDER_BODY = 4,
PUNCTUATION = 9,
SPACE = 10,
TAB = 11,
TAB_SPACE = 12;
@ -1219,7 +1241,7 @@ var EditSession = function(text, mode) {
// a split is simple.
if (tokens[split] >= SPACE) {
// Include all following spaces + tabs in this split as well.
while (tokens[split] >= SPACE) {
while (tokens[split] >= SPACE) {
split ++;
}
addSplit(split);
@ -1274,16 +1296,17 @@ var EditSession = function(text, mode) {
}
// === ELSE ===
// Search for the first non space/tab/placeholder token backwards.
for (split; split != lastSplit - 1; split--) {
if (tokens[split] >= PLACEHOLDER_START) {
split++;
break;
}
// Search for the first non space/tab/placeholder/punctuation token backwards.
var minSplit = Math.max(split - 10, lastSplit - 1);
while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
split --;
}
while (split > minSplit && tokens[split] == PUNCTUATION) {
split --;
}
// If we found one, then add the split.
if (split > lastSplit) {
addSplit(split);
if (split > minSplit) {
addSplit(++split);
continue;
}
@ -1291,7 +1314,7 @@ var EditSession = function(text, mode) {
split = lastSplit + wrapLimit;
// The split is inside of a CHAR or CHAR_EXT token and no space
// around -> force a split.
addSplit(lastSplit + wrapLimit);
addSplit(split);
}
return splits;
}
@ -1317,11 +1340,13 @@ var EditSession = function(text, mode) {
}
}
// Space
else if(c == 32) {
else if (c == 32) {
arr.push(SPACE);
} else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
arr.push(PUNCTUATION);
}
// full width characters
else if (isFullWidth(c)) {
else if (c >= 0x1100 && isFullWidth(c)) {
arr.push(CHAR, CHAR_EXT);
} else {
arr.push(CHAR);
@ -1357,7 +1382,7 @@ var EditSession = function(text, mode) {
screenColumn += this.getScreenTabSize(screenColumn);
}
// full width characters
else if (isFullWidth(c)) {
else if (c >= 0x1100 && isFullWidth(c)) {
screenColumn += 2;
} else {
screenColumn += 1;
@ -1433,7 +1458,7 @@ var EditSession = function(text, mode) {
column: 0
}
}
var line;
var docRow = 0;
var docColumn = 0;
@ -1453,11 +1478,11 @@ var EditSession = function(text, mode) {
}
}
var doCache = !rowCache.length || i == rowCache.length;
// clamp row before clamping column, for selection on last line
var maxRow = this.getLength() - 1;
var foldLine = this.getNextFold(docRow);
var foldLine = this.getNextFoldLine(docRow);
var foldStart = foldLine ? foldLine.start.row : Infinity;
while (row <= screenRow) {
@ -1469,7 +1494,7 @@ var EditSession = function(text, mode) {
docRow++;
if (docRow > foldStart) {
docRow = foldLine.end.row+1;
foldLine = this.getNextFold(docRow);
foldLine = this.getNextFoldLine(docRow, foldLine);
foldStart = foldLine ? foldLine.start.row : Infinity;
}
}
@ -1521,7 +1546,7 @@ var EditSession = function(text, mode) {
if (foldLine) {
return foldLine.idxToPosition(docColumn);
}
return {
row: docRow,
column: docColumn
@ -1532,12 +1557,12 @@ var EditSession = function(text, mode) {
// Normalize the passed in arguments.
if (typeof docColumn === "undefined")
var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
else
else
pos = this.$clipPositionToDocument(docRow, docColumn);
docRow = pos.row;
docColumn = pos.column;
var LL = this.$rowCache.length;
var wrapData;
@ -1579,7 +1604,7 @@ var EditSession = function(text, mode) {
}
var doCache = !rowCache.length || i == rowCache.length;
var foldLine = this.getNextFold(row);
var foldLine = this.getNextFoldLine(row);
var foldStart = foldLine ?foldLine.start.row :Infinity;
while (row < docRow) {
@ -1587,7 +1612,7 @@ var EditSession = function(text, mode) {
rowEnd = foldLine.end.row + 1;
if (rowEnd > docRow)
break;
foldLine = this.getNextFold(rowEnd);
foldLine = this.getNextFoldLine(rowEnd, foldLine);
foldStart = foldLine ?foldLine.start.row :Infinity;
}
else {
@ -1596,7 +1621,7 @@ var EditSession = function(text, mode) {
screenRow += this.getRowLength(row);
row = rowEnd;
if (doCache) {
rowCache.push({
docRow: row,
@ -1713,4 +1738,4 @@ var EditSession = function(text, mode) {
require("ace/edit_session/folding").Folding.call(EditSession.prototype);
exports.EditSession = EditSession;
});
});

View file

@ -52,7 +52,7 @@ function Folding() {
var foldLine = this.getFoldLine(row);
if (!foldLine)
return null;
var folds = foldLine.folds;
for (var i = 0; i < folds.length; i++) {
var fold = folds[i];
@ -134,7 +134,7 @@ function Folding() {
var foldLine = foldLine || this.getFoldLine(row);
if (!foldLine)
return null;
var lastFold = {
end: { column: 0 }
};
@ -183,7 +183,7 @@ function Folding() {
}
// returns the fold which starts after or contains docRow
this.getNextFold = function(docRow, startFoldLine) {
this.getNextFoldLine = function(docRow, startFoldLine) {
var foldData = this.$foldData, ans;
var i = 0;
if (startFoldLine)
@ -251,7 +251,7 @@ function Folding() {
var startColumn = fold.start.column;
var endRow = fold.end.row;
var endColumn = fold.end.column;
// --- Some checking ---
if (fold.placeholder.length < 2)
throw "Placeholder has to be at least 2 characters";
@ -489,8 +489,85 @@ function Folding() {
return fd;
};
}
this.toggleFold = function(tryToUnfold) {
var selection = this.selection;
var range = selection.getRange();
if (range.isEmpty()) {
var cursor = range.start
var fold = this.getFoldAt(cursor.row, cursor.column);
var bracketPos, column;
if (fold) {
this.expandFold(fold);
return;
} else if (bracketPos = this.findMatchingBracket(cursor)) {
if (range.comparePoint(bracketPos) == 1) {
range.end = bracketPos;
} else {
range.start = bracketPos;
range.start.column++;
range.end.column--;
}
} else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
if (range.comparePoint(bracketPos) == 1)
range.end = bracketPos;
else
range.start = bracketPos;
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 {
var folds = this.getFoldsInRange(range);
if (tryToUnfold && folds.length) {
this.expandFolds(folds);
return;
} else if (folds.length == 1 ) {
fold = folds[0];
}
}
if (!fold)
fold = this.getFoldAt(range.start.row, range.start.column);
if (fold && fold.range.toString() == range.toString()){
this.expandFold(fold);
return
}
var placeholder = "...";
if (!range.isMultiLine()) {
placeholder = this.getTextRange(range);
if(placeholder.length < 4)
return;
placeholder = placeholder.trim().substring(0, 2) + ".."
}
this.addFold(placeholder, range);
};
}
exports.Folding = Folding;
});

View file

@ -346,6 +346,11 @@ module.exports = {
computeAndAssert(" ぁぁ", [1, 2], 2);
computeAndAssert(" ぁ\tぁ", [1, 3], 2);
computeAndAssert(" ぁぁ\tぁ", [1, 4], 4);
// Test wrapping for punctuation.
computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2);
computeAndAssert(" a.b", [1, 2, 3], 1);
computeAndAssert("#>>", [1, 2], 1);
},
"test get longest line" : function() {

View file

@ -792,7 +792,7 @@ var Editor =function(renderer, session) {
indentString = lang.stringRepeat(" ", count);
} else
indentString = "\t";
return this.onTextInput(indentString);
return this.onTextInput(indentString, true);
}
};

View file

@ -420,7 +420,7 @@ module.exports = {
var editor = new Editor(new MockRenderer(), session);
editor.moveCursorTo(1, 1);
editor.removeLeft();
editor.remove("left");
assert.equal(session.toString(), "123\n56");
},
@ -429,7 +429,7 @@ module.exports = {
var editor = new Editor(new MockRenderer(), session);
editor.moveCursorTo(1, 0);
editor.removeLeft();
editor.remove("left");
assert.equal(session.toString(), "123456");
},
@ -440,7 +440,7 @@ module.exports = {
var editor = new Editor(new MockRenderer(), session);
editor.moveCursorTo(1, 8);
editor.removeLeft();
editor.remove("left");
assert.equal(session.toString(), "123\n 456");
},

View file

@ -93,8 +93,8 @@ var vimStates = {
},
vimcommand("(k|up)", "golineup"),
vimcommand("(j|down)", "golinedown"),
vimcommand("(l|right)", "golineright"),
vimcommand("(h|left)", "golineleft"),
vimcommand("(l|right)", "gotoright"),
vimcommand("(h|left)", "gotoleft"),
{
key: "shift-g",
exec: "gotoend"

View file

@ -103,13 +103,13 @@ var Gutter = function(parentEl) {
var html = [];
var i = config.firstRow;
var lastRow = config.lastRow;
var fold = this.session.getNextFold(i);
var fold = this.session.getNextFoldLine(i);
var foldStart = fold ? fold.start.row : Infinity;
while (true) {
if(i > foldStart) {
i = fold.end.row + 1;
fold = this.session.getNextFold(i);
fold = this.session.getNextFoldLine(i, fold);
foldStart = fold ?fold.start.row :Infinity;
}
if(i > lastRow)

View file

@ -260,13 +260,13 @@ var Text = function(parentEl) {
this.$renderLinesFragment = function(config, firstRow, lastRow) {
var fragment = this.element.ownerDocument.createDocumentFragment(),
row = firstRow,
fold = this.session.getNextFold(row),
fold = this.session.getNextFoldLine(row),
foldStart = fold ?fold.start.row :Infinity;
while (true) {
if(row > foldStart) {
row = fold.end.row+1;
fold = this.session.getNextFold(row);
fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity;
}
if(row > lastRow)
@ -307,13 +307,13 @@ var Text = function(parentEl) {
var firstRow = config.firstRow, lastRow = config.lastRow;
var row = firstRow,
fold = this.session.getNextFold(row),
fold = this.session.getNextFoldLine(row),
foldStart = fold ?fold.start.row :Infinity;
while (true) {
if(row > foldStart) {
row = fold.end.row+1;
fold = this.session.getNextFold(row);
fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity;
}
if(row > lastRow)

View file

@ -93,7 +93,7 @@ module.exports = {
assert.equal(
stringBuilder.join(""),
"<span class='ace_cjk ace_invisible' style='width:20px'>" + this.textLayer.SPACE_CHAR + "</span>"
+ "<span class='ace_invisible'>&para;</span>"
+ "<span class='ace_invisible'>\xB6</span>"
);
}
};

View file

@ -54,7 +54,7 @@ define(function(require, exports, module) {
var keywords = lang.arrayToMap((
"this|throw|then|try|typeof|super|switch|return|break|by)|continue|" +
"catch|class|in|instanceof|is|isnt|if|else|extends|for|forown|" +
"finally|function|while|when|new|not|delete|debugger|do|loop|of|off|" +
"finally|function|while|when|new|no|not|delete|debugger|do|loop|of|off|" +
"or|on|unless|until|and|yes").split("|")
);

View file

@ -78,9 +78,9 @@ module.exports = {
var tokens = this.tokenizer.getLineTokens("{()}", "start").tokens;
assert.equal(3, tokens.length);
assert.equal("lparen", tokens[0].type);
assert.equal("paren.lparen", tokens[0].type);
assert.equal("text", tokens[1].type);
assert.equal("rparen", tokens[2].type);
assert.equal("paren.rparen", tokens[2].type);
},
"test for last rule in ruleset to catch capturing group bugs" : function() {

View file

@ -95,20 +95,20 @@ module.exports = {
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
assert.equal(7, tokens.length);
assert.equal("lparen", tokens[0].type);
assert.equal("lparen", tokens[1].type);
assert.equal("lparen", tokens[2].type);
assert.equal("paren.lparen", tokens[0].type);
assert.equal("paren.lparen", tokens[1].type);
assert.equal("paren.lparen", tokens[2].type);
assert.equal("text", tokens[3].type);
assert.equal("rparen", tokens[4].type);
assert.equal("rparen", tokens[5].type);
assert.equal("rparen", tokens[6].type);
assert.equal("paren.rparen", tokens[4].type);
assert.equal("paren.rparen", tokens[5].type);
assert.equal("paren.rparen", tokens[6].type);
},
"test for last rule in ruleset to catch capturing group bugs" : function() {
var tokens = this.tokenizer.getLineTokens("}", "start").tokens;
assert.equal(1, tokens.length);
assert.equal("rparen", tokens[0].type);
assert.equal("paren.rparen", tokens[0].type);
},
"test tokenize arithmetic expression which looks like a regexp": function() {
@ -160,7 +160,7 @@ module.exports = {
"test // is not a regexp": function() {
var tokens = this.tokenizer.getLineTokens("{ // 123", "start").tokens;
assert.equal(3, tokens.length);
assert.equal("lparen", tokens[0].type);
assert.equal("paren.lparen", tokens[0].type);
assert.equal("text", tokens[1].type);
assert.equal("comment", tokens[2].type);
}

View file

@ -206,13 +206,12 @@ var Mode = function() {
for (var key in behaviours) {
if (behaviours[key][action]) {
var ret = behaviours[key][action].apply(this, arguments);
if (ret !== false) {
if (ret) {
return ret;
}
}
}
}
return false;
}
}).call(Mode.prototype);

View file

@ -126,18 +126,18 @@ function DefaultHandlers(editor) {
mousePageY = event.getDocumentY(e);
};
var onMouseSelectionEnd = function() {
var onMouseSelectionEnd = function(e) {
clearInterval(timerId);
if (state == STATE_UNKNOWN)
onStartSelect(pos);
else if (state == STATE_DRAG)
onMouseDragSelectionEnd();
onMouseDragSelectionEnd(e);
_self.$clickSelection = null;
state = STATE_UNKNOWN;
};
var onMouseDragSelectionEnd = function() {
var onMouseDragSelectionEnd = function(e) {
dom.removeCssClass(editor.container, "ace_dragging");
editor.session.removeMarker(dragSelectionMarker);
@ -157,7 +157,12 @@ function DefaultHandlers(editor) {
}
editor.clearSelection();
var newRange = editor.moveText(dragRange, dragCursor);
if (e && (e.ctrlKey || e.altKey)) {
var session = editor.session;
var newRange = session.insert(dragCursor, session.getTextRange(dragRange));
} else {
var newRange = editor.moveText(dragRange, dragCursor);
}
if (!newRange) {
dragCursor = null;
return;

View file

@ -102,9 +102,12 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
}
}
this.comparePoint = function(p) {
return this.compare(p.row, p.column);
}
this.containsRange = function(range) {
var cmp = this.compareRange(range);
return (cmp == -1 || cmp == 0 || cmp == 1);
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
}
this.isEnd = function(row, column) {

View file

@ -89,20 +89,28 @@ Search.SELECTION = 2;
};
this.findAll = function(session) {
if (!this.$options.needle)
var options = this.$options;
if (!options.needle)
return [];
if (this.$options.backwards) {
if (options.backwards) {
var iterator = this.$backwardMatchIterator(session);
} else {
iterator = this.$forwardMatchIterator(session);
}
var ignoreCursor = !options.start && options.wrap && options.scope == Search.ALL;
if (ignoreCursor)
options.start = {row: 0, column: 0};
var ranges = [];
iterator.forEach(function(range) {
ranges.push(range);
});
if (ignoreCursor)
options.start = null;
return ranges;
};
@ -213,8 +221,8 @@ Search.SELECTION = 2;
this.$forwardLineIterator = function(session) {
var searchSelection = this.$options.scope == Search.SELECTION;
var range = session.getSelection().getRange();
var start = session.getSelection().getCursor();
var range = this.$options.range || session.getSelection().getRange();
var start = this.$options.start || session.getSelection().getCursor();
var firstRow = searchSelection ? range.start.row : 0;
var firstColumn = searchSelection ? range.start.column : 0;
@ -275,8 +283,8 @@ Search.SELECTION = 2;
this.$backwardLineIterator = function(session) {
var searchSelection = this.$options.scope == Search.SELECTION;
var range = session.getSelection().getRange();
var start = searchSelection ? range.end : range.start;
var range = this.$options.range || session.getSelection().getRange();
var start = this.$options.start || session.getSelection().getCursor();
var firstRow = searchSelection ? range.start.row : 0;
var firstColumn = searchSelection ? range.start.column : 0;

View file

@ -348,6 +348,24 @@ module.exports = {
assert.equal(search.replace("ab12", "$$"), "$");
},
"test: find all using regular expresion containing $" : function() {
var session = new EditSession(["a", " b", "c ", "d"]);
var search = new Search().set({
needle: "[ ]+$",
regExp: true,
wrap: true,
scope: Search.ALL
});
session.getSelection().moveCursorTo(1, 2);
var ranges = search.findAll(session);
assert.equal(ranges.length, 1);
assert.position(ranges[0].start, 2, 1);
assert.position(ranges[0].end, 2, 2);
},
"test: find all matches in a line" : function() {
var session = new EditSession("foo bar foo baz foobar foo");
@ -362,12 +380,12 @@ module.exports = {
var ranges = search.findAll(session);
assert.equal(ranges.length, 3);
assert.position(ranges[0].start, 0, 8);
assert.position(ranges[0].end, 0, 11);
assert.position(ranges[1].start, 0, 23);
assert.position(ranges[1].end, 0, 26);
assert.position(ranges[2].start, 0, 0);
assert.position(ranges[2].end, 0, 3);
assert.position(ranges[0].start, 0, 0);
assert.position(ranges[0].end, 0, 3);
assert.position(ranges[1].start, 0, 8);
assert.position(ranges[1].end, 0, 11);
assert.position(ranges[2].start, 0, 23);
assert.position(ranges[2].end, 0, 26);
},
"test: find all matches in a line backwards" : function() {
@ -385,12 +403,12 @@ module.exports = {
var ranges = search.findAll(session);
assert.equal(ranges.length, 3);
assert.position(ranges[0].start, 0, 8);
assert.position(ranges[0].end, 0, 11);
assert.position(ranges[1].start, 0, 0);
assert.position(ranges[1].end, 0, 3);
assert.position(ranges[2].start, 0, 23);
assert.position(ranges[2].end, 0, 26);
assert.position(ranges[0].start, 0, 23);
assert.position(ranges[0].end, 0, 26);
assert.position(ranges[1].start, 0, 8);
assert.position(ranges[1].end, 0, 11);
assert.position(ranges[2].start, 0, 0);
assert.position(ranges[2].end, 0, 3);
},
};

View file

@ -123,7 +123,7 @@ var Selection = function(session) {
};
var anchor = this.getSelectionAnchor();
var lead = this.getSelectionLead();
var lead = this.getSelectionLead();
var isBackwards = this.isBackwards();
@ -440,9 +440,26 @@ var Selection = function(session) {
this.selectionLead.row,
this.selectionLead.column
);
var screenCol = (chars == 0 && this.$desiredColumn) || screenPos.column;
var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column;
// so here is the deal. First checkout what the content of ur current and ur target line is
var currentLine = (this.session.getLines(screenPos.row, screenPos.row) || [""])[0],
targetLine = (this.session.getLines(screenPos.row + rows, screenPos.row + rows) || [""])[0];
// if you are at the EOL of your current line, and your targetline is all whitespace
if (currentLine && targetLine &&
currentLine.length === screenPos.column && targetLine.match(/^\s*$/)) {
// set the new column to the EOL of the target line
screenCol = this.session.getTabString(targetLine).length;
// update the chars so we are sure that the desired column will be updated
chars = 1;
};
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0);
// move the cursor and update the desired column
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
};
this.moveCursorToPosition = function(position) {

View file

@ -442,6 +442,42 @@ module.exports = {
selection.moveCursorUp();
selection.moveCursorDown();
assert.position(selection.getCursor(), 1, 4);
},
"test (keyboard navigation) when curLine is EOL and targetLine is all whitespace new column should be targetLine's EOL": function() {
var session = new EditSession("function (a) {\n\
\n\
}");
var selection = session.getSelection();
selection.moveCursorTo(2, 1);
selection.moveCursorUp();
assert.position(selection.getCursor(), 1, 4);
},
"test (keyboard navigation) when curLine is not EOL and targetLine is all whitespace new column should be current column": function() {
var session = new EditSession("function (a) {\n\
\n\
}");
var selection = session.getSelection();
selection.moveCursorTo(2, 0);
selection.moveCursorUp();
assert.position(selection.getCursor(), 1, 0);
},
"test (keyboard navigation) when curLine is EOL and targetLine is shorter dan current column, new column should be targetLine's EOL": function() {
var session = new EditSession("function (a) {\n\
\n\
}");
var selection = session.getSelection();
selection.moveCursorTo(0, 14);
selection.moveCursorDown();
assert.position(selection.getCursor(), 1, 4);
}
};

View file

@ -27,8 +27,7 @@
var require = {
paths: {
ace: "../",
cockpit: "../../../../support/cockpit/lib/cockpit",
pilot: "../../../../support/pilot/lib/pilot"
pilot: "../../../support/pilot/lib/pilot"
},
packages : [{
name: "asyncjs",
@ -41,7 +40,7 @@
}]
};
</script>
<script src="../../../demo/require.js" data-main="all_browser" type="text/javascript" charset="utf-8"></script>
<script src="../../../demo/kitchen-sink/require.js" data-main="all_browser" type="text/javascript" charset="utf-8"></script>
</body>