From 389d33acac3be30bb50bafb36b197d4456b23837 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Sat, 19 Feb 2011 11:20:47 +0100 Subject: [PATCH] some more mouse handler fixes --- lib/ace/mouse_handler.js | 47 +++++++++++++++++++++++++--------------- support/pilot | 2 +- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/ace/mouse_handler.js b/lib/ace/mouse_handler.js index 848fab9d..e3e74527 100644 --- a/lib/ace/mouse_handler.js +++ b/lib/ace/mouse_handler.js @@ -42,12 +42,12 @@ define(function(require, exports, module) { var event = require("pilot/event"); var dom = require("pilot/dom"); -const STATE_UNKNOWN = 0; -const STATE_SELECT = 1; -const STATE_DRAG = 2; +var STATE_UNKNOWN = 0; +var STATE_SELECT = 1; +var STATE_DRAG = 2; -const DRAG_TIMER = 500; // milliseconds -const DRAG_OFFSET = 5; // pixels +var DRAG_TIMER = 250; // milliseconds +var DRAG_OFFSET = 5; // pixels var MouseHandler = function(editor) { this.editor = editor; @@ -115,17 +115,9 @@ var MouseHandler = function(editor) { selectionRange.contains(pos.row, pos.column); if (!inSelection) { - if (e.shiftKey) - editor.selection.selectToPosition(pos) - else { - editor.moveCursorToPosition(pos); - if (!editor.$clickSelection) - editor.selection.clearSelection(pos.row, pos.column); - } - // Directly pick STATE_SELECT, since the user is not clicking inside // a selection. - state = STATE_SELECT; + onStartSelect(pos); } editor.renderer.scrollCursorIntoView(); @@ -143,7 +135,9 @@ var MouseHandler = function(editor) { var onMouseSelectionEnd = function() { clearInterval(timerId); - if (state == STATE_DRAG) + if (state == STATE_UNKNOWN) { + onStartSelect(pos); + } else if (state == STATE_DRAG) onMouseDragSelectionEnd(); else self.$clickSelection = null; @@ -189,19 +183,36 @@ var MouseHandler = function(editor) { var distance = self.$distance(pageX, pageY, mousePageX, mousePageY); var time = (new Date()).getTime(); - if (distance > DRAG_OFFSET) + + if (distance > DRAG_OFFSET) { state = STATE_SELECT; - else if ((time - mousedownTime) > DRAG_TIMER) { + var cursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY); + cursor.row = Math.max(0, Math.min(cursor.row, editor.session.getLength()-1)); + onStartSelect(cursor); + } else if ((time - mousedownTime) > DRAG_TIMER) { state = STATE_DRAG; dom.addCssClass(editor.container, "ace_dragging"); } - } else if (state == STATE_DRAG) + } + + if (state == STATE_DRAG) onDragSelectionInterval(); else if (state == STATE_SELECT) onUpdateSelectionInterval(); }; + function onStartSelect(pos) { + if (e.shiftKey) + editor.selection.selectToPosition(pos) + else { + editor.moveCursorToPosition(pos); + if (!editor.$clickSelection) + editor.selection.clearSelection(pos.row, pos.column); + } + state = STATE_SELECT; + } + var onUpdateSelectionInterval = function() { var cursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY); cursor.row = Math.max(0, Math.min(cursor.row, editor.session.getLength()-1)); diff --git a/support/pilot b/support/pilot index 6e1fbe1d..cbfac498 160000 --- a/support/pilot +++ b/support/pilot @@ -1 +1 @@ -Subproject commit 6e1fbe1dfdff64020f15cd9e23ea72b7803cf406 +Subproject commit cbfac498d30d43fdb7687d198c5b752736222c2f