diff --git a/content/vimperator.js b/content/vimperator.js index e2e6e969..65d63912 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -118,24 +118,21 @@ const config = { //{{{ init: function () { + // TODO: support 'nrformats'? function incrementURL(count) { - var url = buffer.URL; - var regex = /(.*?)(\d+)(\D*)$/; + let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/); - var matches = url.match(regex); - if (!matches || !matches[2]) // no number to increment - return liberator.beep(); + if (!matches) + { + liberator.beep(); + return; + } - var newNum = parseInt(matches[2], 10) + count + ""; // "" to make sure its a string - var nums = newNum.match(/^(-?)(\d+)$/); - var oldLength = matches[2].replace(/-/, "").length, newLength = nums[2].length; - newNum = nums[1] || ""; - for (let i = 0; i < oldLength - newLength; i++) - newNum += "0"; // keep leading zeros - newNum += nums[2]; + [, pre, number, post] = matches; + let newNumber = parseInt(number, 10) + count; - liberator.open(matches[1] + newNum + matches[3]); + liberator.open(pre + (newNumber > 0 ? newNumber : 0) + post); } // load Vimperator specific modules diff --git a/locale/en-US/browsing.txt b/locale/en-US/browsing.txt index 11d0b337..7a7554f4 100644 --- a/locale/en-US/browsing.txt +++ b/locale/en-US/browsing.txt @@ -137,7 +137,9 @@ ________________________________________________________________________________ || ||[count]|| ________________________________________________________________________________ -Decrements the last number in URL by 1, or by [count] if given. +Decrements the last number in URL by 1, or by [count] if given. Negative +numbers are not supported, as this not generally useful, so the number cannot +be decremented past 0. ________________________________________________________________________________