mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-20 16:05:47 +01:00
Make Browser.incrementURL a little more readable.
--HG-- extra : rebase_source : d297c23cb02a5b977297938f2086905ffa6a031c
This commit is contained in:
@@ -27,16 +27,16 @@ const Browser = Module("browser", {
|
|||||||
incrementURL: function (count) {
|
incrementURL: function (count) {
|
||||||
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
|
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
|
||||||
dactyl.assert(matches);
|
dactyl.assert(matches);
|
||||||
|
oldNum = matches[2];
|
||||||
|
|
||||||
let [, pre, number, post] = matches;
|
// disallow negative numbers as trailing numbers are often proceeded by hyphens
|
||||||
let newNumber = parseInt(number, 10) + count;
|
let newNum = String(Math.max(parseInt(oldNum, 10) + count, 0));
|
||||||
let newNumberStr = String(newNumber > 0 ? newNumber : 0);
|
if (/^0/.test(oldNum))
|
||||||
if (number.match(/^0/)) { // add 0009<C-a> should become 0010
|
while (newNum.length < oldNum.length)
|
||||||
while (newNumberStr.length < number.length)
|
newNum = "0" + newNum;
|
||||||
newNumberStr = "0" + newNumberStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
dactyl.open(pre + newNumberStr + post);
|
matches[2] = newNum;
|
||||||
|
dactyl.open(matches.slice(1).join(""));
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
options: function () {
|
options: function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user