diff --git a/chrome/content/vimperator/mappings.js b/chrome/content/vimperator/mappings.js index ae8d1904..68504cb9 100644 --- a/chrome/content/vimperator/mappings.js +++ b/chrome/content/vimperator/mappings.js @@ -26,6 +26,10 @@ function Map(mode, cmds, act, extra_info) //{{{ this.help = extra_info.help || null; this.short_help = extra_info.short_help || null; + // TODO: are these limited to HINTS mode? + // Only set for hints maps + this.cancel_mode = extra_info.cancel_mode || false; + this.always_active = extra_info.always_active || false; } } @@ -119,6 +123,11 @@ function Mappings() //{{{ return mappingsIterator(vimperator.modes.NORMAL); } + this.getIterator = function(mode) + { + return mappingsIterator(mode); + } + this.add = function(map) { if (!map) @@ -723,48 +732,52 @@ function Mappings() //{{{ "Also focuses the web page, in case a form field has focus and eats our key presses." } )); + + /* + * Hints mode + */ + + /* action keys */ + addDefaultMap(new Map(vimperator.modes.HINTS, ["o"], function() { vimperator.hints.openHints(false, false); }, { cancel_mode: true, always_active: false })); + addDefaultMap(new Map(vimperator.modes.HINTS, ["t"], function() { vimperator.hints.openHints(true, false); }, { cancel_mode: true, always_active: false })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.hints.openHints(false, true ); }, { cancel_mode: true, always_active: false })); + addDefaultMap(new Map(vimperator.modes.HINTS, ["s"], function() { vimperator.echoerr('Saving of links not yet implemented'); }, { cancel_mode: true, always_active: false })); + addDefaultMap(new Map(vimperator.modes.HINTS, ["y"], function() { vimperator.hints.yankUrlHints(); }, { cancel_mode: true, always_active: false })); + addDefaultMap(new Map(vimperator.modes.HINTS, ["Y"], function() { vimperator.hints.yankTextHints(); }, { cancel_mode: true, always_active: false })); + addDefaultMap(new Map(vimperator.modes.HINTS, [","], function() { vimperator.input.buffer += ','; vimperator.hints.setCurrentState(0); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [":"], function() { vimperator.commandline.open(':', '', vimperator.modes.EX); }, { cancel_mode: false, always_active: true })); + + /* movement keys */ + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferRelative(0, 1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferRelative(0, -1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferAbsolute(-1, 0); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferAbsolute(-1, 100); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { goDoCommand('cmd_scrollPageUp'); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { goDoCommand('cmd_scrollPageUp'); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { goDoCommand('cmd_scrollPageDown'); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { goDoCommand('cmd_scrollPageDown'); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferRelative(-1, 0); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferRelative(0, 1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferRelative(0, -1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { scrollBufferRelative(1, 0); }, { cancel_mode: false, always_active: true })); + + /* tab managment */ + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.tabs.select('+1', true); }, { cancel_mode: true, always_active: true })); // same as gt, but no count supported + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.tabs.select('-1', true); }, { cancel_mode: true, always_active: true })); + + /* navigation */ + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.history.stepTo(vimperator.input.count > 0 ? -1 * vimperator.input.count : -1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.history.stepTo(vimperator.input.count > 0 ? vimperator.input.count : 1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.history.stepTo(vimperator.input.count > 0 ? -1 * vimperator.input.count : -1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.history.stepTo(vimperator.input.count > 0 ? vimperator.input.count : 1); }, { cancel_mode: false, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() { vimperator.tabs.remove(getBrowser().mCurrentTab, vimperator.input.count, false, 0); }, { cancel_mode: true, always_active: true })); + + /* cancel_mode hint mode keys */ + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() {}, { cancel_mode: true, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() {}, { cancel_mode: true, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() {}, { cancel_mode: true, always_active: true })); + addDefaultMap(new Map(vimperator.modes.HINTS, [""], function() {}, { cancel_mode: true, always_active: true })); //}}} } //}}} -// TODO: Convert these to the new mappings model -/* [command, action, cancel_hint_mode, always_active] */ -var g_hint_mappings = [ //{{{ - /* hint action keys */ - ["o", "vimperator.hints.openHints(false, false);", true, false], - ["t", "vimperator.hints.openHints(true, false);", true, false], - ["", "vimperator.hints.openHints(false, true );", true, false], - ["s", "vimperator.echoerr('Saving of links not yet implemented');", true, false], - ["y", "vimperator.hints.yankUrlHints();", true, false], - ["Y", "vimperator.hints.yankTextHints();", true, false], - [",", "vimperator.input.buffer+=','; vimperator.hints.setCurrentState(0);", false, true], - [":", "vimperator.commandline.open(':', '', vimperator.modes.EX);", false, true], - /* movement keys */ - ["", "scrollBufferRelative(0, 1);", false, true], - ["", "scrollBufferRelative(0, -1);", false, true], - ["", "scrollBufferAbsolute(-1, 0);", false, true], - ["", "scrollBufferAbsolute(-1, 100);", false, true], - ["", "goDoCommand('cmd_scrollPageUp');", false, true], - ["", "goDoCommand('cmd_scrollPageUp');", false, true], - ["", "goDoCommand('cmd_scrollPageDown');", false, true], - ["", "goDoCommand('cmd_scrollPageDown');", false, true], - ["", "scrollBufferRelative(-1, 0);", false, true], - ["", "scrollBufferRelative(0, 1);", false, true], - ["", "scrollBufferRelative(0, -1);", false, true], - ["", "scrollBufferRelative(1, 0);", false, true], - /* tab managment */ - ["", "vimperator.tabs.select('+1', true)", true, true], // same as gt, but no count supported - ["", "vimperator.tabs.select('-1', true)", true, true], - /* navigation */ - ["", "vimperator.history.stepTo(vimperator.input.count > 0 ? -1 * vimperator.input.count : -1);", false, true], - ["", "vimperator.history.stepTo(vimperator.input.count > 0 ? vimperator.input.count : 1);", false, true], - ["", "vimperator.history.stepTo(vimperator.input.count > 0 ? -1 * vimperator.input.count : -1);", false, true], - ["", "vimperator.history.stepTo(vimperator.input.count > 0 ? vimperator.input.count : 1);", false, true], - ["", "vimperator.tabs.remove(getBrowser().mCurrentTab, vimperator.input.count, false, 0);", true, true], - /* cancel hint mode keys */ - ["", "", true, true], - ["", "", true, true], - ["", "", 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 dbbbc89b..dffa8924 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -524,7 +524,6 @@ function Events() //{{{ // if Hit-a-hint mode is on, special handling of keys is required - // g_hint_mappings is used // FIXME: total mess if (vimperator.hasMode(vimperator.modes.HINTS)) { @@ -532,28 +531,26 @@ function Events() //{{{ event.preventDefault(); event.stopPropagation(); - for (i = 0; i < g_hint_mappings.length; i++) + var map = vimperator.mappings.get(vimperator.modes.HINTS, key); + if (map) { - if(g_hint_mappings[i][0] == key) + if(map.always_active || vimperator.hints.currentState() == 1) { - if(g_hint_mappings[i][3] == true || vimperator.hints.currentState() == 1) + //g_hint_mappings[i][1].call(this, event); + map.execute(); + if (map.cancel_mode) // stop processing this event { - //g_hint_mappings[i][1].call(this, event); - eval(g_hint_mappings[i][1]); - if (g_hint_mappings[i][2] == true) // stop processing this event - { - vimperator.hints.disableHahMode(); - vimperator.input.buffer = ""; - vimperator.statusline.updateInputBuffer(""); - return false; - } - else - { - // FIXME: make sure that YOU update the statusbar message yourself - // first in g_hint_mappings when in this mode! - vimperator.statusline.updateInputBuffer(vimperator.input.buffer); - return false; - } + vimperator.hints.disableHahMode(); + vimperator.input.buffer = ""; + vimperator.statusline.updateInputBuffer(""); + return false; + } + else + { + // FIXME: make sure that YOU update the statusbar message yourself + // first in g_hint_mappings when in this mode! + vimperator.statusline.updateInputBuffer(vimperator.input.buffer); + return false; } } }