fix selecting with ctrl-alt click

This commit is contained in:
nightwing 2014-05-28 01:25:18 +04:00
commit 1c2bc29424
2 changed files with 59 additions and 41 deletions

View file

@ -109,12 +109,14 @@ function DefaultHandlers(mouseHandler) {
var editor = this.editor; var editor = this.editor;
// allow double/triple click handlers to change selection // allow double/triple click handlers to change selection
var shiftPressed = this.mousedownEvent.getShiftKey(); var shiftPressed = this.mousedownEvent.getShiftKey();
if (shiftPressed) { setTimeout(function(){
editor.selection.selectToPosition(pos); if (shiftPressed) {
} editor.selection.selectToPosition(pos);
else if (!this.$clickSelection) { }
editor.selection.moveToPosition(pos); else if (!this.$clickSelection) {
} editor.selection.moveToPosition(pos);
}
}.bind(this), 0);
if (editor.renderer.scroller.setCapture) { if (editor.renderer.scroller.setCapture) {
editor.renderer.scroller.setCapture(); editor.renderer.scroller.setCapture();
} }
@ -213,7 +215,6 @@ function DefaultHandlers(mouseHandler) {
this.setState("selectByWords"); this.setState("selectByWords");
} }
this.$clickSelection = range; this.$clickSelection = range;
this[this.state] && this[this.state](ev);
}; };
this.onTripleClick = function(ev) { this.onTripleClick = function(ev) {
@ -221,8 +222,13 @@ function DefaultHandlers(mouseHandler) {
var editor = this.editor; var editor = this.editor;
this.setState("selectByLines"); this.setState("selectByLines");
this.$clickSelection = editor.selection.getLineRange(pos.row); var range = editor.getSelectionRange();
this[this.state] && this[this.state](ev); if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
this.$clickSelection = editor.selection.getLineRange(range.start.row);
this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
} else {
this.$clickSelection = editor.selection.getLineRange(pos.row);
}
}; };
this.onQuadClick = function(ev) { this.onQuadClick = function(ev) {

View file

@ -54,7 +54,7 @@ function onMouseDown(e) {
return; return;
} }
if (!ctrl && !alt) { if (!ctrl && !alt && !accel) {
if (button === 0 && e.editor.inMultiSelectMode) if (button === 0 && e.editor.inMultiSelectMode)
e.editor.exitMultiSelectMode(); e.editor.exitMultiSelectMode();
return; return;
@ -70,31 +70,12 @@ function onMouseDown(e) {
var cursor = selection.getCursor(); var cursor = selection.getCursor();
var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor)); var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
var mouseX = e.x, mouseY = e.y; var mouseX = e.x, mouseY = e.y;
var onMouseSelection = function(e) { var onMouseSelection = function(e) {
mouseX = e.clientX; mouseX = e.clientX;
mouseY = e.clientY; mouseY = e.clientY;
}; };
var blockSelect = function() {
var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
if (isSamePoint(screenCursor, newCursor)
&& isSamePoint(cursor, selection.selectionLead))
return;
screenCursor = newCursor;
editor.selection.moveToPosition(cursor);
editor.renderer.scrollCursorIntoView();
editor.removeSelectionMarkers(rectSel);
rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
rectSel.forEach(editor.addSelectionMarker, editor);
editor.updateSelectionMarkers();
};
var session = editor.session; var session = editor.session;
var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY); var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
var screenCursor = screenAnchor; var screenCursor = screenAnchor;
@ -159,26 +140,57 @@ function onMouseDown(e) {
} else if (selectionMode == "block") { } else if (selectionMode == "block") {
e.stop(); e.stop();
editor.inVirtualSelectionMode = true;
if (isMultiSelect && !ctrl) var initialRange;
selection.toSingleRange();
else if (!isMultiSelect && ctrl)
selection.addRange();
var rectSel = []; var rectSel = [];
if (shift) { var blockSelect = function() {
screenAnchor = session.documentToScreenPosition(selection.lead); var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
blockSelect(); var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
} else {
selection.moveToPosition(pos); if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
return;
screenCursor = newCursor;
editor.selection.moveToPosition(cursor);
editor.renderer.scrollCursorIntoView();
editor.removeSelectionMarkers(rectSel);
rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
rectSel.forEach(editor.addSelectionMarker, editor);
editor.updateSelectionMarkers();
};
if (isMultiSelect && !accel) {
selection.toSingleRange();
} else if (!isMultiSelect && accel) {
initialRange = selection.toOrientedRange();
editor.addSelectionMarker(initialRange);
} }
if (shift)
screenAnchor = session.documentToScreenPosition(selection.lead);
else
selection.moveToPosition(pos);
screenCursor = {row: -1, column: -1};
var onMouseSelectionEnd = function(e) { var onMouseSelectionEnd = function(e) {
clearInterval(timerId); clearInterval(timerId);
editor.removeSelectionMarkers(rectSel); editor.removeSelectionMarkers(rectSel);
if (!rectSel.length)
rectSel = [selection.toOrientedRange()];
editor.$blockScrolling++;
if (initialRange) {
editor.removeSelectionMarker(initialRange);
selection.toSingleRange(initialRange);
}
for (var i = 0; i < rectSel.length; i++) for (var i = 0; i < rectSel.length; i++)
selection.addRange(rectSel[i]); selection.addRange(rectSel[i]);
editor.inVirtualSelectionMode = false;
editor.$mouseHandler.$clickSelection = null;
editor.$blockScrolling--;
}; };
var onSelectionInterval = blockSelect; var onSelectionInterval = blockSelect;