From 4f5fd70ab242b2aaf0779210f937a00cdcd2704e Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Fri, 5 Nov 2010 00:49:46 +1100 Subject: [PATCH] Make Browser.incrementURL a little more readable. --HG-- extra : rebase_source : d297c23cb02a5b977297938f2086905ffa6a031c --- common/content/browser.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/content/browser.js b/common/content/browser.js index a931b819..5ff1289c 100644 --- a/common/content/browser.js +++ b/common/content/browser.js @@ -27,16 +27,16 @@ const Browser = Module("browser", { incrementURL: function (count) { let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/); dactyl.assert(matches); + oldNum = matches[2]; - let [, pre, number, post] = matches; - let newNumber = parseInt(number, 10) + count; - let newNumberStr = String(newNumber > 0 ? newNumber : 0); - if (number.match(/^0/)) { // add 0009 should become 0010 - while (newNumberStr.length < number.length) - newNumberStr = "0" + newNumberStr; - } + // disallow negative numbers as trailing numbers are often proceeded by hyphens + let newNum = String(Math.max(parseInt(oldNum, 10) + count, 0)); + if (/^0/.test(oldNum)) + while (newNum.length < oldNum.length) + newNum = "0" + newNum; - dactyl.open(pre + newNumberStr + post); + matches[2] = newNum; + dactyl.open(matches.slice(1).join("")); } }, { options: function () {