1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 22:42:26 +01:00

prevent <C-x> from decrementing the number through 0

This commit is contained in:
Doug Kearns
2008-10-22 15:16:14 +00:00
parent 576899f9d0
commit beb8c6a744
2 changed files with 13 additions and 14 deletions

View File

@@ -118,24 +118,21 @@ const config = { //{{{
init: function () init: function ()
{ {
// TODO: support 'nrformats'?
function incrementURL(count) function incrementURL(count)
{ {
var url = buffer.URL; let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
var regex = /(.*?)(\d+)(\D*)$/;
var matches = url.match(regex); if (!matches)
if (!matches || !matches[2]) // no number to increment {
return liberator.beep(); liberator.beep();
return;
}
var newNum = parseInt(matches[2], 10) + count + ""; // "" to make sure its a string [, pre, number, post] = matches;
var nums = newNum.match(/^(-?)(\d+)$/); let newNumber = parseInt(number, 10) + count;
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];
liberator.open(matches[1] + newNum + matches[3]); liberator.open(pre + (newNumber > 0 ? newNumber : 0) + post);
} }
// load Vimperator specific modules // load Vimperator specific modules

View File

@@ -137,7 +137,9 @@ ________________________________________________________________________________
|<C-x>| |<C-x>|
||[count]<C-x>|| ||[count]<C-x>||
________________________________________________________________________________ ________________________________________________________________________________
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.
________________________________________________________________________________ ________________________________________________________________________________