diff --git a/common/content/commands.js b/common/content/commands.js index 84de5119..cb620144 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -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) { diff --git a/common/content/events.js b/common/content/events.js index 8a150256..cebeed2b 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -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; diff --git a/common/content/finder.js b/common/content/finder.js index 7d521851..a7beed69 100644 --- a/common/content/finder.js +++ b/common/content/finder.js @@ -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( diff --git a/common/content/liberator.js b/common/content/liberator.js index 8e329f4a..65745b04 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -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); } diff --git a/common/content/mappings.js b/common/content/mappings.js index 2c77c151..4acbfb71 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -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, diff --git a/common/content/statusline.js b/common/content/statusline.js index dd44fbd7..5036617e 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -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) { diff --git a/common/content/tabs.js b/common/content/tabs.js index b8db5492..36d06752 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -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], ["", "", ""], "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", "", "", ""], "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);