diff --git a/content/mappings.js b/content/mappings.js index 559a1e5c..4423f3ba 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -198,6 +198,7 @@ vimperator.Mappings = function () //{{{ return user[mode].some(function (map) { return map.hasName(cmd); }); }, + // TODO: rename to add, and change add to addUser(Map) addDefault: function (modes, keys, description, action, extra) { addMap (new vimperator.Map(modes, keys, @@ -349,37 +350,21 @@ vimperator.Mappings = function () //{{{ ////////////////////// DEFAULT MAPPINGS //////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var allModes = [vimperator.modes.NONE, - vimperator.modes.NORMAL, - vimperator.modes.INSERT, - vimperator.modes.VISUAL, - vimperator.modes.HINTS, - vimperator.modes.COMMAND_LINE, - vimperator.modes.MESSAGE, - vimperator.modes.CARET, - vimperator.modes.TEXTAREA]; - - var noninsertModes = [vimperator.modes.NORMAL, - vimperator.modes.VISUAL, - vimperator.modes.HINTS, - vimperator.modes.MESSAGE, - vimperator.modes.CARET, - vimperator.modes.TEXTAREA]; - // // NORMAL mode // {{{ // vimperator management - addDefaultMap(new vimperator.Map(allModes, [""], + addDefaultMap(new vimperator.Map(vimperator.modes.all, [""], function () { vimperator.commands.help(); }, { shortHelp: "Open help window" } )); - addDefaultMap(new vimperator.Map(allModes, ["", ""], + addDefaultMap(new vimperator.Map(vimperator.modes.all, ["", ""], function () { vimperator.events.onEscape() }, { shortHelp: "Focus content" } )); - addDefaultMap(new vimperator.Map(noninsertModes, [":"], + // add the ":" mapping in all but insert mode mappings + addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL, vimperator.modes.VISUAL, vimperator.modes.HINTS, vimperator.modes.MESSAGE, vimperator.modes.CARET, vimperator.modes.TEXTAREA], [":"], function () { vimperator.commandline.open(":", "", vimperator.modes.EX); }, { shortHelp: "Start command line mode" } )); @@ -402,11 +387,11 @@ vimperator.Mappings = function () //{{{ }, { shortHelp: "Start caret mode" } )); - addDefaultMap(new vimperator.Map(allModes, [""], + addDefaultMap(new vimperator.Map(vimperator.modes.all, [""], function () { vimperator.modes.passAllKeys = true; }, { shortHelp: "Temporarily quit Vimperator mode" } )); - addDefaultMap(new vimperator.Map(allModes, [""], + addDefaultMap(new vimperator.Map(vimperator.modes.all, [""], function () { vimperator.modes.passNextKey = true; }, { shortHelp: "Pass through next key" } )); @@ -414,7 +399,7 @@ vimperator.Mappings = function () //{{{ function() { BrowserStop(); }, { shortHelp: "Stop loading" } )); - addDefaultMap(new vimperator.Map(allModes, [""], + addDefaultMap(new vimperator.Map(vimperator.modes.all, [""], function () { return; }, { shortHelp: "Do nothing" } )); diff --git a/content/modes.js b/content/modes.js index 81afc984..80a02c01 100644 --- a/content/modes.js +++ b/content/modes.js @@ -179,8 +179,7 @@ vimperator.modes = (function () //{{{ __iterator__: function () { - var modes = [this.NONE, this.NORMAL, this.INSERT, this.VISUAL, this.HINTS, - this.COMMAND_LINE, this.CARET, this.TEXTAREA, this.MESSAGE, this.CUSTOM]; + var modes = this.all; for (var i = 0; i < modes.length; i++) yield modes[i]; @@ -188,12 +187,11 @@ vimperator.modes = (function () //{{{ throw StopIteration; }, - // keeps recording state - reset: function (silent) - { - this.set(vimperator.modes.NORMAL, vimperator.modes.NONE, silent); - }, + get all() { return [this.NONE, this.NORMAL, this.INSERT, this.VISUAL, + this.HINTS, this.COMMAND_LINE, this.CARET, + this.TEXTAREA, this.MESSAGE, this.CUSTOM]; }, + // show the current mode string in the command line show: function () { if (!vimperator.options["showmode"]) @@ -207,12 +205,11 @@ vimperator.modes = (function () //{{{ vimperator.commandline.DISALLOW_MULTILINE); }, - setCustomMode: function (modestr, oneventfunc, stopfunc) + // add/remove always work on the extended mode only + add: function (mode) { - // TODO this.plugin[id]... ('id' maybe submode or what..) - vimperator.plugins.mode = modestr; - vimperator.plugins.onEvent = oneventfunc; - vimperator.plugins.stop = stopfunc; + extended |= mode; + this.show(); }, // helper function to set both modes in one go @@ -237,12 +234,20 @@ vimperator.modes = (function () //{{{ this.show(); }, - // add/remove always work on the extended mode only - add: function (mode) + setCustomMode: function (modestr, oneventfunc, stopfunc) { - extended |= mode; - this.show(); + // TODO this.plugin[id]... ('id' maybe submode or what..) + vimperator.plugins.mode = modestr; + vimperator.plugins.onEvent = oneventfunc; + vimperator.plugins.stop = stopfunc; }, + + // keeps recording state + reset: function (silent) + { + this.set(vimperator.modes.NORMAL, vimperator.modes.NONE, silent); + }, + remove: function (mode) { extended = (extended | mode) ^ mode;