1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 20:27:58 +01:00

More RangeFind work.

This commit is contained in:
Kris Maglione
2009-11-13 03:00:46 -05:00
parent f19a4edcee
commit 12012af693
7 changed files with 27 additions and 22 deletions

View File

@@ -142,7 +142,7 @@ const Command = Class("Command", {
execute: function (args, bang, count, modifiers) {
// XXX
bang = !!bang;
count = (count === undefined) ? -1 : count;
count = (count === undefined) ? null : count;
modifiers = modifiers || {};
let self = this;
@@ -287,11 +287,11 @@ const Commands = Module("commands", {
OPTION_LIST: 6,
/**
* @property {number} Indicates that no count was specified for this
* @property Indicates that no count was specified for this
* command invocation.
* @final
*/
COUNT_NONE: -1,
COUNT_NONE: null,
/**
* @property {number} Indicates that the full buffer range (1,$) was
* specified for this command invocation.
@@ -748,7 +748,7 @@ const Commands = Module("commands", {
// parse count
if (count)
count = count == "%" ? this.COUNT_ALL: parseInt(count, 10);
count = count == "%" ? this.COUNT_ALL : parseInt(count, 10);
else
count = this.COUNT_NONE;
@@ -1022,6 +1022,7 @@ const Commands = Module("commands", {
// 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
// : No, array comprehensions are fine, generator statements aren't. --Kris
let cmds = this._exCommands.filter(function (c) c.user && (!cmd || c.name.match("^" + cmd)));
if (cmds.length > 0) {

View File

@@ -65,7 +65,7 @@ const Events = Module("events", {
buffer: "", // partial command storage
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}
count: -1 // parsed count from the input buffer
count: null // parsed count from the input buffer
};
function onResize(event) {
@@ -1009,7 +1009,7 @@ const Events = Module("events", {
this._input.pendingMap = null;
this._input.count = parseInt(countStr, 10);
if (isNaN(this._input.count))
this._input.count = -1;
this._input.count = null;
this._input.buffer = "";
if (map.arg) {
this._input.buffer = inputStr;

View File

@@ -615,10 +615,10 @@ const RangeFinder = Module("rangefinder", {
const RangeFind = Class("RangeFind", {
init: function (matchCase, backward) {
this.matchCase = Boolean(matchCase);
this._backward = Boolean(backward);
this.finder = services.create("find");
this.finder.caseSensitive = matchCase;
this.matchCase = matchCase;
this._backward = backward;
this.finder.caseSensitive = this.matchCase;
this.ranges = this.makeFrameList(content);
this.range = RangeFind.Range(tabs.localStore.focusedFrame || content);
@@ -735,6 +735,7 @@ const RangeFind = Class("RangeFind", {
},
search: function (word, reverse, private) {
this.wrapped = false;
this.finder.findBackwards = reverse ? !this._backward : this._backward;
let again = word == null;
if (again)
@@ -756,19 +757,23 @@ const RangeFind = Class("RangeFind", {
else {
function indices() {
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;
if (private)
return;
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;
}
for (let i in indices.call(this)) {
this.range = this.ranges[i];
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);;
if (this.backward && !again)
start = RangeFind.endpoint(this.startRange, false);
var range = this.finder.Find(word, this.range.range, start, this.range.range);
if (range)
@@ -791,7 +796,6 @@ const RangeFind = Class("RangeFind", {
this.found = false;
return null;
}
this.wrapped = false;
this.range.selection.removeAllRanges();
this.range.selection.addRange(range);
this.range.selectionController.scrollSelectionIntoView(

View File

@@ -449,7 +449,7 @@ const Liberator = Module("liberator", {
}
else if (command.action === null)
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";
else if (special && !command.bang)
err = "E477: No ! allowed";
@@ -1652,7 +1652,7 @@ const Liberator = Module("liberator", {
let setFrom = vbs.setFrom;
try {
vbs.set(args.count > -1 ? args.count : 1);
vbs.set(args.count || 1);
vbs.setFrom = null;
liberator.execute(args[0], null, true);
}

View File

@@ -386,7 +386,7 @@ const Mappings = Module("mappings", {
mappings.addUserMap(modes, [lhs],
"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,
rhs: events.canonicalKeys(rhs),
noremap: !!noremap,

View File

@@ -102,7 +102,7 @@ const StatusLine = Module("statusline", {
let sh = window.getWebNavigation().sessionHistory;
if (sh && sh.index > 0)
modified += "+";
if (sh && sh.index < sh.count -1)
if (sh && sh.index < sh.count - 1)
modified += "-";
}
if (modules.bookmarks) {

View File

@@ -869,7 +869,7 @@ const Tabs = Module("tabs", {
if (args.length)
args = args[0];
else
args = Math.max(args.count, 0);
args = args.count || 0;
let m;
if (m = /^(\d+)(:|$)/.exec(args || '1'))
@@ -929,7 +929,7 @@ const Tabs = Module("tabs", {
mappings.add([modes.NORMAL], ["gt"],
"Go to the next tab",
function (count) {
if (count > 0)
if (count != null)
tabs.select(count - 1, false);
else
tabs.select("+1", true);
@@ -938,19 +938,19 @@ const Tabs = Module("tabs", {
mappings.add([modes.NORMAL], ["<C-n>", "<C-Tab>", "<C-PageDown>"],
"Go to the next tab",
function (count) { tabs.select("+" + (count < 1 ? 1 : count), true); },
function (count) { tabs.select("+" + (count || 1), true); },
{ count: true });
mappings.add([modes.NORMAL], ["gT", "<C-p>", "<C-S-Tab>", "<C-PageUp>"],
"Go to previous tab",
function (count) { tabs.select("-" + (count < 1 ? 1 : count), true); },
function (count) { tabs.select("-" + (count || 1), true); },
{ count: true });
if (config.hasTabbrowser) {
mappings.add([modes.NORMAL], ["b"],
"Open a prompt to switch buffers",
function (count) {
if (count != -1)
if (count != null)
tabs.switchTo(String(count));
else
commandline.open(":", "buffer! ", modes.EX);