From 241776dd4c011fcbaec45eae0316f1420bdb12bf Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 16 Jun 2012 17:07:55 +0400 Subject: [PATCH] tweak selectByWords --- lib/ace/edit_session/bracket_match.js | 5 +---- lib/ace/mouse/default_gutter_handler.js | 9 +++------ lib/ace/mouse/default_handlers.js | 17 ++++++++--------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/ace/edit_session/bracket_match.js b/lib/ace/edit_session/bracket_match.js index 4b95c1cd..9b977b8c 100644 --- a/lib/ace/edit_session/bracket_match.js +++ b/lib/ace/edit_session/bracket_match.js @@ -94,7 +94,7 @@ function BracketMatch() { var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/); if (!match) { chr = line.charAt(pos.column); - pos.column++; + pos = {row: pos.row, column: pos.column + 1}; match = chr && chr.match(/([\(\[\{])|([\)\]\}])/); before = false; } @@ -123,9 +123,6 @@ function BracketMatch() { range.cursor = range.start; } - if (!before) - pos.column--; - return range; }; diff --git a/lib/ace/mouse/default_gutter_handler.js b/lib/ace/mouse/default_gutter_handler.js index fc9b012b..21c792a1 100644 --- a/lib/ace/mouse/default_gutter_handler.js +++ b/lib/ace/mouse/default_gutter_handler.js @@ -58,13 +58,10 @@ function GutterHandler(mouseHandler) { var row = e.getDocumentPosition().row; var selection = editor.session.selection; - if (e.getShiftKey()) { + if (e.getShiftKey()) selection.selectTo(row, 0); - } else { - selection.moveCursorTo(row, 0); - selection.selectLine(); - mouseHandler.$clickSelection = selection.getRange(); - } + else + mouseHandler.$clickSelection = editor.selection.getLineRange(row); mouseHandler.captureMouse(e, "selectByLines"); return e.preventDefault(); diff --git a/lib/ace/mouse/default_handlers.js b/lib/ace/mouse/default_handlers.js index 1b916801..7fabf75d 100644 --- a/lib/ace/mouse/default_handlers.js +++ b/lib/ace/mouse/default_handlers.js @@ -65,7 +65,7 @@ function DefaultHandlers(mouseHandler) { mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange"); mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange"); - + mouseHandler.$focusWaitTimout = 250; } @@ -163,10 +163,12 @@ function DefaultHandlers(mouseHandler) { if (cmpStart == -1 && cmpEnd <= 0) { anchor = this.$clickSelection.end; - cursor = range.start; + if (range.end.row != cursor.row || range.end.column != cursor.column) + cursor = range.start; } else if (cmpEnd == 1 && cmpStart >= 0) { anchor = this.$clickSelection.start; - cursor = range.end; + if (range.start.row != cursor.row || range.start.column != cursor.column) + cursor = range.end; } else if (cmpStart == -1 && cmpEnd == 1) { cursor = range.end; anchor = range.start; @@ -286,7 +288,7 @@ function DefaultHandlers(mouseHandler) { this.setState("select"); return; } - + this.$clickSelection = editor.selection.getWordRange(pos.row, pos.column); this.setState("selectByWords"); }; @@ -296,10 +298,7 @@ function DefaultHandlers(mouseHandler) { var editor = this.editor; this.setState("selectByLines"); - - editor.moveCursorToPosition(pos); - editor.selection.selectLine(); - this.$clickSelection = editor.getSelectionRange(); + this.$clickSelection = editor.selection.getLineRange(pos.row); }; this.onQuadClick = function(ev) { @@ -345,7 +344,7 @@ function calcRangeOrientation(range, cursor) { var cmp = 2 * cursor.column - range.start.column - range.end.column; else var cmp = 2 * cursor.row - range.start.row - range.end.row; - + if (cmp < 0) return {cursor: range.start, anchor: range.end}; else