Merge pull request #2052 from ajaxorg/double_tap

fix Double tapping to select words doesn't work reliably
This commit is contained in:
Lennart Kats 2014-07-21 14:06:19 +02:00
commit b71a09d8d0
4 changed files with 19 additions and 45 deletions

View file

@ -415,28 +415,11 @@ bindDropdown("folding", function(value) {
}); });
bindDropdown("soft_wrap", function(value) { bindDropdown("soft_wrap", function(value) {
var session = env.editor.session; env.editor.setOption("wrap", value);
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);
}
}); });
bindCheckbox("select_style", function(checked) { bindCheckbox("select_style", function(checked) {
env.editor.setSelectionStyle(checked ? "line" : "text"); env.editor.setOption("selectionStyle", checked ? "line" : "text");
}); });
bindCheckbox("highlight_active", function(checked) { bindCheckbox("highlight_active", function(checked) {

View file

@ -191,6 +191,8 @@ exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbac
startY = e.clientY; startY = e.clientY;
} }
} }
e._clicks = clicks;
eventHandler[callbackName]("mousedown", e); eventHandler[callbackName]("mousedown", e);

View file

@ -71,21 +71,20 @@ function DefaultHandlers(mouseHandler) {
var selectionRange = editor.getSelectionRange(); var selectionRange = editor.getSelectionRange();
var selectionEmpty = selectionRange.isEmpty(); var selectionEmpty = selectionRange.isEmpty();
if (selectionEmpty) { if (selectionEmpty)
editor.selection.moveToPosition(pos); editor.selection.moveToPosition(pos);
}
// 2: contextmenu, 1: linux paste // 2: contextmenu, 1: linux paste
editor.textInput.onContextMenu(ev.domEvent); editor.textInput.onContextMenu(ev.domEvent);
return; // stopping event here breaks contextmenu on ff mac 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 // if this click caused the editor to be focused should not clear the
// selection // selection
if (inSelection && !editor.isFocused()) { if (inSelection && !editor.isFocused()) {
editor.focus(); editor.focus();
if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) { if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
this.mousedownEvent.time = Date.now();
this.setState("focusWait"); this.setState("focusWait");
this.captureMouse(ev); this.captureMouse(ev);
return; return;
@ -93,31 +92,21 @@ function DefaultHandlers(mouseHandler) {
} }
this.captureMouse(ev); this.captureMouse(ev);
if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) { this.startSelect(pos, ev.domEvent._clicks > 1);
// 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);
}
return ev.preventDefault(); return ev.preventDefault();
}; };
this.startSelect = function(pos) { this.startSelect = function(pos, waitForClickSelection) {
pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y); pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
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();
setTimeout(function(){ if (this.mousedownEvent.getShiftKey())
if (shiftPressed) { editor.selection.selectToPosition(pos);
editor.selection.selectToPosition(pos); else if (!waitForClickSelection)
} editor.selection.moveToPosition(pos);
else if (!this.$clickSelection) { if (!waitForClickSelection)
editor.selection.moveToPosition(pos);
}
this.select(); this.select();
}.bind(this), 0);
if (editor.renderer.scroller.setCapture) { if (editor.renderer.scroller.setCapture) {
editor.renderer.scroller.setCapture(); editor.renderer.scroller.setCapture();
} }
@ -216,6 +205,7 @@ function DefaultHandlers(mouseHandler) {
this.setState("selectByWords"); this.setState("selectByWords");
} }
this.$clickSelection = range; this.$clickSelection = range;
this.select();
}; };
this.onTripleClick = function(ev) { this.onTripleClick = function(ev) {
@ -230,6 +220,7 @@ function DefaultHandlers(mouseHandler) {
} else { } else {
this.$clickSelection = editor.selection.getLineRange(pos.row); this.$clickSelection = editor.selection.getLineRange(pos.row);
} }
this.select();
}; };
this.onQuadClick = function(ev) { this.onQuadClick = function(ev) {

View file

@ -58,17 +58,15 @@ module.exports = {
next(); next();
}, },
"test: double tap. issue #956" : function(done) { "test: double tap. issue #956" : function() {
// mouse up fired immediately after mouse down // mouse up fired immediately after mouse down
var target = this.editor.renderer.getMouseEventTarget(); var target = this.editor.renderer.getMouseEventTarget();
target.dispatchEvent(MouseEvent("down", {x: 1, y: 1})); target.dispatchEvent(MouseEvent("down", {x: 1, y: 1}));
target.dispatchEvent(MouseEvent("up", {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("down", {x: 1, y: 1, detail: 2}));
target.dispatchEvent(MouseEvent("up", {x: 1, y: 1, detail: 2})); target.dispatchEvent(MouseEvent("up", {x: 1, y: 1, detail: 2}));
setTimeout(function() {
assert.equal(this.editor.getSelectedText(), "Juhu"); assert.equal(this.editor.getSelectedText(), "Juhu");
done();
}.bind(this));
} }
}; };