Merge pull request #2052 from ajaxorg/double_tap
fix Double tapping to select words doesn't work reliably
This commit is contained in:
commit
b71a09d8d0
4 changed files with 19 additions and 45 deletions
|
|
@ -415,28 +415,11 @@ bindDropdown("folding", function(value) {
|
|||
});
|
||||
|
||||
bindDropdown("soft_wrap", function(value) {
|
||||
var session = env.editor.session;
|
||||
var renderer = env.editor.renderer;
|
||||
switch (value) {
|
||||
case "off":
|
||||
session.setUseWrapMode(false);
|
||||
renderer.setPrintMarginColumn(80);
|
||||
break;
|
||||
case "free":
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(null, null);
|
||||
renderer.setPrintMarginColumn(80);
|
||||
break;
|
||||
default:
|
||||
session.setUseWrapMode(true);
|
||||
var col = parseInt(value, 10);
|
||||
session.setWrapLimitRange(col, col);
|
||||
renderer.setPrintMarginColumn(col);
|
||||
}
|
||||
env.editor.setOption("wrap", value);
|
||||
});
|
||||
|
||||
bindCheckbox("select_style", function(checked) {
|
||||
env.editor.setSelectionStyle(checked ? "line" : "text");
|
||||
env.editor.setOption("selectionStyle", checked ? "line" : "text");
|
||||
});
|
||||
|
||||
bindCheckbox("highlight_active", function(checked) {
|
||||
|
|
|
|||
|
|
@ -191,6 +191,8 @@ exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbac
|
|||
startY = e.clientY;
|
||||
}
|
||||
}
|
||||
|
||||
e._clicks = clicks;
|
||||
|
||||
eventHandler[callbackName]("mousedown", e);
|
||||
|
||||
|
|
|
|||
|
|
@ -71,21 +71,20 @@ function DefaultHandlers(mouseHandler) {
|
|||
var selectionRange = editor.getSelectionRange();
|
||||
var selectionEmpty = selectionRange.isEmpty();
|
||||
|
||||
if (selectionEmpty) {
|
||||
if (selectionEmpty)
|
||||
editor.selection.moveToPosition(pos);
|
||||
}
|
||||
|
||||
// 2: contextmenu, 1: linux paste
|
||||
editor.textInput.onContextMenu(ev.domEvent);
|
||||
return; // stopping event here breaks contextmenu on ff mac
|
||||
}
|
||||
|
||||
this.mousedownEvent.time = Date.now();
|
||||
// if this click caused the editor to be focused should not clear the
|
||||
// selection
|
||||
if (inSelection && !editor.isFocused()) {
|
||||
editor.focus();
|
||||
if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
|
||||
this.mousedownEvent.time = Date.now();
|
||||
this.setState("focusWait");
|
||||
this.captureMouse(ev);
|
||||
return;
|
||||
|
|
@ -93,31 +92,21 @@ function DefaultHandlers(mouseHandler) {
|
|||
}
|
||||
|
||||
this.captureMouse(ev);
|
||||
if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) {
|
||||
// Directly pick STATE_SELECT, since the user is not clicking inside
|
||||
// a selection.
|
||||
this.startSelect(pos);
|
||||
} else if (inSelection) {
|
||||
this.mousedownEvent.time = Date.now();
|
||||
this.startSelect(pos);
|
||||
}
|
||||
this.startSelect(pos, ev.domEvent._clicks > 1);
|
||||
return ev.preventDefault();
|
||||
};
|
||||
|
||||
this.startSelect = function(pos) {
|
||||
this.startSelect = function(pos, waitForClickSelection) {
|
||||
pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
|
||||
var editor = this.editor;
|
||||
// allow double/triple click handlers to change selection
|
||||
var shiftPressed = this.mousedownEvent.getShiftKey();
|
||||
setTimeout(function(){
|
||||
if (shiftPressed) {
|
||||
editor.selection.selectToPosition(pos);
|
||||
}
|
||||
else if (!this.$clickSelection) {
|
||||
editor.selection.moveToPosition(pos);
|
||||
}
|
||||
|
||||
if (this.mousedownEvent.getShiftKey())
|
||||
editor.selection.selectToPosition(pos);
|
||||
else if (!waitForClickSelection)
|
||||
editor.selection.moveToPosition(pos);
|
||||
if (!waitForClickSelection)
|
||||
this.select();
|
||||
}.bind(this), 0);
|
||||
if (editor.renderer.scroller.setCapture) {
|
||||
editor.renderer.scroller.setCapture();
|
||||
}
|
||||
|
|
@ -216,6 +205,7 @@ function DefaultHandlers(mouseHandler) {
|
|||
this.setState("selectByWords");
|
||||
}
|
||||
this.$clickSelection = range;
|
||||
this.select();
|
||||
};
|
||||
|
||||
this.onTripleClick = function(ev) {
|
||||
|
|
@ -230,6 +220,7 @@ function DefaultHandlers(mouseHandler) {
|
|||
} else {
|
||||
this.$clickSelection = editor.selection.getLineRange(pos.row);
|
||||
}
|
||||
this.select();
|
||||
};
|
||||
|
||||
this.onQuadClick = function(ev) {
|
||||
|
|
|
|||
|
|
@ -58,17 +58,15 @@ module.exports = {
|
|||
next();
|
||||
},
|
||||
|
||||
"test: double tap. issue #956" : function(done) {
|
||||
"test: double tap. issue #956" : function() {
|
||||
// mouse up fired immediately after mouse down
|
||||
var target = this.editor.renderer.getMouseEventTarget();
|
||||
target.dispatchEvent(MouseEvent("down", {x: 1, y: 1}));
|
||||
target.dispatchEvent(MouseEvent("up", {x: 1, y: 1}));
|
||||
target.dispatchEvent(MouseEvent("down", {x: 1, y: 1, detail: 2}));
|
||||
target.dispatchEvent(MouseEvent("up", {x: 1, y: 1, detail: 2}));
|
||||
setTimeout(function() {
|
||||
assert.equal(this.editor.getSelectedText(), "Juhu");
|
||||
done();
|
||||
}.bind(this));
|
||||
|
||||
assert.equal(this.editor.getSelectedText(), "Juhu");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue