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:
@@ -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
|
||||
|
||||
@@ -137,7 +137,9 @@ ________________________________________________________________________________
|
||||
|<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.
|
||||
________________________________________________________________________________
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user