diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 552b1e65..c7beb3d0 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -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) { diff --git a/lib/ace/lib/event.js b/lib/ace/lib/event.js index 612b6a34..b8e2199d 100644 --- a/lib/ace/lib/event.js +++ b/lib/ace/lib/event.js @@ -191,6 +191,8 @@ exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbac startY = e.clientY; } } + + e._clicks = clicks; eventHandler[callbackName]("mousedown", e); diff --git a/lib/ace/mouse/default_handlers.js b/lib/ace/mouse/default_handlers.js index e7a31540..bbd85484 100644 --- a/lib/ace/mouse/default_handlers.js +++ b/lib/ace/mouse/default_handlers.js @@ -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) { diff --git a/lib/ace/mouse/mouse_handler_test.js b/lib/ace/mouse/mouse_handler_test.js index 571acdac..96374d71 100644 --- a/lib/ace/mouse/mouse_handler_test.js +++ b/lib/ace/mouse/mouse_handler_test.js @@ -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"); } };