emacs: fix multi select exchangePointAndMark

Conflicts:
	lib/ace/keyboard/emacs.js
This commit is contained in:
Robert Krahn 2014-03-22 01:11:23 -07:00
commit 24f3bab19d

View file

@ -442,7 +442,7 @@ exports.handler.addCommands({
// Any insertion or mouse click resets mark-mode. // Any insertion or mouse click resets mark-mode.
// setMark twice in a row at the same place resets markmode. // setMark twice in a row at the same place resets markmode.
// in multi select mode, ea selection is handled individually // in multi select mode, ea selection is handled individually
if (args && args.count) { if (args && args.count) {
function moveToMark() { function moveToMark() {
var mark = editor.popEmacsMark(); var mark = editor.popEmacsMark();
@ -452,7 +452,7 @@ exports.handler.addCommands({
else moveToMark(); else moveToMark();
return; return;
} }
var mark = editor.emacsMark(), var mark = editor.emacsMark(),
ranges = editor.selection.getAllRanges(), ranges = editor.selection.getAllRanges(),
rangePositions = ranges.map(function(r) { return {row: r.start.row, column: r.start.column}; }), rangePositions = ranges.map(function(r) { return {row: r.start.row, column: r.start.column}; }),
@ -467,7 +467,7 @@ exports.handler.addCommands({
if (mark) editor.pushEmacsMark(null); if (mark) editor.pushEmacsMark(null);
return; return;
} }
if (!mark) { if (!mark) {
rangePositions.slice(0,-1).forEach(function(pos) { editor.pushEmacsMark(pos); }); rangePositions.slice(0,-1).forEach(function(pos) { editor.pushEmacsMark(pos); });
editor.setEmacsMark(rangePositions[rangePositions.length-1]); editor.setEmacsMark(rangePositions[rangePositions.length-1]);
@ -479,22 +479,26 @@ exports.handler.addCommands({
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, },
exchangePointAndMark: { exchangePointAndMark: {
exec: function(editor, args) { exec: function (editor, args) {
var sel = editor.selection; var restoreMarks = [];
if (args.count) { editor.forEachSelection({
var pos = editor.getCursorPosition(); exec: function() {
sel.clearSelection(); var sel = editor.selection;
sel.moveCursorToPosition(editor.popEmacsMark()); if (args.count) { // replace mark and point
editor.pushEmacsMark(pos); var pos = {row: sel.lead.row, column: sel.lead.column};
return; restoreMarks.push(pos);
} sel.clearSelection();
var lastMark = editor.getLastEmacsMark(); sel.moveCursorToPosition(editor.popEmacsMark());
var range = sel.getRange(); } else if (sel.isEmpty()) { // move to mark, forget point
if (range.isEmpty()) { var lastMark = editor.popEmacsMark();
sel.selectToPosition(lastMark); restoreMarks.push(lastMark);
return; sel.selectToPosition(lastMark);
} } else { // just invert selection
sel.setSelectionRange(range, !sel.isBackwards()); sel.setSelectionRange(sel.getRange(), !sel.isBackwards());
}
}
});
restoreMarks.reverse().forEach(function(p) { editor.pushEmacsMark(p); });
}, },
readOnly: true, readOnly: true,
handlesCount: true, handlesCount: true,