commit
2c1f7951c2
3 changed files with 60 additions and 13 deletions
|
|
@ -1163,11 +1163,12 @@ var Editor = function(renderer, session) {
|
||||||
if (!ranges.length)
|
if (!ranges.length)
|
||||||
return replaced;
|
return replaced;
|
||||||
|
|
||||||
|
this.$blockScrolling += 1;
|
||||||
|
|
||||||
var selection = this.getSelectionRange();
|
var selection = this.getSelectionRange();
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.selection.moveCursorTo(0, 0);
|
this.selection.moveCursorTo(0, 0);
|
||||||
|
|
||||||
this.$blockScrolling += 1;
|
|
||||||
for (var i = ranges.length - 1; i >= 0; --i) {
|
for (var i = ranges.length - 1; i >= 0; --i) {
|
||||||
if(this.$tryReplace(ranges[i], replacement)) {
|
if(this.$tryReplace(ranges[i], replacement)) {
|
||||||
replaced++;
|
replaced++;
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ function onMouseDown(e) {
|
||||||
selection.substractPoint(tmpSel.cursor);
|
selection.substractPoint(tmpSel.cursor);
|
||||||
else {
|
else {
|
||||||
if (range) {
|
if (range) {
|
||||||
editor.removeSelectionMarkers([range]);
|
editor.removeSelectionMarker(range);
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
}
|
}
|
||||||
selection.addRange(tmpSel);
|
selection.addRange(tmpSel);
|
||||||
|
|
|
||||||
|
|
@ -76,22 +76,19 @@ var EditSession = require("./edit_session").EditSession;
|
||||||
*
|
*
|
||||||
* adds a range to selection entering multiselect mode if necessary
|
* adds a range to selection entering multiselect mode if necessary
|
||||||
**/
|
**/
|
||||||
this.addRange = function(range) {
|
this.addRange = function(range, $blockChangeEvents) {
|
||||||
if (!range)
|
if (!range)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.inMultiSelectMode && this.rangeCount == 0) {
|
if (!this.inMultiSelectMode && this.rangeCount == 0) {
|
||||||
var oldRange = this.toOrientedRange();
|
var oldRange = this.toOrientedRange();
|
||||||
if (range.intersects(oldRange)) {
|
if (range.intersects(oldRange))
|
||||||
this.fromOrientedRange(range);
|
return $blockChangeEvents || this.fromOrientedRange(range);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rangeList.add(oldRange);
|
this.rangeList.add(oldRange);
|
||||||
this.$onAddRange(oldRange);
|
this.$onAddRange(oldRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!range.cursor)
|
if (!range.cursor)
|
||||||
range.cursor = range.end;
|
range.cursor = range.end;
|
||||||
|
|
||||||
|
|
@ -108,6 +105,8 @@ var EditSession = require("./edit_session").EditSession;
|
||||||
this.session.$undoSelect = false;
|
this.session.$undoSelect = false;
|
||||||
this.rangeList.attach(this.session);
|
this.rangeList.attach(this.session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $blockChangeEvents || this.fromOrientedRange(range);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toSingleRange = function(range) {
|
this.toSingleRange = function(range) {
|
||||||
|
|
@ -149,7 +148,6 @@ var EditSession = require("./edit_session").EditSession;
|
||||||
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});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -313,17 +311,34 @@ var Editor = require("./editor").Editor;
|
||||||
return orientedRange;
|
return orientedRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editor.removeSelectionMarker(range) -> Void
|
||||||
|
* - range: selection range added with addSelectionMarker
|
||||||
|
*
|
||||||
|
* removes selection marker
|
||||||
|
**/
|
||||||
|
this.removeSelectionMarker = function(range) {
|
||||||
|
if (!range.marker)
|
||||||
|
return;
|
||||||
|
this.session.removeMarker(range.marker);
|
||||||
|
var index = this.session.$selectionMarkers.indexOf(range);
|
||||||
|
if (index != -1)
|
||||||
|
this.session.$selectionMarkers.splice(index, 1);
|
||||||
|
this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
|
||||||
|
};
|
||||||
|
|
||||||
this.removeSelectionMarkers = function(ranges) {
|
this.removeSelectionMarkers = function(ranges) {
|
||||||
|
var markerList = this.session.$selectionMarkers;
|
||||||
for (var i = ranges.length; i--; ) {
|
for (var i = ranges.length; i--; ) {
|
||||||
var range = ranges[i];
|
var range = ranges[i];
|
||||||
if (!range.marker)
|
if (!range.marker)
|
||||||
continue;
|
continue;
|
||||||
this.session.removeMarker(range.marker);
|
this.session.removeMarker(range.marker);
|
||||||
var index = this.session.$selectionMarkers.indexOf(range);
|
var index = markerList.indexOf(range);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
this.session.$selectionMarkers.splice(index, 1);
|
markerList.splice(index, 1);
|
||||||
}
|
}
|
||||||
this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
|
this.session.selectionMarkerCount = markerList.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$onAddRange = function(e) {
|
this.$onAddRange = function(e) {
|
||||||
|
|
@ -446,6 +461,37 @@ var Editor = require("./editor").Editor;
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editor.findAll(dir, options) -> Number
|
||||||
|
* - needle: text to find
|
||||||
|
* - options: search options
|
||||||
|
* - additive: keeps
|
||||||
|
*
|
||||||
|
* finds and selects all the occurencies of needle
|
||||||
|
* returns number of found ranges
|
||||||
|
**/
|
||||||
|
this.findAll = function(needle, options, additive) {
|
||||||
|
options = options || {};
|
||||||
|
options.needle = needle || options.needle;
|
||||||
|
this.$search.set(options);
|
||||||
|
|
||||||
|
var ranges = this.$search.findAll(this.session);
|
||||||
|
if (!ranges.length)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
this.$blockScrolling += 1;
|
||||||
|
var selection = this.multiSelect;
|
||||||
|
|
||||||
|
if (!additive)
|
||||||
|
selection.toSingleRange(ranges[0]);
|
||||||
|
|
||||||
|
for (var i = ranges.length; i--; )
|
||||||
|
selection.addRange(ranges[i], true);
|
||||||
|
|
||||||
|
this.$blockScrolling -= 1;
|
||||||
|
|
||||||
|
return ranges.length;
|
||||||
|
};
|
||||||
|
|
||||||
// commands
|
// commands
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue