Permalink
Browse files

Nicer descriptions for special keys.

  • Loading branch information...
1 parent 13ed5dc commit 1c11737ec73f34aef2564055bdce38aeb6ec76c4 @georgebrock georgebrock committed Dec 7, 2012
Showing with 55 additions and 10 deletions.
  1. +3 −2 js/insert_mode.js
  2. +3 −2 js/normal_mode.js
  3. +13 −5 js/operation.js
  4. +14 −1 js/utils.js
  5. +1 −0 test.html
  6. +21 −0 tests/unit/utils.js
View
@@ -8,6 +8,8 @@
return "<kbd>ESC</kbd> Return to normal mode";
}
});
+ var C = Vimulator.Command,
+ U = Vimulator.Utils;
Vimulator.InsertMode = function (vim) {
this.name = "insert";
@@ -21,8 +23,7 @@
Vimulator.InsertMode.prototype.keyPress = function (key) {
var op;
- // Escape
- if (key === '\u001B') {
+ if (key === U.Keys.ESC) {
op = new Vimulator.Operation;
op.setCommand(escapeCommand);
op.execute(this.vim);
View
@@ -1,4 +1,6 @@
(function () {
+ var U = Vimulator.Utils;
+
Vimulator.NormalMode = function (vim) {
this.name = "normal";
this.vim = vim;
@@ -32,8 +34,7 @@
Vimulator.NormalMode.prototype.keyPress = function (key) {
var op = this.currentOperation;
- // Escape
- if (key === '\u001B') {
+ if (key === U.Keys.ESC) {
this.cancelOperation();
} else {
op.keyPress(key);
View
@@ -1,4 +1,6 @@
(function () {
+ var U = Vimulator.Utils;
+
Vimulator.Operation = function (context) {
this.context = context;
this.multiplier = null;
@@ -93,12 +95,18 @@
var desc, keys, multiplier;
keys = function (str) {
- if (str) {
- str = '' + str;
- return "<kbd>" + str.split("").join("</kbd> <kbd>") + "</kbd> ";
- } else {
- return "";
+ var i, keys;
+
+ if (!str) {
+ return '';
+ }
+
+ str = '' + str;
+ keys = [];
+ for (i = 0; i < str.length; i++) {
+ keys.push("<kbd>" + U.keyName(str.charAt(i)) + "</kbd>");
}
+ return keys.join(' ') + ' ';
};
desc = keys(this.multiplier) +
View
@@ -1,6 +1,13 @@
(function () {
+ var K;
+
Vimulator.Utils = {};
+ Vimulator.Utils.Keys = K = {
+ ESC: '\u001B',
+ RETURN: '\u000D'
+ };
+
Vimulator.Utils.pluralize = function (count, word) {
if (count === 1) {
return "1 " + word;
@@ -24,9 +31,15 @@
Vimulator.Utils.literalArgDescription = function (chr) {
if (chr) {
- return "<kbd>" + chr + "</kbd>";
+ return "<kbd>" + this.keyName(chr) + "</kbd>";
} else {
return "<b>&hellip;</b>";
}
};
+
+ Vimulator.Utils.keyName = function (chr) {
+ if (chr === K.RETURN) { return "\u23CE"; }
+ if (chr === K.ESC) { return "\u241B"; }
+ return chr;
+ };
}());
View
@@ -48,6 +48,7 @@
<script src='tests/unit/insert_mode.js'></script>
<script src='tests/unit/words.js'></script>
<script src='tests/unit/text_object.js'></script>
+ <script src='tests/unit/utils.js'></script>
<script src='tests/acceptance/motions.js'></script>
<script src='tests/acceptance/insertion.js'></script>
View
@@ -0,0 +1,21 @@
+describe("Utils", function () {
+ describe(".keyName", function () {
+ it("describes escape", function () {
+ expect(Vimulator.Utils.keyName(ESC)).toBe("\u241B");
+ });
+
+ it("describes return", function () {
+ expect(Vimulator.Utils.keyName(RETURN)).toBe("\u23CE");
+ });
+
+ it("returns the key for printable characters", function () {
+ var keys, k, i;
+
+ keys = "aQ1.:";
+ for (i = 0; i < keys.length; i++) {
+ k = keys.charAt(i);
+ expect(Vimulator.Utils.keyName(k)).toBe(k);
+ }
+ });
+ });
+});

0 comments on commit 1c11737

Please sign in to comment.