From 6cde5f3b4f8b43af797b28f85334db8bdf68653f Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 3 Apr 2012 00:14:23 +0400 Subject: [PATCH] cleanup --- lib/ace/commands/multi_select_commands.js | 2 +- lib/ace/edit_session/fold.js | 2 +- lib/ace/mouse/fold_handler.js | 2 +- lib/ace/mouse/multi_select_handler.js | 60 +++-------------------- lib/ace/multi_select.js | 21 ++++---- lib/ace/range_list.js | 4 +- 6 files changed, 25 insertions(+), 66 deletions(-) diff --git a/lib/ace/commands/multi_select_commands.js b/lib/ace/commands/multi_select_commands.js index f2627a8f..0c5223b2 100644 --- a/lib/ace/commands/multi_select_commands.js +++ b/lib/ace/commands/multi_select_commands.js @@ -20,7 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Fabian Jakobs + * Harutyun Amirjanyan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or diff --git a/lib/ace/edit_session/fold.js b/lib/ace/edit_session/fold.js index d15bc025..8ce5e708 100644 --- a/lib/ace/edit_session/fold.js +++ b/lib/ace/edit_session/fold.js @@ -76,7 +76,7 @@ var Fold = exports.Fold = function(range, placeholder) { }; this.addSubFold = function(fold) { - if (this.range.isEequal(fold)) + if (this.range.isEqual(fold)) return this; if (!this.range.containsRange(fold)) diff --git a/lib/ace/mouse/fold_handler.js b/lib/ace/mouse/fold_handler.js index 41232024..986ca934 100644 --- a/lib/ace/mouse/fold_handler.js +++ b/lib/ace/mouse/fold_handler.js @@ -45,7 +45,7 @@ function FoldHandler(editor) { var position = e.getDocumentPosition(); var session = editor.session; - // If the user dclicked on a fold, then expand it. + // If the user clicked on a fold, then expand it. var fold = session.getFoldAt(position.row, position.column, 1); if (fold) { if (e.getAccelKey()) diff --git a/lib/ace/mouse/multi_select_handler.js b/lib/ace/mouse/multi_select_handler.js index 318d78ae..96211cac 100644 --- a/lib/ace/mouse/multi_select_handler.js +++ b/lib/ace/mouse/multi_select_handler.js @@ -102,30 +102,6 @@ function onMouseDown(e) { editor.updateSelectionMarkers() }; - var normalSelect = function() { - var clickSelection - if (_self.$clickSelection) { - if (_self.$clickSelection.contains(cursor.row, cursor.column)) { - editor.selection.setSelectionRange(_self.$clickSelection); - } - else { - if (_self.$clickSelection.compare(cursor.row, cursor.column) == -1) { - anchor = _self.$clickSelection.end; - } - else { - anchor = _self.$clickSelection.start; - } - editor.selection.setSelectionAnchor(anchor.row, anchor.column); - editor.selection.selectToPosition(cursor); - } - } - else { - editor.selection.selectToPosition(cursor); - } - - editor.renderer.scrollCursorIntoView(); - }; - var session = editor.session; var anchor = selection.getCursor(); var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY); @@ -133,50 +109,33 @@ function onMouseDown(e) { var screenCursor = screenAnchor; - onSelectionInterval = blockSelect; if (ctrl && !shift && !alt && button == 0) { if (!isMultiSelect && inSelection) return // dragging - if (!isMultiSelect) { + if (!isMultiSelect) selection.addRange(selection.toOrientedRange()); - } - if (inSelection) - selection.clearSelection(); - var helper = selection.toOrientedRange(); - editor.addSelectionMarker(helper); var oldRange = selection.rangeList.rangeAtPoint(pos); event.capture(editor.container, function(){}, function() { - editor.removeSelectionMarkers([helper]); var tmpSel = selection.toOrientedRange(); - if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor)) { - if (selection.rangeCount > 1) { - editor.selection.substractPoint(tmpSel.cursor); - var range = editor.selection.ranges[0]; - if (range) - editor.selection.addRange(range); - return; - } - } - - selection.addRange(tmpSel); + if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor)) + selection.substractPoint(tmpSel.cursor); + else + selection.addRange(tmpSel); }); - //e.stop() } else if (!shift && alt && button == 0) { e.stop() - - if (isMultiSelect && !ctrl) { + if (isMultiSelect && !ctrl) selection.toSingleRange(); - } else if (!isMultiSelect && ctrl) { + else if (!isMultiSelect && ctrl) selection.addRange(); - } selection.moveCursorToPosition(pos); selection.clearSelection(); @@ -190,9 +149,7 @@ function onMouseDown(e) { selection.addRange(rectSel[i]) }; - - - + onSelectionInterval = blockSelect; event.capture(editor.container, onMouseSelection, onMouseSelectionEnd); var timerId = setInterval(function() {onSelectionInterval()}, 20); @@ -202,7 +159,6 @@ function onMouseDown(e) { } - exports.onMouseDown = onMouseDown; }); \ No newline at end of file diff --git a/lib/ace/multi_select.js b/lib/ace/multi_select.js index 12d4569b..27cf79b6 100644 --- a/lib/ace/multi_select.js +++ b/lib/ace/multi_select.js @@ -90,7 +90,6 @@ var EditSession = require("./edit_session").EditSession; var removed = this.rangeList.add(range); - this.fromOrientedRange(range); this.$onAddRange(range); if (removed.length) @@ -123,24 +122,24 @@ var EditSession = require("./edit_session").EditSession; this.mergeOverlappingRanges = function() { var removed = this.rangeList.merge(); - var lastRange = this.ranges[0]; if (removed.length) this.$onRemoveRange(removed); - - if (lastRange) - this.fromOrientedRange(lastRange); + else + this.fromOrientedRange(this.ranges[0]); }; this.$onAddRange = function(range) { this.rangeCount = this.rangeList.ranges.length; this.ranges.unshift(range); + this.fromOrientedRange(range); this._emit("addRange", {range: range}); }; this.$onRemoveRange = function(removed) { this.rangeCount = this.rangeList.ranges.length; if (this.rangeCount == 1 && this.inMultiSelectMode) { - removed.push(this.rangeList.ranges.pop()); + var lastRange = this.rangeList.ranges.pop() + removed.push(lastRange); this.rangeCount = 0; } @@ -149,7 +148,6 @@ var EditSession = require("./edit_session").EditSession; this.ranges.splice(index, 1); } - console.log(this.ranges+'') this._emit("removeRange", {ranges: removed}); if (this.rangeCount == 0 && this.inMultiSelectMode) { @@ -158,6 +156,10 @@ var EditSession = require("./edit_session").EditSession; this.session.$undoSelect = true; this.rangeList.detach(this.session); } + + lastRange = lastRange || this.ranges[0]; + if (lastRange && !lastRange.isEqual(this.getRange())) + this.fromOrientedRange(lastRange); }; // adds multicursor support to selection @@ -448,9 +450,9 @@ var Editor = require("./editor").Editor; var words = []; for (var i = all.length; i--; ) { - var range = all[i] + var range = all[i]; if (range.isEmpty()) { - var tmp = session.getWordRange(range.start.row, range.start.column) + var tmp = session.getWordRange(range.start.row, range.start.column); range.start.row = tmp.start.row; range.start.column = tmp.start.column; range.end.row = tmp.end.row; @@ -459,6 +461,7 @@ var Editor = require("./editor").Editor; words.unshift(this.session.getTextRange(range)); } + if (dir < 0) words.unshift(words.pop()); else diff --git a/lib/ace/range_list.js b/lib/ace/range_list.js index c3dc2dd0..565bf5e1 100644 --- a/lib/ace/range_list.js +++ b/lib/ace/range_list.js @@ -19,7 +19,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Fabian Jakobs + * Harutyun Amirjanyan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -71,7 +71,7 @@ var RangeList = function(startRow, startColumn, endRow, endColumn) { }; this.add = function(range) { - var startIndex = this.pointIndex(range.start); + var startIndex = this.pointIndex(range.start); if (startIndex < 0) startIndex = -startIndex - 1;