mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-28 20:35:46 +01:00
More RangeFind stuff.
This commit is contained in:
@@ -464,6 +464,8 @@ const RangeFinder = Module("rangefinder", {
|
|||||||
requires: ["config"],
|
requires: ["config"],
|
||||||
|
|
||||||
init: function () {
|
init: function () {
|
||||||
|
this.lastSearchString = "";
|
||||||
|
this.lastSearchBackwards = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
openPrompt: function (mode) {
|
openPrompt: function (mode) {
|
||||||
@@ -475,9 +477,9 @@ const RangeFinder = Module("rangefinder", {
|
|||||||
|
|
||||||
find: function (str, backwards) {
|
find: function (str, backwards) {
|
||||||
let caseSensitive = false;
|
let caseSensitive = false;
|
||||||
if (this.rangeFind)
|
let highlighted = this.rangeFind && this.rangeFind.highlighted; // Kludge?
|
||||||
this.clear();
|
|
||||||
this.rangeFind = RangeFind(caseSensitive, backwards);
|
this.rangeFind = RangeFind(caseSensitive, backwards);
|
||||||
|
this.rangeFind.highlighted = highlighted;
|
||||||
|
|
||||||
if (!this.rangeFind.search(str))
|
if (!this.rangeFind.search(str))
|
||||||
setTimeout(function () { liberator.echoerr("E486: Pattern not found: " + str); }, 0);
|
setTimeout(function () { liberator.echoerr("E486: Pattern not found: " + str); }, 0);
|
||||||
@@ -487,9 +489,9 @@ const RangeFinder = Module("rangefinder", {
|
|||||||
|
|
||||||
findAgain: function (reverse) {
|
findAgain: function (reverse) {
|
||||||
if (!this.rangeFind)
|
if (!this.rangeFind)
|
||||||
this.find(this._lastSearchString);
|
this.find(this.lastSearchString);
|
||||||
else if (!this.rangeFind.search(null, reverse))
|
else if (!this.rangeFind.search(null, reverse))
|
||||||
liberator.echoerr("E486: Pattern not found: " + lastSearchPattern);
|
liberator.echoerr("E486: Pattern not found: " + this.lastSearchString);
|
||||||
else if (this.rangeFind.wrapped) {
|
else if (this.rangeFind.wrapped) {
|
||||||
// hack needed, because wrapping causes a "scroll" event which clears
|
// hack needed, because wrapping causes a "scroll" event which clears
|
||||||
// our command line
|
// our command line
|
||||||
@@ -499,12 +501,11 @@ const RangeFinder = Module("rangefinder", {
|
|||||||
commandline.echo(msg, commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES);
|
commandline.echo(msg, commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES);
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
liberator.echo((this.rangeFind.backward ? "?" : "/") + lastSearchPattern, null, commandline.FORCE_SINGLELINE);
|
commandline.echo((this.rangeFind.backward ? "?" : "/") + this.lastSearchString, null, commandline.FORCE_SINGLELINE);
|
||||||
|
|
||||||
if (options["hlsearch"])
|
if (options["hlsearch"])
|
||||||
this.highlight(this.rangeFind.lastString);
|
this.highlight();
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called when the user types a key in the search dialog. Triggers a find attempt if 'incsearch' is set
|
// Called when the user types a key in the search dialog. Triggers a find attempt if 'incsearch' is set
|
||||||
@@ -516,12 +517,11 @@ const RangeFinder = Module("rangefinder", {
|
|||||||
onSubmit: function (command) {
|
onSubmit: function (command) {
|
||||||
if (!options["incsearch"] || !this.rangeFind || !this.rangeFind.found) {
|
if (!options["incsearch"] || !this.rangeFind || !this.rangeFind.found) {
|
||||||
this.clear();
|
this.clear();
|
||||||
this.find(command || this._lastSearchString, this._lastSearchBackwards);
|
this.find(command || this.lastSearchString, this.lastSearchBackwards);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._lastSearchBackwards = this.rangeFind.backwards;
|
this.lastSearchBackwards = this.rangeFind.backwards;
|
||||||
this._lastSearchPattern = command;
|
this.lastSearchString = this.rangeFind.searchString;
|
||||||
this._lastSearchString = command;
|
|
||||||
|
|
||||||
if (options["hlsearch"])
|
if (options["hlsearch"])
|
||||||
this.highlight();
|
this.highlight();
|
||||||
@@ -535,7 +535,6 @@ const RangeFinder = Module("rangefinder", {
|
|||||||
// TODO: code to reposition the document to the place before search started
|
// TODO: code to reposition the document to the place before search started
|
||||||
if (this.rangeFind)
|
if (this.rangeFind)
|
||||||
this.rangeFind.cancel();
|
this.rangeFind.cancel();
|
||||||
this.rangeFind = null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get rangeFind() tabs.localStore.rangeFind,
|
get rangeFind() tabs.localStore.rangeFind,
|
||||||
@@ -629,6 +628,7 @@ const RangeFind = Class("RangeFind", {
|
|||||||
this.range = this.findRange(this.startRange);
|
this.range = this.findRange(this.startRange);
|
||||||
this.ranges.first = this.range;
|
this.ranges.first = this.range;
|
||||||
|
|
||||||
|
this.highlighted = null;
|
||||||
this.lastString = "";
|
this.lastString = "";
|
||||||
this.lastRange = null;
|
this.lastRange = null;
|
||||||
this.forward = null;
|
this.forward = null;
|
||||||
@@ -719,19 +719,18 @@ const RangeFind = Class("RangeFind", {
|
|||||||
get searchString() this.lastString,
|
get searchString() this.lastString,
|
||||||
get backward() this.finder.findBackwards,
|
get backward() this.finder.findBackwards,
|
||||||
|
|
||||||
__iterator__: function () {
|
iter: function (word) {
|
||||||
let range = this.range;
|
let saved = ["range", "lastRange", "lastString"].map(this.closure(function (s) [s, this[s]]))
|
||||||
let lastRange = this.lastRange
|
|
||||||
try {
|
try {
|
||||||
this.range = this.ranges[0];
|
this.range = this.ranges[0];
|
||||||
this.lastRange = null;
|
this.lastRange = null;
|
||||||
|
this.lastString = word
|
||||||
var res;
|
var res;
|
||||||
while (res = this.search(null, this._backward, true))
|
while (res = this.search(null, this._backward, true))
|
||||||
yield res;
|
yield res;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
this.range = range;
|
saved.forEach(function ([k, v]) this[k] = v, this)
|
||||||
this.lastRange = lastRange;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -802,13 +801,15 @@ const RangeFind = Class("RangeFind", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
highlight: function (clear) {
|
highlight: function (clear) {
|
||||||
if (!this.lastString)
|
|
||||||
|
if (!clear && (!this.lastString || this.lastString == this.highlighted))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!clear)
|
if (!clear && this.highlighted)
|
||||||
for (let range in values(this.ranges))
|
this.highlight(true);
|
||||||
if (util.evaluateXPath("//@liberator:highlight[1][.='Search']").snapshotLength)
|
|
||||||
return;
|
if (clear && !this.highlighted)
|
||||||
|
return;
|
||||||
|
|
||||||
let span = util.xmlToDom(<span highlight="Search"/>, this.range.document);
|
let span = util.xmlToDom(<span highlight="Search"/>, this.range.document);
|
||||||
|
|
||||||
@@ -838,15 +839,18 @@ const RangeFind = Class("RangeFind", {
|
|||||||
parent.normalize();
|
parent.normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.range.save();
|
|
||||||
let action = clear ? unhighlight : highlight;
|
let action = clear ? unhighlight : highlight;
|
||||||
for (let r in this) {
|
let string = this[clear ? "highlighted" : "lastString"];
|
||||||
|
for (let r in this.iter(string)) {
|
||||||
action(r);
|
action(r);
|
||||||
this.lastRange = r;
|
this.lastRange = r;
|
||||||
}
|
}
|
||||||
this.range.deselect();
|
if (clear)
|
||||||
if (!clear)
|
this.highlighted = null;
|
||||||
|
else {
|
||||||
|
this.highlighted = this.lastString;
|
||||||
this.search(null, false);
|
this.search(null, false);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
cancel: function () {
|
cancel: function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user