From 4912348398a373394f20e8f8350532555e23cf3e Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Wed, 6 May 2009 21:33:21 +1000 Subject: [PATCH] Normalise the count arg of map actions with Math.max. Passing an arg object to these actions as is done for commands might be better. --- common/content/buffer.js | 34 ++++++++++++++++----------------- common/content/tabs.js | 2 +- muttator/content/mail.js | 4 ++-- vimperator/content/bookmarks.js | 8 ++++---- vimperator/content/config.js | 4 ++-- xulmus/content/bookmarks.js | 8 ++++---- xulmus/content/config.js | 4 ++-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/common/content/buffer.js b/common/content/buffer.js index b4927118..512a541a 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -266,22 +266,22 @@ function Buffer() //{{{ // scrolling mappings.add(myModes, ["j", "", ""], "Scroll document down", - function (count) { buffer.scrollLines(count > 1 ? count : 1); }, + function (count) { buffer.scrollLines(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["k", "", ""], "Scroll document up", - function (count) { buffer.scrollLines(-(count > 1 ? count : 1)); }, + function (count) { buffer.scrollLines(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, liberator.has("mail") ? ["h"] : ["h", ""], "Scroll document to the left", - function (count) { buffer.scrollColumns(-(count > 1 ? count : 1)); }, + function (count) { buffer.scrollColumns(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, liberator.has("mail") ? ["l"] : ["l", ""], "Scroll document to the right", - function (count) { buffer.scrollColumns(count > 1 ? count : 1); }, + function (count) { buffer.scrollColumns(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["0", "^"], @@ -294,7 +294,7 @@ function Buffer() //{{{ mappings.add(myModes, ["gg", ""], "Go to the top of the document", - function (count) { buffer.scrollToPercentile(count > 0 ? count : 0); }, + function (count) { buffer.scrollToPercentile(Math.max(count, 0)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["G", ""], @@ -325,22 +325,22 @@ function Buffer() //{{{ mappings.add(myModes, ["", "", ""], "Scroll up a full page", - function (count) { buffer.scrollPages(-(count > 1 ? count : 1)); }, + function (count) { buffer.scrollPages(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["", "", ""], "Scroll down a full page", - function (count) { buffer.scrollPages(count > 1 ? count : 1); }, + function (count) { buffer.scrollPages(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["]f"], "Focus next frame", - function (count) { buffer.shiftFrameFocus(count > 1 ? count : 1, true); }, + function (count) { buffer.shiftFrameFocus(Math.max(count, 1), true); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["[f"], "Focus previous frame", - function (count) { buffer.shiftFrameFocus(count > 1 ? count : 1, false); }, + function (count) { buffer.shiftFrameFocus(Math.max(count, 1), false); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["]]"], @@ -453,22 +453,22 @@ function Buffer() //{{{ // zooming mappings.add(myModes, ["zi", "+"], "Enlarge text zoom of current web page", - function (count) { buffer.zoomIn(count > 1 ? count : 1, false); }, + function (count) { buffer.zoomIn(Math.max(count, 1), false); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zm"], "Enlarge text zoom of current web page by a larger amount", - function (count) { buffer.zoomIn((count > 1 ? count : 1) * 3, false); }, + function (count) { buffer.zoomIn(Math.max(count, 1) * 3, false); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zo", "-"], "Reduce text zoom of current web page", - function (count) { buffer.zoomOut(count > 1 ? count : 1, false); }, + function (count) { buffer.zoomOut(Math.max(count, 1), false); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zr"], "Reduce text zoom of current web page by a larger amount", - function (count) { buffer.zoomOut((count > 1 ? count : 1) * 3, false); }, + function (count) { buffer.zoomOut(Math.max(count, 1) * 3, false); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zz"], @@ -478,22 +478,22 @@ function Buffer() //{{{ mappings.add(myModes, ["zI"], "Enlarge full zoom of current web page", - function (count) { buffer.zoomIn(count > 1 ? count : 1, true); }, + function (count) { buffer.zoomIn(Math.max(count, 1), true); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zM"], "Enlarge full zoom of current web page by a larger amount", - function (count) { buffer.zoomIn((count > 1 ? count : 1) * 3, true); }, + function (count) { buffer.zoomIn(Math.max(count, 1) * 3, true); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zO"], "Reduce full zoom of current web page", - function (count) { buffer.zoomOut(count > 1 ? count : 1, true); }, + function (count) { buffer.zoomOut(Math.max(count, 1), true); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zR"], "Reduce full zoom of current web page by a larger amount", - function (count) { buffer.zoomOut((count > 1 ? count : 1) * 3, true); }, + function (count) { buffer.zoomOut(Math.max(count, 1) * 3, true); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["zZ"], diff --git a/common/content/tabs.js b/common/content/tabs.js index a1158fd5..ec0f6471 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -334,7 +334,7 @@ function Tabs() //{{{ liberator.echoerr("E94: No matching tab for " + arg); } else // just remove the current tab - tabs.remove(tabs.getTab(), count > 0 ? count : 1, special, 0); + tabs.remove(tabs.getTab(), Math.max(count, 1), special, 0); }, { argCount: "?", diff --git a/muttator/content/mail.js b/muttator/content/mail.js index 576498b5..7f93316b 100644 --- a/muttator/content/mail.js +++ b/muttator/content/mail.js @@ -374,12 +374,12 @@ function Mail() //{{{ // SCROLLING mappings.add(myModes, [""], "Scroll message down", - function (count) { buffer.scrollLines(count > 1 ? count : 1); }, + function (count) { buffer.scrollLines(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, [""], "Scroll message up", - function (count) { buffer.scrollLines(-(count > 1 ? count : 1)); }, + function (count) { buffer.scrollLines(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add([modes.MESSAGE], [""], diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 1d362a20..cec44ff3 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -663,22 +663,22 @@ function History() //{{{ mappings.add(myModes, [""], "Go to an older position in the jump list", - function (count) { history.stepTo(-(count > 1 ? count : 1)); }, + function (count) { history.stepTo(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, [""], "Go to a newer position in the jump list", - function (count) { history.stepTo(count > 1 ? count : 1); }, + function (count) { history.stepTo(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["H", "", ""], "Go back in the browser history", - function (count) { history.stepTo(-(count > 1 ? count : 1)); }, + function (count) { history.stepTo(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["L", "", ""], "Go forward in the browser history", - function (count) { history.stepTo(count > 1 ? count : 1); }, + function (count) { history.stepTo(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); /////////////////////////////////////////////////////////////////////////////}}} diff --git a/vimperator/content/config.js b/vimperator/content/config.js index ea4f5df7..64165c86 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -226,12 +226,12 @@ const config = { //{{{ mappings.add([modes.NORMAL], [""], "Increment last number in URL", - function (count) { incrementURL(count > 1 ? count : 1); }, + function (count) { incrementURL(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add([modes.NORMAL], [""], "Decrement last number in URL", - function (count) { incrementURL(-(count > 1 ? count : 1)); }, + function (count) { incrementURL(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add([modes.NORMAL], ["~"], diff --git a/xulmus/content/bookmarks.js b/xulmus/content/bookmarks.js index c7beb02a..184457e6 100644 --- a/xulmus/content/bookmarks.js +++ b/xulmus/content/bookmarks.js @@ -732,22 +732,22 @@ function History() //{{{ mappings.add(myModes, [""], "Go to an older position in the jump list", - function (count) { history.stepTo(-(count > 1 ? count : 1)); }, + function (count) { history.stepTo(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, [""], "Go to a newer position in the jump list", - function (count) { history.stepTo(count > 1 ? count : 1); }, + function (count) { history.stepTo(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["H", "", ""], "Go back in the browser history", - function (count) { history.stepTo(-(count > 1 ? count : 1)); }, + function (count) { history.stepTo(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["L", "", ""], "Go forward in the browser history", - function (count) { history.stepTo(count > 1 ? count : 1); }, + function (count) { history.stepTo(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); /////////////////////////////////////////////////////////////////////////////}}} diff --git a/xulmus/content/config.js b/xulmus/content/config.js index 19e0c330..64a9b04c 100644 --- a/xulmus/content/config.js +++ b/xulmus/content/config.js @@ -325,12 +325,12 @@ const config = { //{{{ mappings.add([modes.NORMAL], [""], "Increment last number in URL", - function (count) { incrementURL(count > 1 ? count : 1); }, + function (count) { incrementURL(Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add([modes.NORMAL], [""], "Decrement last number in URL", - function (count) { incrementURL(-(count > 1 ? count : 1)); }, + function (count) { incrementURL(-Math.max(count, 1)); }, { flags: Mappings.flags.COUNT }); mappings.add([modes.NORMAL], ["~"],