add editor.findAll
This commit is contained in:
parent
e80a862f3e
commit
01d053c46b
2 changed files with 58 additions and 12 deletions
|
|
@ -125,7 +125,7 @@ function onMouseDown(e) {
|
|||
selection.substractPoint(tmpSel.cursor);
|
||||
else {
|
||||
if (range) {
|
||||
editor.removeSelectionMarkers([range]);
|
||||
editor.removeSelectionMarker(range);
|
||||
selection.addRange(range);
|
||||
}
|
||||
selection.addRange(tmpSel);
|
||||
|
|
|
|||
|
|
@ -76,22 +76,19 @@ var EditSession = require("./edit_session").EditSession;
|
|||
*
|
||||
* adds a range to selection entering multiselect mode if necessary
|
||||
**/
|
||||
this.addRange = function(range) {
|
||||
this.addRange = function(range, $blockChangeEvents) {
|
||||
if (!range)
|
||||
return;
|
||||
|
||||
if (!this.inMultiSelectMode && this.rangeCount == 0) {
|
||||
var oldRange = this.toOrientedRange();
|
||||
if (range.intersects(oldRange)) {
|
||||
this.fromOrientedRange(range);
|
||||
return;
|
||||
}
|
||||
|
||||
if (range.intersects(oldRange))
|
||||
return $blockChangeEvents || this.fromOrientedRange(range);
|
||||
|
||||
this.rangeList.add(oldRange);
|
||||
this.$onAddRange(oldRange);
|
||||
}
|
||||
|
||||
|
||||
if (!range.cursor)
|
||||
range.cursor = range.end;
|
||||
|
||||
|
|
@ -108,6 +105,8 @@ var EditSession = require("./edit_session").EditSession;
|
|||
this.session.$undoSelect = false;
|
||||
this.rangeList.attach(this.session);
|
||||
}
|
||||
|
||||
return $blockChangeEvents || this.fromOrientedRange(range);
|
||||
};
|
||||
|
||||
this.toSingleRange = function(range) {
|
||||
|
|
@ -149,7 +148,6 @@ var EditSession = require("./edit_session").EditSession;
|
|||
this.$onAddRange = function(range) {
|
||||
this.rangeCount = this.rangeList.ranges.length;
|
||||
this.ranges.unshift(range);
|
||||
this.fromOrientedRange(range);
|
||||
this._emit("addRange", {range: range});
|
||||
};
|
||||
|
||||
|
|
@ -313,17 +311,34 @@ var Editor = require("./editor").Editor;
|
|||
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) {
|
||||
var markerList = this.session.$selectionMarkers;
|
||||
for (var i = ranges.length; i--; ) {
|
||||
var range = ranges[i];
|
||||
if (!range.marker)
|
||||
continue;
|
||||
this.session.removeMarker(range.marker);
|
||||
var index = this.session.$selectionMarkers.indexOf(range);
|
||||
var index = markerList.indexOf(range);
|
||||
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) {
|
||||
|
|
@ -446,6 +461,37 @@ var Editor = require("./editor").Editor;
|
|||
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
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue