emacs: fix exchangePointAndMark in normal select mode
This commit is contained in:
parent
78b2147c3c
commit
ea67201540
1 changed files with 18 additions and 17 deletions
|
|
@ -481,24 +481,25 @@ exports.handler.addCommands({
|
||||||
exchangePointAndMark: {
|
exchangePointAndMark: {
|
||||||
exec: function (editor, args) {
|
exec: function (editor, args) {
|
||||||
var restoreMarks = [];
|
var restoreMarks = [];
|
||||||
editor.forEachSelection({
|
if (editor.inMultiSelectMode) editor.forEachSelection({exec: doExchange});
|
||||||
exec: function() {
|
else doExchange();
|
||||||
var sel = editor.selection;
|
|
||||||
if (args.count) { // replace mark and point
|
|
||||||
var pos = {row: sel.lead.row, column: sel.lead.column};
|
|
||||||
restoreMarks.push(pos);
|
|
||||||
sel.clearSelection();
|
|
||||||
sel.moveCursorToPosition(editor.popEmacsMark());
|
|
||||||
} else if (sel.isEmpty()) { // move to mark, forget point
|
|
||||||
var lastMark = editor.popEmacsMark();
|
|
||||||
restoreMarks.push(lastMark);
|
|
||||||
sel.selectToPosition(lastMark);
|
|
||||||
} else { // just invert selection
|
|
||||||
sel.setSelectionRange(sel.getRange(), !sel.isBackwards());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
restoreMarks.reverse().forEach(function(p) { editor.pushEmacsMark(p); });
|
restoreMarks.reverse().forEach(function(p) { editor.pushEmacsMark(p); });
|
||||||
|
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||||
|
function doExchange() {
|
||||||
|
var sel = editor.selection;
|
||||||
|
if (args.count) { // replace mark and point
|
||||||
|
var pos = {row: sel.lead.row, column: sel.lead.column};
|
||||||
|
restoreMarks.push(pos);
|
||||||
|
sel.clearSelection();
|
||||||
|
sel.moveCursorToPosition(editor.popEmacsMark());
|
||||||
|
} else if (sel.isEmpty()) { // move to mark, forget point
|
||||||
|
var lastMark = editor.popEmacsMark();
|
||||||
|
restoreMarks.push(lastMark);
|
||||||
|
sel.selectToPosition(lastMark);
|
||||||
|
} else { // just invert selection
|
||||||
|
sel.setSelectionRange(sel.getRange(), !sel.isBackwards());
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
handlesCount: true,
|
handlesCount: true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue