This commit is contained in:
nightwing 2012-04-03 00:14:23 +04:00
commit 6cde5f3b4f
6 changed files with 25 additions and 66 deletions

View file

@ -20,7 +20,7 @@
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Fabian Jakobs <fabian AT ajax DOT org> * Harutyun Amirjanyan <amirjanyan AT gmail DOT com>
* *
* Alternatively, the contents of this file may be used under the terms of * 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 * either the GNU General Public License Version 2 or later (the "GPL"), or

View file

@ -76,7 +76,7 @@ var Fold = exports.Fold = function(range, placeholder) {
}; };
this.addSubFold = function(fold) { this.addSubFold = function(fold) {
if (this.range.isEequal(fold)) if (this.range.isEqual(fold))
return this; return this;
if (!this.range.containsRange(fold)) if (!this.range.containsRange(fold))

View file

@ -45,7 +45,7 @@ function FoldHandler(editor) {
var position = e.getDocumentPosition(); var position = e.getDocumentPosition();
var session = editor.session; 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); var fold = session.getFoldAt(position.row, position.column, 1);
if (fold) { if (fold) {
if (e.getAccelKey()) if (e.getAccelKey())

View file

@ -102,30 +102,6 @@ function onMouseDown(e) {
editor.updateSelectionMarkers() 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 session = editor.session;
var anchor = selection.getCursor(); var anchor = selection.getCursor();
var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY); var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
@ -133,50 +109,33 @@ function onMouseDown(e) {
var screenCursor = screenAnchor; var screenCursor = screenAnchor;
onSelectionInterval = blockSelect;
if (ctrl && !shift && !alt && button == 0) { if (ctrl && !shift && !alt && button == 0) {
if (!isMultiSelect && inSelection) if (!isMultiSelect && inSelection)
return // dragging return // dragging
if (!isMultiSelect) { if (!isMultiSelect)
selection.addRange(selection.toOrientedRange()); selection.addRange(selection.toOrientedRange());
}
if (inSelection)
selection.clearSelection();
var helper = selection.toOrientedRange();
editor.addSelectionMarker(helper);
var oldRange = selection.rangeList.rangeAtPoint(pos); var oldRange = selection.rangeList.rangeAtPoint(pos);
event.capture(editor.container, function(){}, function() { event.capture(editor.container, function(){}, function() {
editor.removeSelectionMarkers([helper]);
var tmpSel = selection.toOrientedRange(); var tmpSel = selection.toOrientedRange();
if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor)) { if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
if (selection.rangeCount > 1) { selection.substractPoint(tmpSel.cursor);
editor.selection.substractPoint(tmpSel.cursor); else
var range = editor.selection.ranges[0];
if (range)
editor.selection.addRange(range);
return;
}
}
selection.addRange(tmpSel); selection.addRange(tmpSel);
}); });
//e.stop()
} else if (!shift && alt && button == 0) { } else if (!shift && alt && button == 0) {
e.stop() e.stop()
if (isMultiSelect && !ctrl)
if (isMultiSelect && !ctrl) {
selection.toSingleRange(); selection.toSingleRange();
} else if (!isMultiSelect && ctrl) { else if (!isMultiSelect && ctrl)
selection.addRange(); selection.addRange();
}
selection.moveCursorToPosition(pos); selection.moveCursorToPosition(pos);
selection.clearSelection(); selection.clearSelection();
@ -190,9 +149,7 @@ function onMouseDown(e) {
selection.addRange(rectSel[i]) selection.addRange(rectSel[i])
}; };
onSelectionInterval = blockSelect;
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd); event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
var timerId = setInterval(function() {onSelectionInterval()}, 20); var timerId = setInterval(function() {onSelectionInterval()}, 20);
@ -202,7 +159,6 @@ function onMouseDown(e) {
} }
exports.onMouseDown = onMouseDown; exports.onMouseDown = onMouseDown;
}); });

View file

@ -90,7 +90,6 @@ var EditSession = require("./edit_session").EditSession;
var removed = this.rangeList.add(range); var removed = this.rangeList.add(range);
this.fromOrientedRange(range);
this.$onAddRange(range); this.$onAddRange(range);
if (removed.length) if (removed.length)
@ -123,24 +122,24 @@ var EditSession = require("./edit_session").EditSession;
this.mergeOverlappingRanges = function() { this.mergeOverlappingRanges = function() {
var removed = this.rangeList.merge(); var removed = this.rangeList.merge();
var lastRange = this.ranges[0];
if (removed.length) if (removed.length)
this.$onRemoveRange(removed); this.$onRemoveRange(removed);
else
if (lastRange) this.fromOrientedRange(this.ranges[0]);
this.fromOrientedRange(lastRange);
}; };
this.$onAddRange = function(range) { this.$onAddRange = function(range) {
this.rangeCount = this.rangeList.ranges.length; this.rangeCount = this.rangeList.ranges.length;
this.ranges.unshift(range); this.ranges.unshift(range);
this.fromOrientedRange(range);
this._emit("addRange", {range: range}); this._emit("addRange", {range: range});
}; };
this.$onRemoveRange = function(removed) { this.$onRemoveRange = function(removed) {
this.rangeCount = this.rangeList.ranges.length; this.rangeCount = this.rangeList.ranges.length;
if (this.rangeCount == 1 && this.inMultiSelectMode) { if (this.rangeCount == 1 && this.inMultiSelectMode) {
removed.push(this.rangeList.ranges.pop()); var lastRange = this.rangeList.ranges.pop()
removed.push(lastRange);
this.rangeCount = 0; this.rangeCount = 0;
} }
@ -149,7 +148,6 @@ var EditSession = require("./edit_session").EditSession;
this.ranges.splice(index, 1); this.ranges.splice(index, 1);
} }
console.log(this.ranges+'')
this._emit("removeRange", {ranges: removed}); this._emit("removeRange", {ranges: removed});
if (this.rangeCount == 0 && this.inMultiSelectMode) { if (this.rangeCount == 0 && this.inMultiSelectMode) {
@ -158,6 +156,10 @@ var EditSession = require("./edit_session").EditSession;
this.session.$undoSelect = true; this.session.$undoSelect = true;
this.rangeList.detach(this.session); this.rangeList.detach(this.session);
} }
lastRange = lastRange || this.ranges[0];
if (lastRange && !lastRange.isEqual(this.getRange()))
this.fromOrientedRange(lastRange);
}; };
// adds multicursor support to selection // adds multicursor support to selection
@ -448,9 +450,9 @@ var Editor = require("./editor").Editor;
var words = []; var words = [];
for (var i = all.length; i--; ) { for (var i = all.length; i--; ) {
var range = all[i] var range = all[i];
if (range.isEmpty()) { 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.row = tmp.start.row;
range.start.column = tmp.start.column; range.start.column = tmp.start.column;
range.end.row = tmp.end.row; range.end.row = tmp.end.row;
@ -459,6 +461,7 @@ var Editor = require("./editor").Editor;
words.unshift(this.session.getTextRange(range)); words.unshift(this.session.getTextRange(range));
} }
if (dir < 0) if (dir < 0)
words.unshift(words.pop()); words.unshift(words.pop());
else else

View file

@ -19,7 +19,7 @@
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Fabian Jakobs <fabian AT ajax DOT org> * Harutyun Amirjanyan <amirjanyan AT gmail DOT com>
* *
* Alternatively, the contents of this file may be used under the terms of * 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 * either the GNU General Public License Version 2 or later (the "GPL"), or