diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index e59df444..28b56928 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -511,538 +511,6 @@ var g_commands = [/*{{{*/ ] ];/*}}}*/ -/* all built-in normal mode commands of Vimperator - * format: - * [ - * 0: [all shortcuts of this command], - * 1: usage, - * 2: shorthelp - * 3: helptext - * 4: function (arguments in this order: args, special, count) - * ] - */ -var g_mappings = [/*{{{*/ - [ - ["]f"], - ["]f"], - "Focus next frame", - "Flashes the next frame in order with a red color, to quickly show where keyboard focus is.
"+ - "This may not work correctly for frames with lots of CSS code.", - focusNextFrame - ], - [ - ["b"], - ["b {number}"], - "Open a prompt to switch buffers", - "Typing the corresponding number opens switches to this buffer.", - function (args) { vimperator.commandline.open(":", "buffer ", vimperator.modes.EX); } - ], - [ - ["B"], - ["B"], - "Toggle buffer list", - "Toggles the display of the buffer list which shows all opened tabs.", - toggleBufferList - ], - [ - ["d"], - ["{count}d"], - "Delete current buffer (=tab)", - "Count WILL be supported in future releases, then 2d removes two tabs and the one the right is selected.", - function(count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, false, 0); } - ], - [ - ["D"], - ["{count}D"], - "Delete current buffer (=tab)", - "Count WILL be supported in future releases, then 2D removes two tabs and the one the left is selected.", - function(count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, true, 0); } - ], - /*[ - ["ge"], - ["ge {cmd}"], - "Execute an Ex command", - "Go Execute works like :execute.
"+ - "This mapping is for debugging purposes, and may be removed in future.", - function(count) { openVimperatorBar('execute '); } - ],*/ - [ - ["gh"], - ["gh"], - "Go home", - "Opens the homepage in the current tab.", - BrowserHome - ], - [ - ["gH"], - ["gH"], - "Go home in a new tab", - "Opens the homepage in a new tab.", - function(count) { openURLsInNewTab("", true); BrowserHome(); } - ], - [ - ["gP"], - ["gP"], - "Open (put) an URL based on the current clipboard contents in a new buffer", - "Works like P, but inverts the 'activate' setting.", - function(count) { openURLsInNewTab(readFromClipboard(), false); } - ], - [ - ["gt", "", ""], - ["{count}gt"], - "Go to next tab", - "Cycles to the first tab, when the last is selected.
"+ - "Count is supported, 3gt goes to the third tab.", - function(count) { vimperator.tabs.select(count > 0 ? count -1: "+1", count > 0 ? false : true); } - ], - [ - ["gT", "", ""], - ["{count}gT"], - "Go to previous tab", - "Cycles to the last tab, when the first is selected.
"+ - "Count is supported, 3gt goes to the third tab.", - function(count) { vimperator.tabs.select(count > 0 ? count -1: "-1", count > 0 ? false : true); } - ], - [ - ["o"], - ["o"], - "Open one or more URLs in the current tab", - "See :open for more details.", - function(count) { vimperator.commandline.open(":", "open ", vimperator.modes.EX); } - ], - [ - ["O"], - ["O"], - "Open one ore more URLs in the current tab, based on current location", - "Works like o, but preselects current URL in the :open query.", - function(count) { vimperator.commandline.open(":", "open " + getCurrentLocation(), vimperator.modes.EX); } - ], - [ - ["p", ""], - ["p", ""], - "Open (put) an URL based on the current clipboard contents in the current buffer", - "You can also just select some non-URL text, and search for it with the default search engine or keyword (specified by the 'defsearch' setting) with p.", - function(count) { openURLs(readFromClipboard()); } - ], - [ - ["P"], - ["P"], - "Open (put) an URL based on the current clipboard contents in a new buffer", - "Works like p, but opens a new tab.
"+ - "Whether the new buffer is activated, depends on the 'activate' setting.", - function(count) { openURLsInNewTab(readFromClipboard(), true); } - ], - [ - ["r"], - ["r"], - "Reload", - "Forces reloading of the current page.", - function(count) { reload(getBrowser().mCurrentTab, false); } - ], - [ - ["R"], - ["R"], - "Reload skipping the cache", - "Forces reloading of the current page skipping the cache.", - function(count) { reload(getBrowser().mCurrentTab, true); } - ], - [ - ["t"], - ["t"], - "Open one or more URLs in a new tab", - "Like o but open URLs in a new tab.
"+ - "See :tabopen for more details.", - function(count) { vimperator.commandline.open(":", "tabopen ", vimperator.modes.EX); } - ], - [ - ["T"], - ["T"], - "Open one ore more URLs in a new tab, based on current location", - "Works like t, but preselects current URL in the :tabopen query.", - function(count) { vimperator.commandline.open(":", "tabopen " + getCurrentLocation(), vimperator.modes.EX); } - ], - [ - ["u"], - ["{count}u"], - "Undo closing of a tab", - "If a count is given, don't close the last but the n'th last tab.", - function(count) { execute_command(count, 'undo', false, ''); } - ], - [ - ["y"], - ["y"], - "Yank current location to the clipboard", - "Under UNIX the location is also put into the selection, which can be pasted with the middle mouse button.", - yankCurrentLocation - ], - [ - ["Y"], - ["Y"], - "Copy selected text", - "The currently selected text is copied to the system clipboard.", - yankCurrentSelection, - null - ], - [ - ["zi", "+"], - ["zi", "+"], - "Zoom in current web page by 25%", - "Currently no count supported.", - function(count) { zoom_in(1); } - ], - [ - ["zI"], - ["zI"], - "Zoom in current web page by 100%", - "Currently no count supported.", - function(count) { zoom_in(4); } - ], - [ - ["zo", "-"], - ["zo", "-"], - "Zoom out current web page by 25%", - "Currently no count supported.", - function(count) { zoom_in(-1); } - ], - [ - ["zO"], - ["zO"], - "Zoom out current web page by 100%", - "Currently no count supported.", - function(count) { zoom_in(-4); } - ], - [ - ["zz"], - ["{count}zz"], - "Set zoom value of the webpage", - "Zoom value can be between 25 and 500%. If it is omitted, zoom is reset to 100%.", - zoom_to - ], - [ - ["ZQ"], - ["ZQ"], - "Quit and don't save the session", - "Works like :qall.", - function(count) { quit(false); } - ], - [ - ["ZZ"], - ["ZZ"], - "Quit and save the session", - "Quit Vimperator, no matter how many tabs/windows are open. The session is stored.
" + - "Works like :xall.", - function(count) { quit(true); } - ], - - /* scrolling commands */ - [ - ["0", "^"], - ["0", "^"], - "Scroll to the absolute left of the document", - "Unlike in vim, 0 and ^ work exactly the same way.", - function(count) { scrollBufferAbsolute(0, -1); } - ], - [ - ["$"], - ["$"], - "Scroll to the absolute right of the document", - null, - function(count) { scrollBufferAbsolute(100, -1); } - ], - [ - ["gg", ""], - ["{count}gg", "{count}"], - "Goto the top of the document", - "Count is supported, 35gg vertically goes to 35% of the document.", - function(count) { scrollBufferAbsolute(-1, count > 0 ? count : 0); } - ], - [ - ["G", ""], - ["{count}G", "{count}"], - "Goto the end of the document", - "Count is supported, 35G vertically goes to 35% of the document.", - function(count) { scrollBufferAbsolute(-1, count >= 0 ? count : 100); } - ], - [ - ["h", ""], - ["{count}h", "{count}"], - "Scroll document to the left", - "Count is supported: 10h will move 10 times as much to the left.
"+ - "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - function(count) { scrollBufferRelative(-1, 0); } - ], - [ - ["j", "", ""], - ["{count}j", "{count}", "{count}"], - "Scroll document down", - "Count is supported: 10j will move 10 times as much down.
"+ - "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - function(count) { scrollBufferRelative(0, 1); } - ], - [ - ["k", "", ""], - ["{count}k", "{count}", "{count}"], - "Scroll document up", - "Count is supported: 10k will move 10 times as much up.
"+ - "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - function(count) { scrollBufferRelative(0, -1); } - ], - [ - ["l", ""], - ["{count}l", "{count}"], - "Scroll document to the right", - "Count is supported: 10l will move 10 times as much to the right.
"+ - "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - function(count) { scrollBufferRelative(1, 0); } - ], - [ - ["", "", "", ""], - [""], - "Scroll up a full page of the current document", - "No count support for now.", - function(count) { goDoCommand('cmd_scrollPageUp'); } - ], - [ - ["", "", "", ""], - [""], - "Scroll down a full page of the current document", - "No count support for now,", - function(count) { goDoCommand('cmd_scrollPageDown'); } - ], - - /* history manipulation and jumplist */ - [ - [""], - ["{count}"], - "Go to an older position in the jump list", - "The jump list is just the browser history for now", - function(count) { stepInHistory(count > 0 ? -1 * count : -1); } - ], - [ - [""], - ["{count}"], - "Go to a newer position in the jump list", - "The jump list is just the browser history for now", - function(count) { stepInHistory(count > 0 ? count : 1); } - ], - [ - ["H", "", ""], - ["{count}H", "{count}", "{count}"], - "Go back in the browser history", - "Count is supported, 3H goes back 3 steps.", - function(count) { stepInHistory(count > 0 ? -1 * count : -1); } - ], - [ - ["L", "", ""], - ["{count}L", "{count}", "{count}"], - "Go forward in the browser history", - "Count is supported, 3L goes forward 3 steps.", - function(count) { stepInHistory(count > 0 ? count : 1); } - ], - [ - ["gu", ""], - ["{count}gu", "{count}"], - "Go to parent directory", - "Count is supported, 2gu on http://www.example.com/dir1/dir2/file.htm would open http://www.example.com/dir1/.", - goUp - ], - [ - ["gU", ""], - ["gU", ""], - "Go to the root of the website", - "gU on http://www.example.com/dir1/dir2/file.htm opens http://www.example.com/.
"+ - "When browsing a local directory, it goes to the root document.", - function(count) { openURLs("..."); } - ], - - /* hint managment */ - [ - ["f"], - ["f"], - "Start QuickHint mode", - "In QuickHint mode, every hintable item (according to the 'hinttags' XPath query) is assigned a label.
"+ - "If you then press the keys for a label, it is followed as soon as it can be uniquely identified and this mode is stopped. Or press <Esc> to stop this mode.
"+ - "If you write the hint in ALLCAPS, the hint is followed in a background tab.", - function(count) { hah.enableHahMode(vimperator.modes.QUICK_HINT); } - ], - [ - ["F"], - ["F"], - "Start AlwaysHint mode", - "In AlwaysHint mode, every hintable item (according to the 'hinttags' XPath query) is assigned a label.
"+ - "If you then press the keys for a label, it is followed as soon as it can be uniquely identified. Labels stay active after following a hint in this mode, press <Esc> to stop this mode.
"+ - "This hint mode is especially useful for browsing large sites like Forums as hints are automatically regenerated when switching to a new document.
"+ - "Also, most Ctrl-prefixed shortcut keys are available in this mode for navigation.", - function(count) { hah.enableHahMode(vimperator.modes.ALWAYS_HINT); } - ], - [ - [";"], - [";"], - "Start ExtendedHint mode", - "ExtendedHint mode is useful, since in this mode you can yank link locations, or open them in a new window.
"+ - "E.g., if you want to yank the location of hint AB, press ; to start this hint mode.
"+ - "Then press AB to select the hint. Now press y to yank its location.
"+ - "Actions for selected hints in ExtendedHint mode are:
"+ - "
  • y to yank its location
  • "+ - "
  • Y to yank its text description
  • "+ - "
  • o to open its location in the current tab
  • "+ - "
  • t to open its location in a new tab
  • "+ - "
  • O to open its location in an :open query (not implemented yet)
  • "+ - "
  • T to open its location in an :tabopen query (not implemented yet)
  • "+ - "
  • s to save its destination (not implemented yet)
  • "+ - "
  • <C-w> to open its destination in a new window
  • "+ - "
"+ - "Multiple hints can be seperated by commas where it makes sense. ;ab,ac,adt opens AB, AC and AD in a new tab.
"+ - "Hintable elements for this mode can be set in the 'extendedhinttags' XPath string.", - function(count) { hah.enableHahMode(vimperator.modes.EXTENDED_HINT); } - ], - - /* search managment */ - [ - ["g/"], - ["g/"], - "Open search dialog", - "", - function(count) { vimperator.search.openSearchDialog(); } - ], - [ - ["n"], - ["n"], - "Find next", - "Repeat the last \"/\" 1 time (until count is supported).", - function(count) { vimperator.search.findNext(); } - ], - [ - ["N"], - ["N"], - "Find previous", - "Repeat the last \"/\" 1 time (until count is supported) in the opposite direction.", - function(count) { vimperator.search.findPrevious(); } - ], - - /* vimperator managment */ - [ - [""], - [""], - "Open help window", - "The default section is shown, if you need help for a specific topic, try :help <F1> (jumping to a specific section not implemented yet).", - function(count) { help(null); } - ], - [ - [":"], - [":"], - "Start command line mode", - "In command line mode, you can perform extended commands, which may require arguments.", - function(count) { vimperator.commandline.open(":", "", vimperator.modes.EX); } - ], - [ - ["I"], - ["I"], - "Disable vimperator keys", - "Starts an 'ignorekeys' mode, where all keys except <Esc> are passed to the next event handler.
"+ - "This is especially useful, if JavaScript controlled forms like the RichEdit form fields of GMail don't work anymore.
" + - "To exit this mode, press <Esc>. If you also need to pass <Esc>"+ - "in this mode to the webpage, prepend it with <C-v>.", - function(count) { vimperator.addMode(null, vimperator.modes.ESCAPE_ALL_KEYS);} - ], - [ - [""], // if you ever add/remove keys here, also check them in the onVimperatorKeypress() function - [""], - "Escape next key", - "If you need to pass a certain key to a javascript form field or another extension prefix the key with <C-v>.
"+ - "Also works to unshadow Firefox shortcuts like <C-o> which are otherwise hidden in Vimperator.
"+ - "When in 'ignorekeys' mode (activated by <I>), <C-v> will pass the next key to Vimperator instead of the webpage.", - function(count) { vimperator.addMode(null, vimperator.modes.ESCAPE_ONE_KEY); } - ], - [ - [""], - [""], - "Stop loading", - "Stops loading the current webpage.", - BrowserStop, - ], - [ - ["", ""], // if you ever add/remove keys here, also check them in the onVimperatorKeypress() function - ["", ""], - "Cancel any operation", - "Exits any command line or hint mode and returns to browser mode.
"+ - "Also focuses the web page, in case a form field has focus and eats our key presses.", - onEscape - ], - - /* quick bookmark access - will be customizable in future*/ - [ - ["'b"], - ["'b"], - "These quick bookmarks will be customizable in future releases, ignore for now", - null, - function(count) { openURLs('www.bwin.com'); } - ], - [ - ["'o"], - ["'o"], - "These quick bookmarks will be customizable in future releases, ignore for now", - null, - function(count) { openURLs('www.osnews.com'); } - ], - [ - ["'s"], - ["'s"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLs('www.derstandard.at'); } - ], - [ - ["'w"], - ["'w"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLs('wetter.orf.at'); } - ], - [ - ["'t"], - ["'t"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLs('www.tvinfo.de'); } - ], - [ - ["\"b"], - ["\"b"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLsInNewTab('www.bwin.com'); } - ], - [ - ["\"o"], - ["\"o"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLsInNewTab('www.osnews.com'); } - ], - [ - ["\"s"], - ["\"s"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLsInNewTab('www.derstandard.at'); } - ], - [ - ["\"w"], - ["\"w"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLsInNewTab('wetter.orf.at'); } - ], - [ - ["\"t"], - ["\"t"], - "These quick bookmarks will be customizable in future releases, ignore for now
", - null, - function(count) { openURLsInNewTab('www.tvinfo.de'); } - ] -];/*}}}*/ - // var g_insert_mappings = [ /*{{{*/ // ["xxx", "todo"], // ["", "delete word"], diff --git a/chrome/content/vimperator/completion.js b/chrome/content/vimperator/completion.js index d4aa1ef9..bbc23617 100644 --- a/chrome/content/vimperator/completion.js +++ b/chrome/content/vimperator/completion.js @@ -270,9 +270,8 @@ function get_help_completions(filter)/*{{{*/ $_[1] ]; })); - help_array = help_array.concat(g_mappings.map(function($_) { - return [ $_[COMMANDS], $_[SHORTHELP] ]; - })); + for (map in vimperator.mappings) + help_array.push([map.commands, map.short_help]) if (!filter) return help_array.map(function($_) { return [$_[COMMANDS][0], $_[1]]; // unfiltered, use the first command diff --git a/chrome/content/vimperator/help.js b/chrome/content/vimperator/help.js index f585a4d7..3fecdf30 100644 --- a/chrome/content/vimperator/help.js +++ b/chrome/content/vimperator/help.js @@ -166,7 +166,12 @@ function help(section, easter) var mappings = '

Mappings

\n'+ '

The denotion of modifier keys is like in Vim, so C- means the Control key, M- the Meta key, A- the Alt key and S- the Shift key.

'+ '

' - mappings += makeHelpString(g_mappings, "#102663", "", "", null); + // FIXME: fix this when Command() is added and help patch is merged -- djk + var all_maps = []; + for (map in vimperator.mappings) + all_maps.push([map.commands, [map.usage], map.short_help, map.help]) + mappings += makeHelpString(all_maps, "#102663", "", "", null); + //mappings += makeHelpString(g_mappings, "#102663", "", "", null); mappings += '

'; if (section && section == 'holy-grail') mappings += 'You found it, Arthur!\n'; diff --git a/chrome/content/vimperator/mappings.js b/chrome/content/vimperator/mappings.js index b3eb287d..015f3c98 100644 --- a/chrome/content/vimperator/mappings.js +++ b/chrome/content/vimperator/mappings.js @@ -1,5 +1,5 @@ // TODO: document -function Map(mode, cmds, act, extra_info) +function Map(mode, cmds, act, extra_info) //{{{ { if (!mode || (!cmds || !cmds.length) || !act) return null; @@ -18,10 +18,10 @@ function Map(mode, cmds, act, extra_info) else { this.usage = ""; - if (flags & vimperator.mappings.flags.COUNT) + if (flags & Mappings.flags.COUNT) this.usage = "{count}"; - this.usage += this.commands[0]; - if (flags & vimperator.mappings.flags.ARGUMENT) + this.usage += this.commands[0]; //XXX: or sth. like .join("<br/>"); + if (flags & Mappings.flags.ARGUMENT) this.usage += " {arg}"; } @@ -54,13 +54,13 @@ function Map(mode, cmds, act, extra_info) "\nhelp: " + this.help + "\n}" } -} +} //}}} -function Mappings() +function Mappings()//{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////{{{ var main = []; // array of default Map() objects var user = []; // array of objects created by :map @@ -91,16 +91,40 @@ function Mappings() } } - //////////////////////////////////////////////////////////////////////////////// - ////////////////////// PUBLIC SECTION ////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// + var mappingsIterator = function(mode) + { + var mappings; - this.flags = { + // FIXME: initialize empty map tables -- djk + if (user[mode]) + mappings = user[mode].concat(main[mode]) + else + mappings = main[mode] + + for (var i = 0; i < mappings.length; i++) + yield mappings[i]; + + throw StopIteration; + } + + /////////////////////////////////////////////////////////////////////////////}}} + ////////////////////// PUBLIC SECTION ////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////{{{ + + // TODO: change to Mappings.MOTION etc? -- djk + Mappings.flags = { MOTION: 1 << 0, COUNT: 1 << 1, ARGUMENT: 1 << 2 }; + // NOTE: just the main/default map for now -- djk + this.__iterator__ = function() + { + return mappingsIterator(vimperator.modes.NORMAL); + } + + // TODO: remove duplication in addDefaultMap -- djk this.add = function(map) { if (!map) @@ -137,28 +161,33 @@ function Mappings() } // same as this.get() but always returns an array of commands which start with "cmd" - this.getAll = function(mode, cmd) + this.getCandidates = function(mode, cmd) { var matching = []; if (!mode || !cmd) return matching; - // TODO: fill matching array with commands which start with cmd - /*var map = getFrom(mode, cmd, user); - if (!map) - map = getFrom(mode, cmd, main); - */ + // fill matching array with maps which have commands starting with cmd + for (var i = 0; i < main[mode].length; i++) // FIXME: just the main/default map space for now -- djk + { + var map = main[mode][i]; + for (var j = 0; j < map.commands.length; j++) + { + if (map.commands[j].indexOf(cmd) == 0) + matching.push(map) + } + } return matching; } - //////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// DEFAULT MAPPINGS //////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// - /* Default mappings + /////////////////////////////////////////////////////////////////////////////{{{ + /* * Normal mode - * */ + */ addDefaultMap(new Map(vimperator.modes.NORMAL, ["]f"], focusNextFrame, { short_help: "Focus next frame", @@ -182,14 +211,14 @@ function Mappings() { short_help: "Delete current buffer (=tab)", help: "Count WILL be supported in future releases, then 2d removes two tabs and the one the right is selected.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["D"], function(count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, true, 0); }, { short_help: "Delete current buffer (=tab)", help: "Count WILL be supported in future releases, then 2d removes two tabs and the one the right is selected.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["gh"], BrowserHome, @@ -214,21 +243,22 @@ function Mappings() { short_help: "Go to the next tab", help: "Cycles to the first tab, when the last is selected.
Count is supported, 3gt goes to the third tab.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["gT", "", ""], function(count) { vimperator.tabs.select(count > 0 ? count -1: "-1", count > 0 ? false : true); }, { short_help: "Go to the previous tab", help: "Cycles to the last tab, when the first is selected.
Count is supported, 3gT goes to the third tab.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["m"], set_location_mark, { - short_help: "Set mark at the cursor position", usage: "m{a-zA-Z}", + short_help: "Set mark at the cursor position", + usage: "m{a-zA-Z}", help: "Marks a-z are local to the buffer, whereas A-Z are valid between buffers.", - flags: this.flags.ARGUMENT + flags: Mappings.flags.ARGUMENT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["o"], function(count) { vimperator.commandline.open(":", "open ", vimperator.modes.EX); }, @@ -285,7 +315,7 @@ function Mappings() { short_help: "Undo closing of a tab", help: "If a count is given, don't close the last but the n'th last tab.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["y"], yankCurrentLocation, @@ -328,7 +358,7 @@ function Mappings() { short_help: "Set zoom value of the webpage", help: "Zoom value can be between 25 and 500%. If it is omitted, zoom is reset to 100%.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["ZQ"], function(count) { quit(false); }, @@ -362,14 +392,14 @@ function Mappings() { short_help: "Goto the top of the document", help: "Count is supported, 35gg vertically goes to 35% of the document.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["G", ""], function(count) { scrollBufferAbsolute(-1, count >= 0 ? count : 100); }, { short_help: "Goto the end of the document", help: "Count is supported, 35G vertically goes to 35% of the document.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["h", ""], function(count) { scrollBufferRelative(-1, 0); }, @@ -377,7 +407,7 @@ function Mappings() short_help: "Scroll document to the left", help: "Count is supported: 10h will move 10 times as much to the left.
" + "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["j", "", ""], function(count) { scrollBufferRelative(0, 1); }, @@ -385,7 +415,7 @@ function Mappings() short_help: "Scroll document down", help: "Count is supported: 10j will move 10 times as much down.
" + "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["k", "", ""], function(count) { scrollBufferRelative(0, -1); }, @@ -393,7 +423,7 @@ function Mappings() short_help: "Scroll document up", help: "Count is supported: 10k will move 10 times as much up.
" + "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["l", ""], function(count) { scrollBufferRelative(1, 0); }, @@ -401,7 +431,7 @@ function Mappings() short_help: "Scroll document to the right", help: "Count is supported: 10l will move 10 times as much to the right.
" + "If the document cannot scroll more, a beep is emmited (unless 'beep' is turned off).", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["", "", "", ""], function(count) { goDoCommand('cmd_scrollPageUp'); }, @@ -422,35 +452,35 @@ function Mappings() { short_help: "Go to an older position in the jump list", help: "The jump list is just the browser history for now.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, [""], function(count) { stepInHistory(count > 0 ? count : 1); }, { short_help: "Go to a newer position in the jump list", help: "The jump list is just the browser history for now.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["H", "", ""], function(count) { stepInHistory(count > 0 ? -1 * count : -1); }, { short_help: "Go back in the browser history", help: "Count is supported, 3H goes back 3 steps.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["L", "", ""], function(count) { stepInHistory(count > 0 ? count : 1); }, { short_help: "Go forward in the browser history", help: "Count is supported, 3L goes forward 3 steps.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["gu", ""], goUp, { short_help: "Go to parent directory", help: "Count is supported, 2gu on http://www.example.com/dir1/dir2/file.htm would open http://www.example.com/dir1/.", - flags: this.flags.COUNT + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["gU", ""], function(count) { openURLs("..."); }, @@ -565,7 +595,7 @@ function Mappings() "Also focuses the web page, in case a form field has focus and eats our key presses." } )); - +//}}} var hint_maps = [ /* hint action keys */ ["o", "hah.openHints(false, false);", true, false], @@ -604,6 +634,6 @@ function Mappings() ["", "", true, true], ["", "", true, true] ]; -} +}//}}} // vim: set fdm=marker sw=4 ts=4 et: diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js index 7d0049f0..861f5cca 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -180,6 +180,8 @@ function init() Vimperator.prototype.bufferwindow = new InformationList("vimperator-bufferwindow", { incremental_fill: false, max_items: 10 }); Vimperator.prototype.statusline = new StatusLine(); Vimperator.prototype.tabs = new Tabs(); + Vimperator.prototype.mappings = new Mappings(); + // XXX: move elsewhere vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } ); @@ -899,8 +901,6 @@ function Vimperator() return true; } - // set this variable to true, if we have the start of a mapping - var couldBecomeCompleteMapping = false; var count_str = g_inputbuffer.match(/^[0-9]*/)[0]; // counts must be at the start of a complete mapping (10j -> go 10 lines down) @@ -926,40 +926,25 @@ function Vimperator() } } - for (var i in g_mappings) + var candidate_command = (g_inputbuffer + key).replace(count_str, ''); + + if (map = vimperator.mappings.get(vimperator.modes.NORMAL, candidate_command)) { - // each internal mapping can have multiple keys - for (var j in g_mappings[i][COMMANDS]) - { - var mapping = g_mappings[i][COMMANDS][j]; - // alert("key: " + key +" - mapping: "+ mapping + " - g_input: " + g_inputbuffer); - if(count_str + mapping == g_inputbuffer + key) - //if (count_str + mapping == vimperator.commandline.getCommand() + key) - { - g_count = parseInt(count_str, 10); - if (isNaN(g_count)) - g_count = -1; + g_count = parseInt(count_str, 10); + if (isNaN(g_count)) + g_count = -1; - // allow null (= no operation) mappings - if(g_mappings[i][FUNCTION] != null) - g_mappings[i][FUNCTION].call(this, g_count); + // FIXME: allow null (= no operation) mappings. No longer applicable? -- djk + map.execute(); - // command executed, reset input buffer - g_inputbuffer = ""; - vimperator.statusline.updateInputBuffer(g_inputbuffer); - event.preventDefault(); - event.stopPropagation(); - return false; - } - else if ((count_str+mapping).indexOf(g_inputbuffer + key) == 0) - //else if ((count_str+mapping).indexOf(vimperator.commandline.getCommand() + key) == 0) - { - couldBecomeCompleteMapping = true; - } - } + // command executed, reset input buffer + g_inputbuffer = ""; + vimperator.statusline.updateInputBuffer(g_inputbuffer); + event.preventDefault(); + event.stopPropagation(); + return false; } - - if (couldBecomeCompleteMapping) + else if (vimperator.mappings.getCandidates(vimperator.modes.NORMAL, candidate_command).length > 0) { g_inputbuffer += key; event.preventDefault(); diff --git a/chrome/content/vimperator/vimperator.xul b/chrome/content/vimperator/vimperator.xul index 95223560..6374621f 100644 --- a/chrome/content/vimperator/vimperator.xul +++ b/chrome/content/vimperator/vimperator.xul @@ -48,6 +48,7 @@ the terms of any one of the MPL, the GPL or the LGPL.