mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 00:28:00 +01:00
More RangeFind work.
This commit is contained in:
@@ -142,7 +142,7 @@ const Command = Class("Command", {
|
|||||||
execute: function (args, bang, count, modifiers) {
|
execute: function (args, bang, count, modifiers) {
|
||||||
// XXX
|
// XXX
|
||||||
bang = !!bang;
|
bang = !!bang;
|
||||||
count = (count === undefined) ? -1 : count;
|
count = (count === undefined) ? null : count;
|
||||||
modifiers = modifiers || {};
|
modifiers = modifiers || {};
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
@@ -287,11 +287,11 @@ const Commands = Module("commands", {
|
|||||||
OPTION_LIST: 6,
|
OPTION_LIST: 6,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} Indicates that no count was specified for this
|
* @property Indicates that no count was specified for this
|
||||||
* command invocation.
|
* command invocation.
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
COUNT_NONE: -1,
|
COUNT_NONE: null,
|
||||||
/**
|
/**
|
||||||
* @property {number} Indicates that the full buffer range (1,$) was
|
* @property {number} Indicates that the full buffer range (1,$) was
|
||||||
* specified for this command invocation.
|
* specified for this command invocation.
|
||||||
@@ -748,7 +748,7 @@ const Commands = Module("commands", {
|
|||||||
|
|
||||||
// parse count
|
// parse count
|
||||||
if (count)
|
if (count)
|
||||||
count = count == "%" ? this.COUNT_ALL: parseInt(count, 10);
|
count = count == "%" ? this.COUNT_ALL : parseInt(count, 10);
|
||||||
else
|
else
|
||||||
count = this.COUNT_NONE;
|
count = this.COUNT_NONE;
|
||||||
|
|
||||||
@@ -1022,6 +1022,7 @@ const Commands = Module("commands", {
|
|||||||
|
|
||||||
// TODO: using an array comprehension here generates flakey results across repeated calls
|
// TODO: using an array comprehension here generates flakey results across repeated calls
|
||||||
// : perhaps we shouldn't allow options in a list call but just ignore them for now
|
// : perhaps we shouldn't allow options in a list call but just ignore them for now
|
||||||
|
// : No, array comprehensions are fine, generator statements aren't. --Kris
|
||||||
let cmds = this._exCommands.filter(function (c) c.user && (!cmd || c.name.match("^" + cmd)));
|
let cmds = this._exCommands.filter(function (c) c.user && (!cmd || c.name.match("^" + cmd)));
|
||||||
|
|
||||||
if (cmds.length > 0) {
|
if (cmds.length > 0) {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ const Events = Module("events", {
|
|||||||
buffer: "", // partial command storage
|
buffer: "", // partial command storage
|
||||||
pendingMotionMap: null, // e.g. "d{motion}" if we wait for a motion of the "d" command
|
pendingMotionMap: null, // e.g. "d{motion}" if we wait for a motion of the "d" command
|
||||||
pendingArgMap: null, // pending map storage for commands like m{a-z}
|
pendingArgMap: null, // pending map storage for commands like m{a-z}
|
||||||
count: -1 // parsed count from the input buffer
|
count: null // parsed count from the input buffer
|
||||||
};
|
};
|
||||||
|
|
||||||
function onResize(event) {
|
function onResize(event) {
|
||||||
@@ -1009,7 +1009,7 @@ const Events = Module("events", {
|
|||||||
this._input.pendingMap = null;
|
this._input.pendingMap = null;
|
||||||
this._input.count = parseInt(countStr, 10);
|
this._input.count = parseInt(countStr, 10);
|
||||||
if (isNaN(this._input.count))
|
if (isNaN(this._input.count))
|
||||||
this._input.count = -1;
|
this._input.count = null;
|
||||||
this._input.buffer = "";
|
this._input.buffer = "";
|
||||||
if (map.arg) {
|
if (map.arg) {
|
||||||
this._input.buffer = inputStr;
|
this._input.buffer = inputStr;
|
||||||
|
|||||||
@@ -615,10 +615,10 @@ const RangeFinder = Module("rangefinder", {
|
|||||||
|
|
||||||
const RangeFind = Class("RangeFind", {
|
const RangeFind = Class("RangeFind", {
|
||||||
init: function (matchCase, backward) {
|
init: function (matchCase, backward) {
|
||||||
|
this.matchCase = Boolean(matchCase);
|
||||||
|
this._backward = Boolean(backward);
|
||||||
this.finder = services.create("find");
|
this.finder = services.create("find");
|
||||||
this.finder.caseSensitive = matchCase;
|
this.finder.caseSensitive = this.matchCase;
|
||||||
this.matchCase = matchCase;
|
|
||||||
this._backward = backward;
|
|
||||||
|
|
||||||
this.ranges = this.makeFrameList(content);
|
this.ranges = this.makeFrameList(content);
|
||||||
this.range = RangeFind.Range(tabs.localStore.focusedFrame || content);
|
this.range = RangeFind.Range(tabs.localStore.focusedFrame || content);
|
||||||
@@ -735,6 +735,7 @@ const RangeFind = Class("RangeFind", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
search: function (word, reverse, private) {
|
search: function (word, reverse, private) {
|
||||||
|
this.wrapped = false;
|
||||||
this.finder.findBackwards = reverse ? !this._backward : this._backward;
|
this.finder.findBackwards = reverse ? !this._backward : this._backward;
|
||||||
let again = word == null;
|
let again = word == null;
|
||||||
if (again)
|
if (again)
|
||||||
@@ -756,19 +757,23 @@ const RangeFind = Class("RangeFind", {
|
|||||||
else {
|
else {
|
||||||
function indices() {
|
function indices() {
|
||||||
let idx = this.range.index;
|
let idx = this.range.index;
|
||||||
for (let i in this.backward ? util.range(idx + 1, -1, -1) : util.range(idx, this.ranges.length))
|
for (let i in this.backward ? util.range(idx + 1, 0, -1) : util.range(idx, this.ranges.length))
|
||||||
yield i;
|
yield i;
|
||||||
if (private)
|
if (private)
|
||||||
return;
|
return;
|
||||||
this.wrapped = true;
|
this.wrapped = true;
|
||||||
for (let i in this.backward ? util.range(this.ranges.length, idx, -1) : util.range(0, idx))
|
this.lastRange = null;
|
||||||
|
for (let i in this.backward ? util.range(this.ranges.length, idx, -1) : util.range(0, idx + 1))
|
||||||
yield i;
|
yield i;
|
||||||
}
|
}
|
||||||
for (let i in indices.call(this)) {
|
for (let i in indices.call(this)) {
|
||||||
this.range = this.ranges[i];
|
this.range = this.ranges[i];
|
||||||
|
|
||||||
let start = this.sameDocument(this.lastRange, this.range.range) ?
|
let start = this.sameDocument(this.lastRange, this.range.range) ?
|
||||||
RangeFind.endpoint(this.lastRange, this.backward) :
|
RangeFind.endpoint(this.lastRange, !(again ^ this.backward)) :
|
||||||
RangeFind.endpoint(this.range.range, !this.backward);;
|
RangeFind.endpoint(this.range.range, !this.backward);;
|
||||||
|
if (this.backward && !again)
|
||||||
|
start = RangeFind.endpoint(this.startRange, false);
|
||||||
|
|
||||||
var range = this.finder.Find(word, this.range.range, start, this.range.range);
|
var range = this.finder.Find(word, this.range.range, start, this.range.range);
|
||||||
if (range)
|
if (range)
|
||||||
@@ -791,7 +796,6 @@ const RangeFind = Class("RangeFind", {
|
|||||||
this.found = false;
|
this.found = false;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this.wrapped = false;
|
|
||||||
this.range.selection.removeAllRanges();
|
this.range.selection.removeAllRanges();
|
||||||
this.range.selection.addRange(range);
|
this.range.selection.addRange(range);
|
||||||
this.range.selectionController.scrollSelectionIntoView(
|
this.range.selectionController.scrollSelectionIntoView(
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ const Liberator = Module("liberator", {
|
|||||||
}
|
}
|
||||||
else if (command.action === null)
|
else if (command.action === null)
|
||||||
err = "E666: Internal error: command.action === null"; // TODO: need to perform this test? -- djk
|
err = "E666: Internal error: command.action === null"; // TODO: need to perform this test? -- djk
|
||||||
else if (count != -1 && !command.count)
|
else if (count != null && !command.count)
|
||||||
err = "E481: No range allowed";
|
err = "E481: No range allowed";
|
||||||
else if (special && !command.bang)
|
else if (special && !command.bang)
|
||||||
err = "E477: No ! allowed";
|
err = "E477: No ! allowed";
|
||||||
@@ -1652,7 +1652,7 @@ const Liberator = Module("liberator", {
|
|||||||
let setFrom = vbs.setFrom;
|
let setFrom = vbs.setFrom;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vbs.set(args.count > -1 ? args.count : 1);
|
vbs.set(args.count || 1);
|
||||||
vbs.setFrom = null;
|
vbs.setFrom = null;
|
||||||
liberator.execute(args[0], null, true);
|
liberator.execute(args[0], null, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ const Mappings = Module("mappings", {
|
|||||||
|
|
||||||
mappings.addUserMap(modes, [lhs],
|
mappings.addUserMap(modes, [lhs],
|
||||||
"User defined mapping",
|
"User defined mapping",
|
||||||
function (count) { events.feedkeys((count > -1 ? count : "") + this.rhs, this.noremap, this.silent); }, {
|
function (count) { events.feedkeys((count || "") + this.rhs, this.noremap, this.silent); }, {
|
||||||
count: true,
|
count: true,
|
||||||
rhs: events.canonicalKeys(rhs),
|
rhs: events.canonicalKeys(rhs),
|
||||||
noremap: !!noremap,
|
noremap: !!noremap,
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ const StatusLine = Module("statusline", {
|
|||||||
let sh = window.getWebNavigation().sessionHistory;
|
let sh = window.getWebNavigation().sessionHistory;
|
||||||
if (sh && sh.index > 0)
|
if (sh && sh.index > 0)
|
||||||
modified += "+";
|
modified += "+";
|
||||||
if (sh && sh.index < sh.count -1)
|
if (sh && sh.index < sh.count - 1)
|
||||||
modified += "-";
|
modified += "-";
|
||||||
}
|
}
|
||||||
if (modules.bookmarks) {
|
if (modules.bookmarks) {
|
||||||
|
|||||||
@@ -869,7 +869,7 @@ const Tabs = Module("tabs", {
|
|||||||
if (args.length)
|
if (args.length)
|
||||||
args = args[0];
|
args = args[0];
|
||||||
else
|
else
|
||||||
args = Math.max(args.count, 0);
|
args = args.count || 0;
|
||||||
|
|
||||||
let m;
|
let m;
|
||||||
if (m = /^(\d+)(:|$)/.exec(args || '1'))
|
if (m = /^(\d+)(:|$)/.exec(args || '1'))
|
||||||
@@ -929,7 +929,7 @@ const Tabs = Module("tabs", {
|
|||||||
mappings.add([modes.NORMAL], ["gt"],
|
mappings.add([modes.NORMAL], ["gt"],
|
||||||
"Go to the next tab",
|
"Go to the next tab",
|
||||||
function (count) {
|
function (count) {
|
||||||
if (count > 0)
|
if (count != null)
|
||||||
tabs.select(count - 1, false);
|
tabs.select(count - 1, false);
|
||||||
else
|
else
|
||||||
tabs.select("+1", true);
|
tabs.select("+1", true);
|
||||||
@@ -938,19 +938,19 @@ const Tabs = Module("tabs", {
|
|||||||
|
|
||||||
mappings.add([modes.NORMAL], ["<C-n>", "<C-Tab>", "<C-PageDown>"],
|
mappings.add([modes.NORMAL], ["<C-n>", "<C-Tab>", "<C-PageDown>"],
|
||||||
"Go to the next tab",
|
"Go to the next tab",
|
||||||
function (count) { tabs.select("+" + (count < 1 ? 1 : count), true); },
|
function (count) { tabs.select("+" + (count || 1), true); },
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
mappings.add([modes.NORMAL], ["gT", "<C-p>", "<C-S-Tab>", "<C-PageUp>"],
|
mappings.add([modes.NORMAL], ["gT", "<C-p>", "<C-S-Tab>", "<C-PageUp>"],
|
||||||
"Go to previous tab",
|
"Go to previous tab",
|
||||||
function (count) { tabs.select("-" + (count < 1 ? 1 : count), true); },
|
function (count) { tabs.select("-" + (count || 1), true); },
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
if (config.hasTabbrowser) {
|
if (config.hasTabbrowser) {
|
||||||
mappings.add([modes.NORMAL], ["b"],
|
mappings.add([modes.NORMAL], ["b"],
|
||||||
"Open a prompt to switch buffers",
|
"Open a prompt to switch buffers",
|
||||||
function (count) {
|
function (count) {
|
||||||
if (count != -1)
|
if (count != null)
|
||||||
tabs.switchTo(String(count));
|
tabs.switchTo(String(count));
|
||||||
else
|
else
|
||||||
commandline.open(":", "buffer! ", modes.EX);
|
commandline.open(":", "buffer! ", modes.EX);
|
||||||
|
|||||||
Reference in New Issue
Block a user