diff --git a/lib/ace/mouse_handler.js b/lib/ace/mouse_handler.js index 2f7b30a7..cf5ccb9a 100644 --- a/lib/ace/mouse_handler.js +++ b/lib/ace/mouse_handler.js @@ -94,24 +94,33 @@ var MouseHandler = function(editor) { }; this.onMouseDown = function(e) { - // if this click caused the editor to be focused ignore the click - // for selection and cursor placement - if ( - !this.browserFocus.isFocused() - || new Date().getTime() - this.browserFocus.lastFocus < 20 - || !this.editor.isFocused() - ) - return; - var pageX = event.getDocumentX(e); var pageY = event.getDocumentY(e); + var pos = this.$getEventPosition(e); + var editor = this.editor; var self = this; var selectionRange = editor.getSelectionRange(); var selectionEmpty = selectionRange.isEmpty(); + var inSelection = !editor.getReadOnly() + && !selectionEmpty + && selectionRange.contains(pos.row, pos.column); + var state = STATE_UNKNOWN; - var inSelection = false; + + // if this click caused the editor to be focused should not clear the + // selection + if ( + inSelection && ( + !this.browserFocus.isFocused() + || new Date().getTime() - this.browserFocus.lastFocus < 20 + || !this.editor.isFocused() + ) + ) { + this.editor.focus(); + return; + } var button = event.getButton(e); if (button !== 0) { @@ -130,10 +139,6 @@ var MouseHandler = function(editor) { editor.selection.setSelectionRange(fold.range); return; } - - inSelection = !editor.getReadOnly() - && !selectionEmpty - && selectionRange.contains(pos.row, pos.column); } if (!inSelection) { @@ -261,8 +266,7 @@ var MouseHandler = function(editor) { var onDragSelectionInterval = function() { dragCursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY); - dragCursor.row = Math.max(0, Math.min(dragCursor.row, - editor.session.getLength() - 1)); + dragCursor.row = Math.max(0, Math.min(dragCursor.row, editor.session.getLength() - 1)); editor.moveCursorToPosition(dragCursor); };