Permalink
Browse files

Refactor insert mode commands.

  • Loading branch information...
1 parent 1c11737 commit eb8beb64fb4432c2c1c758594b0c2db77c5f3481 @georgebrock georgebrock committed Dec 7, 2012
Showing with 28 additions and 12 deletions.
  1. +1 −0 index.html
  2. +10 −12 js/insert_mode.js
  3. +16 −0 js/insert_mode/commands.js
  4. +1 −0 test.html
View
@@ -30,6 +30,7 @@
<script src='js/normal_mode/operators.js'></script>
<script src='js/normal_mode/repeat.js'></script>
<script src='js/insert_mode.js'></script>
+ <script src='js/insert_mode/commands.js'></script>
<script src='js/demo.js'></script>
<script>
window.vimulator = new Vimulator.Demo().init('#vimulator');
View
@@ -1,13 +1,4 @@
(function () {
- var escapeCommand = new Vimulator.Command({
- callback: function (vim) {
- vim.setMode("normal");
- vim.moveCursorRelative(0, -1);
- },
- description: function () {
- return "<kbd>ESC</kbd> Return to normal mode";
- }
- });
var C = Vimulator.Command,
U = Vimulator.Utils;
@@ -20,12 +11,19 @@
this.vim.registers["."] = "";
};
+ Vimulator.InsertMode.prototype.commandList = function () {
+ this.commands = this.commands || new Vimulator.CommandList(
+ Vimulator.InsertMode.Commands
+ );
+ return this.commands;
+ };
+
Vimulator.InsertMode.prototype.keyPress = function (key) {
var op;
- if (key === U.Keys.ESC) {
- op = new Vimulator.Operation;
- op.setCommand(escapeCommand);
+ if (Vimulator.InsertMode.Commands.hasOwnProperty(key)) {
+ op = new Vimulator.Operation(this.commandList());
+ op.keyPress(key);
op.execute(this.vim);
return op;
} else {
View
@@ -0,0 +1,16 @@
+(function () {
+ var C = Vimulator.Command,
+ U = Vimulator.Utils;
+
+ Vimulator.InsertMode.Commands = {};
+
+ Vimulator.InsertMode.Commands[U.Keys.ESC] = new C({
+ callback: function (vim) {
+ vim.setMode("normal");
+ vim.moveCursorRelative(0, -1);
+ },
+ description: function () {
+ return "Return to normal mode";
+ }
+ });
+}());
View
@@ -32,6 +32,7 @@
<script src='js/normal_mode/operators.js'></script>
<script src='js/normal_mode/repeat.js'></script>
<script src='js/insert_mode.js'></script>
+ <script src='js/insert_mode/commands.js'></script>
<script>
window.vimulator = new Vimulator.Base().init('#vimulator');
</script>

0 comments on commit eb8beb6

Please sign in to comment.