diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js index ca40cad1..02ef21ee 100644 --- a/lib/ace/autocomplete/popup.js +++ b/lib/ace/autocomplete/popup.js @@ -86,8 +86,7 @@ var AcePopup = function(parentNode) { popup.on("mousedown", function(e) { var pos = e.getDocumentPosition(); - popup.moveCursorToPosition(pos); - popup.selection.clearSelection(); + popup.selection.moveToPosition(pos); selectionMarker.start.row = selectionMarker.end.row = pos.row; e.stop(); }); diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index ce526bd5..9689ea5c 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -281,13 +281,13 @@ var EditSession = function(text, mode) { **/ this.setValue = function(text) { this.doc.setValue(text); - this.selection.moveCursorTo(0, 0); - this.selection.clearSelection(); + this.selection.moveTo(0, 0); this.$resetRowCache(0); this.$deltas = []; this.$deltasDoc = []; this.$deltasFold = []; + this.setUndoManager(this.$undoManager); this.getUndoManager().reset(); }; @@ -412,7 +412,7 @@ var EditSession = function(text, mode) { } self.mergeUndoDeltas = false; self.$deltas = []; - } + }; this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager); } }; @@ -696,7 +696,7 @@ var EditSession = function(text, mode) { this.$searchHighlight = this.addDynamicMarker(highlight); } this.$searchHighlight.setRegexp(re); - } + }; // experimental this.highlightLines = function(startRow, endRow, clazz, inFront) { diff --git a/lib/ace/editor.js b/lib/ace/editor.js index cecec203..0efbdd93 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -1941,8 +1941,7 @@ var Editor = function(renderer, session) { else this.selection.selectTo(pos.row, pos.column); } else { - this.clearSelection(); - this.moveCursorTo(pos.row, pos.column); + this.selection.moveTo(pos.row, pos.column); } } }; @@ -1977,8 +1976,7 @@ var Editor = function(renderer, session) { * @related Editor.moveCursorTo **/ this.navigateTo = function(row, column) { - this.clearSelection(); - this.moveCursorTo(row, column); + this.selection.moveTo(row, column); }; /** @@ -1993,8 +1991,7 @@ var Editor = function(renderer, session) { return this.moveCursorToPosition(selectionStart); } this.selection.clearSelection(); - times = times || 1; - this.selection.moveCursorBy(-times, 0); + this.selection.moveCursorBy(-times || -1, 0); }; /** @@ -2009,8 +2006,7 @@ var Editor = function(renderer, session) { return this.moveCursorToPosition(selectionEnd); } this.selection.clearSelection(); - times = times || 1; - this.selection.moveCursorBy(times, 0); + this.selection.moveCursorBy(times || 1, 0); }; /** @@ -2154,8 +2150,7 @@ var Editor = function(renderer, session) { this.$blockScrolling += 1; var selection = this.getSelectionRange(); - this.clearSelection(); - this.selection.moveCursorTo(0, 0); + this.selection.moveTo(0, 0); for (var i = ranges.length - 1; i >= 0; --i) { if(this.$tryReplace(ranges[i], replacement)) { diff --git a/lib/ace/ext/emmet.js b/lib/ace/ext/emmet.js index 6647da40..896a66d8 100644 --- a/lib/ace/ext/emmet.js +++ b/lib/ace/ext/emmet.js @@ -130,8 +130,7 @@ AceEmmetEditor.prototype = { */ setCaretPos: function(index){ var pos = this.ace.indexToPosition(index); - this.ace.clearSelection(); - this.ace.selection.moveCursorToPosition(pos); + this.ace.selection.moveToPosition(pos); }, /** diff --git a/lib/ace/ext/error_marker.js b/lib/ace/ext/error_marker.js index 18de2b88..2f5466b0 100644 --- a/lib/ace/ext/error_marker.js +++ b/lib/ace/ext/error_marker.js @@ -122,8 +122,7 @@ exports.showErrorMarker = function(editor, dir) { }; } editor.session.unfold(pos.row); - editor.selection.moveCursorToPosition(pos); - editor.selection.clearSelection(); + editor.selection.moveToPosition(pos); var w = { row: pos.row, diff --git a/lib/ace/keyboard/vim/commands.js b/lib/ace/keyboard/vim/commands.js index dd3357d6..e48446f4 100644 --- a/lib/ace/keyboard/vim/commands.js +++ b/lib/ace/keyboard/vim/commands.js @@ -201,8 +201,7 @@ var actions = exports.actions = { //editor.selection.selectLine(); //editor.selection.selectLeft(); var row = editor.getCursorPosition().row; - editor.selection.clearSelection(); - editor.selection.moveCursorTo(row, 0); + editor.selection.moveTo(row, 0); editor.selection.selectLineEnd(); editor.selection.visualLineStart = row; @@ -582,13 +581,11 @@ var handleCursorMove = exports.onCursorMove = function(editor, e) { var cursorRow = editor.getCursorPosition().row; if(originRow <= cursorRow) { var endLine = editor.session.getLine(cursorRow); - editor.selection.clearSelection(); - editor.selection.moveCursorTo(originRow, 0); + editor.selection.moveTo(originRow, 0); editor.selection.selectTo(cursorRow, endLine.length); } else { var endLine = editor.session.getLine(originRow); - editor.selection.clearSelection(); - editor.selection.moveCursorTo(originRow, endLine.length); + editor.selection.moveTo(originRow, endLine.length); editor.selection.selectTo(cursorRow, 0); } } diff --git a/lib/ace/keyboard/vim/maps/motions.js b/lib/ace/keyboard/vim/maps/motions.js index ae457d54..630ba66a 100644 --- a/lib/ace/keyboard/vim/maps/motions.js +++ b/lib/ace/keyboard/vim/maps/motions.js @@ -53,8 +53,7 @@ function Motion(m) { var a = getPos(editor, range, count, param, false); if (!a) return; - editor.clearSelection(); - editor.moveCursorTo(a.row, a.column); + editor.selection.moveTo(a.row, a.column); }; m.sel = function(editor, range, count, param) { var a = getPos(editor, range, count, param, true); diff --git a/lib/ace/keyboard/vim/maps/util.js b/lib/ace/keyboard/vim/maps/util.js index af0e07c7..a216c2cc 100644 --- a/lib/ace/keyboard/vim/maps/util.js +++ b/lib/ace/keyboard/vim/maps/util.js @@ -122,13 +122,11 @@ module.exports = { }, copyLine: function(editor) { var pos = editor.getCursorPosition(); - editor.selection.clearSelection(); - editor.moveCursorTo(pos.row, pos.column); + editor.selection.moveTo(pos.row, pos.column); editor.selection.selectLine(); registers._default.isLine = true; registers._default.text = editor.getCopyText().replace(/\n$/, ""); - editor.selection.clearSelection(); - editor.moveCursorTo(pos.row, pos.column); + editor.selection.moveTo(pos.row, pos.column); } }; }); diff --git a/lib/ace/mouse/default_handlers.js b/lib/ace/mouse/default_handlers.js index 84e0ac48..6e97bc5d 100644 --- a/lib/ace/mouse/default_handlers.js +++ b/lib/ace/mouse/default_handlers.js @@ -72,8 +72,7 @@ function DefaultHandlers(mouseHandler) { var selectionEmpty = selectionRange.isEmpty(); if (selectionEmpty) { - editor.moveCursorToPosition(pos); - editor.selection.clearSelection(); + editor.selection.moveToPosition(pos); } // 2: contextmenu, 1: linux paste @@ -93,6 +92,7 @@ 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. @@ -101,7 +101,6 @@ function DefaultHandlers(mouseHandler) { this.mousedownEvent.time = Date.now(); this.startSelect(pos); } - this.captureMouse(ev); return ev.preventDefault(); }; @@ -114,8 +113,7 @@ function DefaultHandlers(mouseHandler) { editor.selection.selectToPosition(pos); } else if (!this.$clickSelection) { - editor.moveCursorToPosition(pos); - editor.selection.clearSelection(); + editor.selection.moveToPosition(pos); } if (editor.renderer.scroller.setCapture) { editor.renderer.scroller.setCapture(); diff --git a/lib/ace/mouse/multi_select_handler.js b/lib/ace/mouse/multi_select_handler.js index f9c79c4a..88dc6668 100644 --- a/lib/ace/mouse/multi_select_handler.js +++ b/lib/ace/mouse/multi_select_handler.js @@ -32,7 +32,6 @@ define(function(require, exports, module) { var event = require("../lib/event"); - // mouse function isSamePoint(p1, p2) { return p1.row == p2.row && p1.column == p2.column; @@ -79,8 +78,7 @@ function onMouseDown(e) { return; screenCursor = newCursor; - editor.selection.moveCursorToPosition(cursor); - editor.selection.clearSelection(); + editor.selection.moveToPosition(cursor); editor.renderer.scrollCursorIntoView(); editor.removeSelectionMarkers(rectSel); @@ -95,7 +93,7 @@ function onMouseDown(e) { - if (ctrl && !shift && !alt && button == 0) { + if (ctrl && !alt && !shift && button === 0) { if (!isMultiSelect && inSelection) return; // dragging @@ -122,7 +120,7 @@ function onMouseDown(e) { editor.$blockScrolling--; }); - } else if (alt && button == 0) { + } else if (alt && button === 0) { e.stop(); if (isMultiSelect && !ctrl) @@ -135,8 +133,7 @@ function onMouseDown(e) { screenAnchor = session.documentToScreenPosition(selection.lead); blockSelect(); } else { - selection.moveCursorToPosition(pos); - selection.clearSelection(); + selection.moveToPosition(pos); } diff --git a/lib/ace/selection.js b/lib/ace/selection.js index adfb6518..712021ad 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -298,6 +298,27 @@ var Selection = function(session) { }); }; + /** + * Moves the selection cursor to the indicated row and column. + * @param {Number} row The row to select to + * @param {Number} column The column to select to + * + **/ + this.moveTo = function(row, column) { + this.clearSelection(); + this.moveCursorTo(row, column); + }; + + /** + * Moves the selection cursor to the row and column indicated by `pos`. + * @param {Object} pos An object containing the row and column + **/ + this.moveToPosition = function(pos) { + this.clearSelection(); + this.moveCursorToPosition(pos); + }; + + /** * * Moves the selection up one row.