cleanup
This commit is contained in:
parent
d578c63beb
commit
387790d94c
6 changed files with 82 additions and 71 deletions
|
|
@ -127,91 +127,109 @@ exports.commands = [{
|
|||
name: "selectup",
|
||||
bindKey: bindKey("Shift-Up", "Shift-Up"),
|
||||
exec: function(editor) { editor.getSelection().selectUp(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "golineup",
|
||||
bindKey: bindKey("Up", "Up|Ctrl-P"),
|
||||
exec: function(editor, args) { editor.navigateUp(args.times); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selecttoend",
|
||||
bindKey: bindKey("Ctrl-Shift-End|Alt-Shift-Down", "Command-Shift-Down"),
|
||||
exec: function(editor) { editor.getSelection().selectFileEnd(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "gotoend",
|
||||
bindKey: bindKey("Ctrl-End|Ctrl-Down", "Command-End|Command-Down"),
|
||||
exec: function(editor) { editor.navigateFileEnd(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selectdown",
|
||||
bindKey: bindKey("Shift-Down", "Shift-Down"),
|
||||
exec: function(editor) { editor.getSelection().selectDown(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "golinedown",
|
||||
bindKey: bindKey("Down", "Down|Ctrl-N"),
|
||||
exec: function(editor, args) { editor.navigateDown(args.times); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selectwordleft",
|
||||
bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
|
||||
exec: function(editor) { editor.getSelection().selectWordLeft(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "gotowordleft",
|
||||
bindKey: bindKey("Ctrl-Left", "Option-Left"),
|
||||
exec: function(editor) { editor.navigateWordLeft(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selecttolinestart",
|
||||
bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
|
||||
exec: function(editor) { editor.getSelection().selectLineStart(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "gotolinestart",
|
||||
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
|
||||
exec: function(editor) { editor.navigateLineStart(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selectleft",
|
||||
bindKey: bindKey("Shift-Left", "Shift-Left"),
|
||||
exec: function(editor) { editor.getSelection().selectLeft(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "gotoleft",
|
||||
bindKey: bindKey("Left", "Left|Ctrl-B"),
|
||||
exec: function(editor, args) { editor.navigateLeft(args.times); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selectwordright",
|
||||
bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
|
||||
exec: function(editor) { editor.getSelection().selectWordRight(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "gotowordright",
|
||||
bindKey: bindKey("Ctrl-Right", "Option-Right"),
|
||||
exec: function(editor) { editor.navigateWordRight(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selecttolineend",
|
||||
bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
|
||||
exec: function(editor) { editor.getSelection().selectLineEnd(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "gotolineend",
|
||||
bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
|
||||
exec: function(editor) { editor.navigateLineEnd(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selectright",
|
||||
bindKey: bindKey("Shift-Right", "Shift-Right"),
|
||||
exec: function(editor) { editor.getSelection().selectRight(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "gotoright",
|
||||
bindKey: bindKey("Right", "Right|Ctrl-F"),
|
||||
exec: function(editor, args) { editor.navigateRight(args.times); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selectpagedown",
|
||||
|
|
@ -247,11 +265,13 @@ exports.commands = [{
|
|||
name: "selectlinestart",
|
||||
bindKey: bindKey("Shift-Home", "Shift-Home"),
|
||||
exec: function(editor) { editor.getSelection().selectLineStart(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "selectlineend",
|
||||
bindKey: bindKey("Shift-End", "Shift-End"),
|
||||
exec: function(editor) { editor.getSelection().selectLineEnd(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "togglerecording",
|
||||
|
|
@ -267,6 +287,7 @@ exports.commands = [{
|
|||
name: "jumptomatching",
|
||||
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
|
||||
exec: function(editor) { editor.jumpToMatching(); },
|
||||
multiSelectAction: "forEach",
|
||||
readOnly: true
|
||||
},
|
||||
|
||||
|
|
@ -274,11 +295,13 @@ exports.commands = [{
|
|||
{
|
||||
name: "removeline",
|
||||
bindKey: bindKey("Ctrl-D", "Command-D"),
|
||||
exec: function(editor) { editor.removeLines(); }
|
||||
exec: function(editor) { editor.removeLines(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "togglecomment",
|
||||
bindKey: bindKey("Ctrl-7", "Command-7"),
|
||||
exec: function(editor) { editor.toggleCommentLines(); }
|
||||
exec: function(editor) { editor.toggleCommentLines(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "replace",
|
||||
bindKey: bindKey("Ctrl-R", "Command-Option-F"),
|
||||
|
|
@ -330,62 +353,76 @@ exports.commands = [{
|
|||
}, {
|
||||
name: "del",
|
||||
bindKey: bindKey("Delete", "Delete|Ctrl-D"),
|
||||
exec: function(editor) { editor.remove("right"); }
|
||||
exec: function(editor) { editor.remove("right"); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "backspace",
|
||||
bindKey: bindKey(
|
||||
"Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
|
||||
"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
|
||||
),
|
||||
exec: function(editor) { editor.remove("left"); }
|
||||
exec: function(editor) { editor.remove("left"); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "removetolinestart",
|
||||
bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
|
||||
exec: function(editor) { editor.removeToLineStart(); }
|
||||
exec: function(editor) { editor.removeToLineStart(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "removetolineend",
|
||||
bindKey: bindKey("Alt-Delete", "Ctrl-K"),
|
||||
exec: function(editor) { editor.removeToLineEnd(); }
|
||||
exec: function(editor) { editor.removeToLineEnd(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "removewordleft",
|
||||
bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
|
||||
exec: function(editor) { editor.removeWordLeft(); }
|
||||
exec: function(editor) { editor.removeWordLeft(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "removewordright",
|
||||
bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
|
||||
exec: function(editor) { editor.removeWordRight(); }
|
||||
exec: function(editor) { editor.removeWordRight(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "outdent",
|
||||
bindKey: bindKey("Shift-Tab", "Shift-Tab"),
|
||||
exec: function(editor) { editor.blockOutdent(); }
|
||||
exec: function(editor) { editor.blockOutdent(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "indent",
|
||||
bindKey: bindKey("Tab", "Tab"),
|
||||
exec: function(editor) { editor.indent(); }
|
||||
exec: function(editor) { editor.indent(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "insertstring",
|
||||
exec: function(editor, str) { editor.insert(str); }
|
||||
exec: function(editor, str) { editor.insert(str); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "inserttext",
|
||||
exec: function(editor, args) {
|
||||
editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
|
||||
}
|
||||
},
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "splitline",
|
||||
bindKey: bindKey(null, "Ctrl-O"),
|
||||
exec: function(editor) { editor.splitLine(); }
|
||||
exec: function(editor) { editor.splitLine(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "transposeletters",
|
||||
bindKey: bindKey("Ctrl-T", "Ctrl-T"),
|
||||
exec: function(editor) { editor.transposeLetters(); }
|
||||
exec: function(editor) { editor.transposeLetters(); },
|
||||
multiSelectAction: function(editor) {editor.transposeSelections(1); }
|
||||
}, {
|
||||
name: "touppercase",
|
||||
bindKey: bindKey("Ctrl-U", "Ctrl-U"),
|
||||
exec: function(editor) { editor.toUpperCase(); }
|
||||
exec: function(editor) { editor.toUpperCase(); },
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
name: "tolowercase",
|
||||
bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
|
||||
exec: function(editor) { editor.toLowerCase(); }
|
||||
exec: function(editor) { editor.toLowerCase(); },
|
||||
multiSelectAction: "forEach"
|
||||
}];
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,27 +38,6 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
// add multiSelectAction annotations to default commands
|
||||
require("./default_commands").commands.forEach(function(command) {
|
||||
var single = RegExp(["selectall"].join("|"), "");
|
||||
var mapOver = RegExp(["backspace", "del",
|
||||
"golinedown", "golineup", "gotoend", "gotoleft", "gotolineend", "gotolinestart",
|
||||
"gotoright", "gotostart", "gotowordleft", "gotowordright",
|
||||
"indent", "insertstring", "inserttext", "jumptomatching", "outdent",
|
||||
"removetolineend", "removetolinestart", "removewordleft", "removewordright", "removeline",
|
||||
"selectdown", "selectleft", "selectlineend", "selectlinestart", "selectright",
|
||||
"selecttoend", "selecttolineend", "selecttolinestart", "selecttostart",
|
||||
"selectup", "selectwordleft", "selectwordright",
|
||||
"splitline", "tolowercase", "touppercase"].join("|"), "");
|
||||
|
||||
if (single.test(command.name))
|
||||
command.multiSelectAction = "single";
|
||||
else if (mapOver.test(command.name))
|
||||
command.multiSelectAction = "forEach";
|
||||
else if (command.name == "transposeletters")
|
||||
command.multiSelectAction = function(editor) {editor.transposeSelections(1); };
|
||||
});
|
||||
|
||||
// commands to enter multiselect mode
|
||||
exports.defaultCommands = [{
|
||||
name: "addCursorAbove",
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ var event = require("../lib/event");
|
|||
|
||||
// mouse
|
||||
function isSamePoint(p1, p2) {
|
||||
return p1.row == p2.row && p1.column == p2.column
|
||||
return p1.row == p2.row && p1.column == p2.column;
|
||||
}
|
||||
|
||||
function onMouseDown(e) {
|
||||
|
|
@ -72,12 +72,11 @@ function onMouseDown(e) {
|
|||
var selection = editor.selection;
|
||||
var isMultiSelect = editor.inMultiSelectMode;
|
||||
var pos = e.getDocumentPosition();
|
||||
var cursor = selection.getCursor()
|
||||
var cursor = selection.getCursor();
|
||||
var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
|
||||
|
||||
|
||||
var mouseX = e.pageX, mouseY = e.pageY;
|
||||
var clickX = mouseX, clickY = mouseY;
|
||||
var onMouseSelection = function(e) {
|
||||
mouseX = event.getDocumentX(e);
|
||||
mouseY = event.getDocumentY(e);
|
||||
|
|
@ -99,20 +98,18 @@ function onMouseDown(e) {
|
|||
editor.removeSelectionMarkers(rectSel);
|
||||
rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
|
||||
rectSel.forEach(editor.addSelectionMarker, editor);
|
||||
editor.updateSelectionMarkers()
|
||||
editor.updateSelectionMarkers();
|
||||
};
|
||||
|
||||
var session = editor.session;
|
||||
var anchor = selection.getCursor();
|
||||
var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
|
||||
var clippedAnchor = session.documentToScreenPosition(anchor);
|
||||
var screenCursor = screenAnchor;
|
||||
|
||||
|
||||
|
||||
if (ctrl && !shift && !alt && button == 0) {
|
||||
if (!isMultiSelect && inSelection)
|
||||
return // dragging
|
||||
return; // dragging
|
||||
|
||||
if (!isMultiSelect)
|
||||
selection.addRange(selection.toOrientedRange());
|
||||
|
|
@ -130,7 +127,7 @@ function onMouseDown(e) {
|
|||
});
|
||||
|
||||
} else if (!shift && alt && button == 0) {
|
||||
e.stop()
|
||||
e.stop();
|
||||
|
||||
if (isMultiSelect && !ctrl)
|
||||
selection.toSingleRange();
|
||||
|
|
@ -146,13 +143,13 @@ function onMouseDown(e) {
|
|||
clearInterval(timerId);
|
||||
editor.removeSelectionMarkers(rectSel);
|
||||
for (var i = 0; i < rectSel.length; i++)
|
||||
selection.addRange(rectSel[i])
|
||||
selection.addRange(rectSel[i]);
|
||||
};
|
||||
|
||||
onSelectionInterval = blockSelect;
|
||||
var onSelectionInterval = blockSelect;
|
||||
|
||||
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
|
||||
var timerId = setInterval(function() {onSelectionInterval()}, 20);
|
||||
var timerId = setInterval(function() {onSelectionInterval();}, 20);
|
||||
|
||||
return e.preventDefault();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,14 +57,14 @@ function find(session, needle, dir) {
|
|||
|
||||
// extend EditSession
|
||||
var EditSession = require("./edit_session").EditSession;
|
||||
;(function() {
|
||||
(function() {
|
||||
this.getSelectionMarkers = function() {
|
||||
return this.$selectionMarkers;
|
||||
};
|
||||
}).call(EditSession.prototype);
|
||||
|
||||
// extend Selection
|
||||
;(function() {
|
||||
(function() {
|
||||
// list of ranges in reverse addition order
|
||||
this.ranges = null;
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ var EditSession = require("./edit_session").EditSession;
|
|||
var removed = this.rangeList.substractPoint(pos);
|
||||
if (removed) {
|
||||
this.$onRemoveRange(removed);
|
||||
return removed[0]
|
||||
return removed[0];
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ var EditSession = require("./edit_session").EditSession;
|
|||
this.$onRemoveRange = function(removed) {
|
||||
this.rangeCount = this.rangeList.ranges.length;
|
||||
if (this.rangeCount == 1 && this.inMultiSelectMode) {
|
||||
var lastRange = this.rangeList.ranges.pop()
|
||||
var lastRange = this.rangeList.ranges.pop();
|
||||
removed.push(lastRange);
|
||||
this.rangeCount = 0;
|
||||
}
|
||||
|
|
@ -241,6 +241,7 @@ var EditSession = require("./edit_session").EditSession;
|
|||
range.cursor = xBackwards ? range.start : range.end;
|
||||
rectSel.push(range);
|
||||
}
|
||||
|
||||
if (yBackwards)
|
||||
rectSel.reverse();
|
||||
|
||||
|
|
@ -265,7 +266,7 @@ var EditSession = require("./edit_session").EditSession;
|
|||
|
||||
// extend Editor
|
||||
var Editor = require("./editor").Editor;
|
||||
;(function() {
|
||||
(function() {
|
||||
this.updateSelectionMarkers = function() {
|
||||
this.renderer.updateCursor();
|
||||
this.renderer.updateBackMarkers();
|
||||
|
|
@ -291,7 +292,7 @@ var Editor = require("./editor").Editor;
|
|||
this.session.removeMarker(range.marker);
|
||||
var index = this.session.$selectionMarkers.indexOf(range);
|
||||
if (index != -1)
|
||||
this.session.$selectionMarkers.splice(index, 1)
|
||||
this.session.$selectionMarkers.splice(index, 1);
|
||||
}
|
||||
this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
|
||||
};
|
||||
|
|
@ -353,7 +354,7 @@ var Editor = require("./editor").Editor;
|
|||
this.forEachSelection = function(cmd, args) {
|
||||
if (this.inVirtualSelectionMode)
|
||||
return;
|
||||
|
||||
|
||||
var session = this.session;
|
||||
var selection = this.selection;
|
||||
var rangeList = selection.rangeList;
|
||||
|
|
@ -452,9 +453,6 @@ var Editor = require("./editor").Editor;
|
|||
if (!this.selection.inMultiSelectMode) {
|
||||
this.selection.addRange(range);
|
||||
} else {
|
||||
var allRanges = this.selection.rangeList.ranges;
|
||||
// remove range if at end
|
||||
// var atEdge = range.isEqual(allRanges[dir == 1 ? 0 : allRanges.length - 1]);
|
||||
if (skip)
|
||||
var toRemove = range.cursor;
|
||||
}
|
||||
|
|
@ -462,7 +460,7 @@ var Editor = require("./editor").Editor;
|
|||
this.selection.addRange(newRange);
|
||||
if (toRemove)
|
||||
this.selection.substractPoint(toRemove);
|
||||
}
|
||||
};
|
||||
|
||||
this.transposeSelections = function(dir) {
|
||||
var session = this.session;
|
||||
|
|
@ -516,12 +514,12 @@ var Editor = require("./editor").Editor;
|
|||
}
|
||||
if (skip)
|
||||
this.multiSelect.substractPoint(range.cursor);
|
||||
}
|
||||
};
|
||||
}).call(Editor.prototype);
|
||||
|
||||
|
||||
function isSamePoint(p1, p2) {
|
||||
return p1.row == p2.row && p1.column == p2.column
|
||||
return p1.row == p2.row && p1.column == p2.column;
|
||||
}
|
||||
|
||||
// patch
|
||||
|
|
|
|||
|
|
@ -78,7 +78,9 @@ module.exports = {
|
|||
assert.ok(editor.inMultiSelectMode);
|
||||
assert.equal(editor.selection.getAllRanges().length, 4);
|
||||
|
||||
assert.equal(editor.getCopyText(), "wwww");
|
||||
var newLine = editor.session.getDocument().getNewLineCharacter();
|
||||
var copyText = "wwww".split("").join(newLine);
|
||||
assert.equal(editor.getCopyText(), copyText);
|
||||
exec("insertstring", 1, "a");
|
||||
exec("backspace", 2);
|
||||
assert.equal(editor.session.getValue(), "w1.w2\ntt\ntt");
|
||||
|
|
|
|||
|
|
@ -38,16 +38,14 @@
|
|||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var oop = require("./lib/oop");
|
||||
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
||||
|
||||
var RangeList = function(startRow, startColumn, endRow, endColumn) {
|
||||
var RangeList = function() {
|
||||
this.ranges = [];
|
||||
};
|
||||
|
||||
(function() {
|
||||
this.comparePoints = function(p1, p2) {
|
||||
return p1.row - p2.row || p1.column - p2.column
|
||||
return p1.row - p2.row || p1.column - p2.column;
|
||||
};
|
||||
|
||||
this.pointIndex = function(pos, startIndex) {
|
||||
|
|
@ -67,7 +65,7 @@ var RangeList = function(startRow, startColumn, endRow, endColumn) {
|
|||
|
||||
return -i-1;
|
||||
}
|
||||
return -i - 1
|
||||
return -i - 1;
|
||||
};
|
||||
|
||||
this.add = function(range) {
|
||||
|
|
@ -88,7 +86,7 @@ var RangeList = function(startRow, startColumn, endRow, endColumn) {
|
|||
this.addList = function(list) {
|
||||
var removed = [];
|
||||
for (var i = list.length; i--; ) {
|
||||
removed.push.call(removed, this.add(list[i]))
|
||||
removed.push.call(removed, this.add(list[i]));
|
||||
}
|
||||
return removed;
|
||||
};
|
||||
|
|
@ -108,7 +106,7 @@ var RangeList = function(startRow, startColumn, endRow, endColumn) {
|
|||
for (var i = 1; i < list.length; i++) {
|
||||
range = next;
|
||||
next = list[i];
|
||||
var cmp = this.comparePoints(range.end, next.start)
|
||||
var cmp = this.comparePoints(range.end, next.start);
|
||||
if (cmp < 0)
|
||||
continue;
|
||||
|
||||
|
|
@ -180,8 +178,8 @@ var RangeList = function(startRow, startColumn, endRow, endColumn) {
|
|||
this.detach = function() {
|
||||
if (!this.session)
|
||||
return;
|
||||
this.session.removeListener('change', this.onChange)
|
||||
this.session = null
|
||||
this.session.removeListener('change', this.onChange);
|
||||
this.session = null;
|
||||
};
|
||||
|
||||
this.$onChange = function(e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue