Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Added vim an emacs keybidings #6

Merged
merged 1 commit into from about 2 years ago

2 participants

Haris Amin Jesse Wolgamott
Haris Amin
hamin commented March 14, 2012

No description provided.

Jesse Wolgamott
Owner
jwo commented March 14, 2012

Was testing out, and looks like once a riddle has been saved, the button group gets hidden.

I have plans to expand the console width, but I think it's possible if we drop this below the save button? Any other thoughts on where to put this?

https://img.skitch.com/20120315-xyu97i5fudxpwe4yke1xn9k8dx.png

Haris Amin
hamin commented March 14, 2012

@jwo working on the gist integration right now. Almost done. In this new branch I also moved the thing so the keybindings bar so it looks like this:

Gistify

what do u think? If you think its cool just go ahead and merge this pull-request in master and my next pull request with teh gist integration will apply it as it is in the picture above.

Jesse Wolgamott
Owner
jwo commented March 14, 2012
Jesse Wolgamott jwo merged commit 05e9a29 into from March 14, 2012
Jesse Wolgamott jwo closed this March 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 14, 2012
Haris Amin Added vim an emacs keybidings 8a937fd
This page is out of date. Refresh to see the latest.
2  app/assets/javascripts/application.js
@@ -15,4 +15,6 @@
15 15
 //= require foundation
16 16
 //= require codemirror
17 17
 //= require ruby
  18
+//= require vim
  19
+//= require emacs
18 20
 //= require_tree .
29  app/assets/javascripts/emacs.js
... ...
@@ -0,0 +1,29 @@
  1
+// TODO number prefixes
  2
+(function() {
  3
+  // Really primitive kill-ring implementation.
  4
+  var killRing = [];
  5
+  function addToRing(str) {
  6
+    killRing.push(str);
  7
+    if (killRing.length > 50) killRing.shift();
  8
+  }
  9
+  function getFromRing() { return killRing[killRing.length - 1] || ""; }
  10
+  function popFromRing() { if (killRing.length > 1) killRing.pop(); return getFromRing(); }
  11
+
  12
+  CodeMirror.keyMap.emacs = {
  13
+    "Ctrl-X": function(cm) {cm.setOption("keyMap", "emacs-Ctrl-X");},
  14
+    "Ctrl-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
  15
+    "Ctrl-Alt-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
  16
+    "Alt-W": function(cm) {addToRing(cm.getSelection());},
  17
+    "Ctrl-Y": function(cm) {cm.replaceSelection(getFromRing());},
  18
+    "Alt-Y": function(cm) {cm.replaceSelection(popFromRing());},
  19
+    "Ctrl-/": "undo", "Shift-Ctrl--": "undo", "Shift-Alt-,": "goDocStart", "Shift-Alt-.": "goDocEnd",
  20
+    "Ctrl-S": "findNext", "Ctrl-R": "findPrev", "Ctrl-G": "clearSearch", "Shift-Alt-5": "replace",
  21
+    "Ctrl-Z": "undo", "Cmd-Z": "undo",
  22
+    fallthrough: ["basic", "emacsy"]
  23
+  };
  24
+
  25
+  CodeMirror.keyMap["emacs-Ctrl-X"] = {
  26
+    "Ctrl-S": "save", "Ctrl-W": "save", "S": "saveAll", "F": "open", "U": "undo", "K": "close",
  27
+    auto: "emacs", catchall: function(cm) {/*ignore*/}
  28
+  };
  29
+})();
6  app/assets/javascripts/riddle.js.coffee
@@ -7,6 +7,12 @@ $ ->
7 7
      lineNumbers: true,
8 8
      theme: 'rubyblue'
9 9
     )
  10
+  
  11
+  $(".segmented_control button").on "click", ->
  12
+    $("button.selected_binding").removeClass('selected_binding')
  13
+    editor.setOption('keyMap', $(this).val())
  14
+    $(this).addClass('selected_binding')
  15
+    
10 16
 	$("#save_riddle").on "click", ->
11 17
 		$.ajax
12 18
 			type: 'POST',
347  app/assets/javascripts/vim.js
... ...
@@ -0,0 +1,347 @@
  1
+(function() {
  2
+  var count = "";
  3
+  var sdir = "f";
  4
+  var buf = "";
  5
+  var yank = 0;
  6
+  var mark = [];
  7
+  function emptyBuffer() { buf = ""; }
  8
+  function pushInBuffer(str) { buf += str; };
  9
+  function pushCountDigit(digit) { return function(cm) {count += digit;} }
  10
+  function popCount() { var i = parseInt(count); count = ""; return i || 1; }
  11
+  function countTimes(func) {
  12
+    if (typeof func == "string") func = CodeMirror.commands[func];
  13
+    return function(cm) { for (var i = 0, c = popCount(); i < c; ++i) func(cm); }
  14
+  }
  15
+
  16
+  function iterObj(o, f) {
  17
+    for (var prop in o) if (o.hasOwnProperty(prop)) f(prop, o[prop]);
  18
+  }
  19
+
  20
+  var word = [/\w/, /[^\w\s]/], bigWord = [/\S/];
  21
+  function findWord(line, pos, dir, regexps) {
  22
+    var stop = 0, next = -1;
  23
+    if (dir > 0) { stop = line.length; next = 0; }
  24
+    var start = stop, end = stop;
  25
+    // Find bounds of next one.
  26
+    outer: for (; pos != stop; pos += dir) {
  27
+      for (var i = 0; i < regexps.length; ++i) {
  28
+        if (regexps[i].test(line.charAt(pos + next))) {
  29
+          start = pos;
  30
+          for (; pos != stop; pos += dir) {
  31
+            if (!regexps[i].test(line.charAt(pos + next))) break;
  32
+          }
  33
+          end = pos;
  34
+          break outer;
  35
+        }
  36
+      }
  37
+    }
  38
+    return {from: Math.min(start, end), to: Math.max(start, end)};
  39
+  }
  40
+  function moveToWord(cm, regexps, dir, where) {
  41
+    var cur = cm.getCursor(), ch = cur.ch, line = cm.getLine(cur.line), word;
  42
+    while (true) {
  43
+      word = findWord(line, ch, dir, regexps);
  44
+      ch = word[where == "end" ? "to" : "from"];
  45
+      if (ch == cur.ch && word.from != word.to) ch = word[dir < 0 ? "from" : "to"];
  46
+      else break;
  47
+    }
  48
+    cm.setCursor(cur.line, word[where == "end" ? "to" : "from"], true);
  49
+  }
  50
+  function joinLineNext(cm) {
  51
+    var cur = cm.getCursor(), ch = cur.ch, line = cm.getLine(cur.line);
  52
+    CodeMirror.commands.goLineEnd(cm); 
  53
+    if (cur.line != cm.lineCount()) {
  54
+      CodeMirror.commands.goLineEnd(cm);
  55
+      cm.replaceSelection(" ", "end");
  56
+      CodeMirror.commands.delCharRight(cm);
  57
+    } 
  58
+  }
  59
+  function editCursor(mode) {
  60
+    if (mode == "vim-insert") {  
  61
+      // put in your cursor css changing code
  62
+    } else if (mode == "vim") {
  63
+      // put in your cursor css changing code
  64
+    }
  65
+  }
  66
+  function delTillMark(cm, cHar) { 
  67
+    var i = mark[cHar], l = cm.getCursor().line, start = i > l ? l : i, end = i > l ? i : l;
  68
+    cm.setCursor(start);
  69
+    for (var c = start; c <= end; c++) {
  70
+      pushInBuffer("\n"+cm.getLine(start)); 
  71
+      cm.removeLine(start);
  72
+    }
  73
+  }
  74
+  function yankTillMark(cm, cHar) { 
  75
+    var i = mark[cHar], l = cm.getCursor().line, start = i > l ? l : i, end = i > l ? i : l;
  76
+    for (var c = start; c <= end; c++) {
  77
+      pushInBuffer("\n"+cm.getLine(c));
  78
+    }
  79
+    cm.setCursor(start);
  80
+  }
  81
+
  82
+  var map = CodeMirror.keyMap.vim = {
  83
+    "0": function(cm) {count.length > 0 ? pushCountDigit("0")(cm) : CodeMirror.commands.goLineStart(cm);},
  84
+    "A": function(cm) {popCount(); cm.setCursor(cm.getCursor().line, cm.getCursor().ch+1, true); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
  85
+    "Shift-A": function(cm) {popCount(); CodeMirror.commands.goLineEnd(cm); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
  86
+    "I": function(cm) {popCount(); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
  87
+    "Shift-I": function(cm) {popCount(); CodeMirror.commands.goLineStartSmart(cm); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
  88
+    "O": function(cm) {popCount(); CodeMirror.commands.goLineEnd(cm); cm.replaceSelection("\n", "end"); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
  89
+    "Shift-O": function(cm) {popCount(); CodeMirror.commands.goLineStart(cm); cm.replaceSelection("\n", "start"); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
  90
+    "G": function(cm) {cm.setOption("keyMap", "vim-prefix-g");},
  91
+    "D": function(cm) {cm.setOption("keyMap", "vim-prefix-d"); emptyBuffer();},
  92
+    "M": function(cm) {cm.setOption("keyMap", "vim-prefix-m"); mark = [];},
  93
+    "Y": function(cm) {cm.setOption("keyMap", "vim-prefix-y"); emptyBuffer(); yank = 0;},
  94
+    "/": function(cm) {var f = CodeMirror.commands.find; f && f(cm); sdir = "f"},
  95
+    "Shift-/": function(cm) {
  96
+      var f = CodeMirror.commands.find;
  97
+      if (f) { f(cm); CodeMirror.commands.findPrev(cm); sdir = "r"; }
  98
+    },
  99
+    "N": function(cm) {
  100
+      var fn = CodeMirror.commands.findNext;
  101
+      if (fn) sdir != "r" ? fn(cm) : CodeMirror.commands.findPrev(cm);
  102
+    },
  103
+    "Shift-N": function(cm) {
  104
+      var fn = CodeMirror.commands.findNext;
  105
+      if (fn) sdir != "r" ? CodeMirror.commands.findPrev(cm) : fn.findNext(cm);
  106
+    },
  107
+    "Shift-G": function(cm) {count == "" ? cm.setCursor(cm.lineCount()) : cm.setCursor(parseInt(count)-1); popCount(); CodeMirror.commands.goLineStart(cm);},
  108
+    catchall: function(cm) {/*ignore*/}
  109
+  };
  110
+  // Add bindings for number keys
  111
+  for (var i = 1; i < 10; ++i) map[i] = pushCountDigit(i);
  112
+  // Add bindings that are influenced by number keys
  113
+  iterObj({"H": "goColumnLeft", "L": "goColumnRight", "J": "goLineDown", "K": "goLineUp",
  114
+		       "Left": "goColumnLeft", "Right": "goColumnRight", "Down": "goLineDown", "Up": "goLineUp",
  115
+           "Backspace": "goCharLeft", "Space": "goCharRight",
  116
+           "B": function(cm) {moveToWord(cm, word, -1, "end");},
  117
+           "E": function(cm) {moveToWord(cm, word, 1, "end");},
  118
+           "W": function(cm) {moveToWord(cm, word, 1, "start");},
  119
+           "Shift-B": function(cm) {moveToWord(cm, bigWord, -1, "end");},
  120
+           "Shift-E": function(cm) {moveToWord(cm, bigWord, 1, "end");},
  121
+           "Shift-W": function(cm) {moveToWord(cm, bigWord, 1, "start");},
  122
+           "X": function(cm) {CodeMirror.commands.delCharRight(cm)},
  123
+           "P": function(cm) {
  124
+		  var cur = cm.getCursor().line;
  125
+		  if (buf!= "") {
  126
+                    CodeMirror.commands.goLineEnd(cm); 
  127
+		    cm.replaceSelection(buf, "end");
  128
+		  }
  129
+		  cm.setCursor(cur+1);
  130
+	        },
  131
+           "Shift-X": function(cm) {CodeMirror.commands.delCharLeft(cm)},
  132
+           "Shift-J": function(cm) {joinLineNext(cm)},
  133
+           "Shift-`": function(cm) {
  134
+                        var cur = cm.getCursor(), cHar = cm.getRange({line: cur.line, ch: cur.ch}, {line: cur.line, ch: cur.ch+1});
  135
+			cHar = cHar != cHar.toLowerCase() ? cHar.toLowerCase() : cHar.toUpperCase();
  136
+                        cm.replaceRange(cHar, {line: cur.line, ch: cur.ch}, {line: cur.line, ch: cur.ch+1});
  137
+			cm.setCursor(cur.line, cur.ch+1);
  138
+	              },
  139
+           "Ctrl-B": function(cm) {CodeMirror.commands.goPageUp(cm)},
  140
+           "Ctrl-F": function(cm) {CodeMirror.commands.goPageDown(cm)},
  141
+	   "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
  142
+           "U": "undo", "Ctrl-R": "redo", "Shift-4": "goLineEnd"},
  143
+          function(key, cmd) { map[key] = countTimes(cmd); });
  144
+
  145
+  CodeMirror.keyMap["vim-prefix-g"] = {
  146
+    "E": countTimes(function(cm) { moveToWord(cm, word, -1, "start");}),
  147
+    "Shift-E": countTimes(function(cm) { moveToWord(cm, bigWord, -1, "start");}),
  148
+    auto: "vim", 
  149
+    catchall: function(cm) {/*ignore*/}
  150
+  };
  151
+
  152
+  CodeMirror.keyMap["vim-prefix-m"] = {
  153
+    "A": function(cm) {mark["A"] = cm.getCursor().line;},
  154
+    "Shift-A": function(cm) {mark["Shift-A"] = cm.getCursor().line;},
  155
+    "B": function(cm) {mark["B"] = cm.getCursor().line;},
  156
+    "Shift-B": function(cm) {mark["Shift-B"] = cm.getCursor().line;},
  157
+    "C": function(cm) {mark["C"] = cm.getCursor().line;},
  158
+    "Shift-C": function(cm) {mark["Shift-C"] = cm.getCursor().line;},
  159
+    "D": function(cm) {mark["D"] = cm.getCursor().line;},
  160
+    "Shift-D": function(cm) {mark["Shift-D"] = cm.getCursor().line;},
  161
+    "E": function(cm) {mark["E"] = cm.getCursor().line;},
  162
+    "Shift-E": function(cm) {mark["Shift-E"] = cm.getCursor().line;},
  163
+    "F": function(cm) {mark["F"] = cm.getCursor().line;},
  164
+    "Shift-F": function(cm) {mark["Shift-F"] = cm.getCursor().line;},
  165
+    "G": function(cm) {mark["G"] = cm.getCursor().line;},
  166
+    "Shift-G": function(cm) {mark["Shift-G"] = cm.getCursor().line;},
  167
+    "H": function(cm) {mark["H"] = cm.getCursor().line;},
  168
+    "Shift-H": function(cm) {mark["Shift-H"] = cm.getCursor().line;},
  169
+    "I": function(cm) {mark["I"] = cm.getCursor().line;},
  170
+    "Shift-I": function(cm) {mark["Shift-I"] = cm.getCursor().line;},
  171
+    "J": function(cm) {mark["J"] = cm.getCursor().line;},
  172
+    "Shift-J": function(cm) {mark["Shift-J"] = cm.getCursor().line;},
  173
+    "K": function(cm) {mark["K"] = cm.getCursor().line;},
  174
+    "Shift-K": function(cm) {mark["Shift-K"] = cm.getCursor().line;},
  175
+    "L": function(cm) {mark["L"] = cm.getCursor().line;},
  176
+    "Shift-L": function(cm) {mark["Shift-L"] = cm.getCursor().line;},
  177
+    "M": function(cm) {mark["M"] = cm.getCursor().line;},
  178
+    "Shift-M": function(cm) {mark["Shift-M"] = cm.getCursor().line;},
  179
+    "N": function(cm) {mark["N"] = cm.getCursor().line;},
  180
+    "Shift-N": function(cm) {mark["Shift-N"] = cm.getCursor().line;},
  181
+    "O": function(cm) {mark["O"] = cm.getCursor().line;},
  182
+    "Shift-O": function(cm) {mark["Shift-O"] = cm.getCursor().line;},
  183
+    "P": function(cm) {mark["P"] = cm.getCursor().line;},
  184
+    "Shift-P": function(cm) {mark["Shift-P"] = cm.getCursor().line;},
  185
+    "Q": function(cm) {mark["Q"] = cm.getCursor().line;},
  186
+    "Shift-Q": function(cm) {mark["Shift-Q"] = cm.getCursor().line;},
  187
+    "R": function(cm) {mark["R"] = cm.getCursor().line;},
  188
+    "Shift-R": function(cm) {mark["Shift-R"] = cm.getCursor().line;},
  189
+    "S": function(cm) {mark["S"] = cm.getCursor().line;},
  190
+    "Shift-S": function(cm) {mark["Shift-S"] = cm.getCursor().line;},
  191
+    "T": function(cm) {mark["T"] = cm.getCursor().line;},
  192
+    "Shift-T": function(cm) {mark["Shift-T"] = cm.getCursor().line;},
  193
+    "U": function(cm) {mark["U"] = cm.getCursor().line;},
  194
+    "Shift-U": function(cm) {mark["Shift-U"] = cm.getCursor().line;},
  195
+    "V": function(cm) {mark["V"] = cm.getCursor().line;},
  196
+    "Shift-V": function(cm) {mark["Shift-V"] = cm.getCursor().line;},
  197
+    "W": function(cm) {mark["W"] = cm.getCursor().line;},
  198
+    "Shift-W": function(cm) {mark["Shift-W"] = cm.getCursor().line;},
  199
+    "X": function(cm) {mark["X"] = cm.getCursor().line;},
  200
+    "Shift-X": function(cm) {mark["Shift-X"] = cm.getCursor().line;},
  201
+    "Y": function(cm) {mark["Y"] = cm.getCursor().line;},
  202
+    "Shift-Y": function(cm) {mark["Shift-Y"] = cm.getCursor().line;},
  203
+    "Z": function(cm) {mark["Z"] = cm.getCursor().line;},
  204
+    "Shift-Z": function(cm) {mark["Shift-Z"] = cm.getCursor().line;},
  205
+    auto: "vim", 
  206
+    catchall: function(cm) {/*ignore*/}
  207
+  }
  208
+  
  209
+  CodeMirror.keyMap["vim-prefix-d"] = {
  210
+    "D": countTimes(function(cm) { pushInBuffer("\n"+cm.getLine(cm.getCursor().line)); cm.removeLine(cm.getCursor().line); }),
  211
+    "'": function(cm) {cm.setOption("keyMap", "vim-prefix-d'"); emptyBuffer();},
  212
+    auto: "vim", 
  213
+    catchall: function(cm) {/*ignore*/}
  214
+  };
  215
+
  216
+  CodeMirror.keyMap["vim-prefix-d'"] = {
  217
+    "A": function(cm) {delTillMark(cm,"A");},
  218
+    "Shift-A": function(cm) {delTillMark(cm,"Shift-A");},
  219
+    "B": function(cm) {delTillMark(cm,"B");},
  220
+    "Shift-B": function(cm) {delTillMark(cm,"Shift-B");},
  221
+    "C": function(cm) {delTillMark(cm,"C");},
  222
+    "Shift-C": function(cm) {delTillMark(cm,"Shift-C");},
  223
+    "D": function(cm) {delTillMark(cm,"D");},
  224
+    "Shift-D": function(cm) {delTillMark(cm,"Shift-D");},
  225
+    "E": function(cm) {delTillMark(cm,"E");},
  226
+    "Shift-E": function(cm) {delTillMark(cm,"Shift-E");},
  227
+    "F": function(cm) {delTillMark(cm,"F");},
  228
+    "Shift-F": function(cm) {delTillMark(cm,"Shift-F");},
  229
+    "G": function(cm) {delTillMark(cm,"G");},
  230
+    "Shift-G": function(cm) {delTillMark(cm,"Shift-G");},
  231
+    "H": function(cm) {delTillMark(cm,"H");},
  232
+    "Shift-H": function(cm) {delTillMark(cm,"Shift-H");},
  233
+    "I": function(cm) {delTillMark(cm,"I");},
  234
+    "Shift-I": function(cm) {delTillMark(cm,"Shift-I");},
  235
+    "J": function(cm) {delTillMark(cm,"J");},
  236
+    "Shift-J": function(cm) {delTillMark(cm,"Shift-J");},
  237
+    "K": function(cm) {delTillMark(cm,"K");},
  238
+    "Shift-K": function(cm) {delTillMark(cm,"Shift-K");},
  239
+    "L": function(cm) {delTillMark(cm,"L");},
  240
+    "Shift-L": function(cm) {delTillMark(cm,"Shift-L");},
  241
+    "M": function(cm) {delTillMark(cm,"M");},
  242
+    "Shift-M": function(cm) {delTillMark(cm,"Shift-M");},
  243
+    "N": function(cm) {delTillMark(cm,"N");},
  244
+    "Shift-N": function(cm) {delTillMark(cm,"Shift-N");},
  245
+    "O": function(cm) {delTillMark(cm,"O");},
  246
+    "Shift-O": function(cm) {delTillMark(cm,"Shift-O");},
  247
+    "P": function(cm) {delTillMark(cm,"P");},
  248
+    "Shift-P": function(cm) {delTillMark(cm,"Shift-P");},
  249
+    "Q": function(cm) {delTillMark(cm,"Q");},
  250
+    "Shift-Q": function(cm) {delTillMark(cm,"Shift-Q");},
  251
+    "R": function(cm) {delTillMark(cm,"R");},
  252
+    "Shift-R": function(cm) {delTillMark(cm,"Shift-R");},
  253
+    "S": function(cm) {delTillMark(cm,"S");},
  254
+    "Shift-S": function(cm) {delTillMark(cm,"Shift-S");},
  255
+    "T": function(cm) {delTillMark(cm,"T");},
  256
+    "Shift-T": function(cm) {delTillMark(cm,"Shift-T");},
  257
+    "U": function(cm) {delTillMark(cm,"U");},
  258
+    "Shift-U": function(cm) {delTillMark(cm,"Shift-U");},
  259
+    "V": function(cm) {delTillMark(cm,"V");},
  260
+    "Shift-V": function(cm) {delTillMark(cm,"Shift-V");},
  261
+    "W": function(cm) {delTillMark(cm,"W");},
  262
+    "Shift-W": function(cm) {delTillMark(cm,"Shift-W");},
  263
+    "X": function(cm) {delTillMark(cm,"X");},
  264
+    "Shift-X": function(cm) {delTillMark(cm,"Shift-X");},
  265
+    "Y": function(cm) {delTillMark(cm,"Y");},
  266
+    "Shift-Y": function(cm) {delTillMark(cm,"Shift-Y");},
  267
+    "Z": function(cm) {delTillMark(cm,"Z");},
  268
+    "Shift-Z": function(cm) {delTillMark(cm,"Shift-Z");},
  269
+    auto: "vim", 
  270
+    catchall: function(cm) {/*ignore*/}
  271
+  };
  272
+
  273
+  CodeMirror.keyMap["vim-prefix-y'"] = {
  274
+    "A": function(cm) {yankTillMark(cm,"A");},
  275
+    "Shift-A": function(cm) {yankTillMark(cm,"Shift-A");},
  276
+    "B": function(cm) {yankTillMark(cm,"B");},
  277
+    "Shift-B": function(cm) {yankTillMark(cm,"Shift-B");},
  278
+    "C": function(cm) {yankTillMark(cm,"C");},
  279
+    "Shift-C": function(cm) {yankTillMark(cm,"Shift-C");},
  280
+    "D": function(cm) {yankTillMark(cm,"D");},
  281
+    "Shift-D": function(cm) {yankTillMark(cm,"Shift-D");},
  282
+    "E": function(cm) {yankTillMark(cm,"E");},
  283
+    "Shift-E": function(cm) {yankTillMark(cm,"Shift-E");},
  284
+    "F": function(cm) {yankTillMark(cm,"F");},
  285
+    "Shift-F": function(cm) {yankTillMark(cm,"Shift-F");},
  286
+    "G": function(cm) {yankTillMark(cm,"G");},
  287
+    "Shift-G": function(cm) {yankTillMark(cm,"Shift-G");},
  288
+    "H": function(cm) {yankTillMark(cm,"H");},
  289
+    "Shift-H": function(cm) {yankTillMark(cm,"Shift-H");},
  290
+    "I": function(cm) {yankTillMark(cm,"I");},
  291
+    "Shift-I": function(cm) {yankTillMark(cm,"Shift-I");},
  292
+    "J": function(cm) {yankTillMark(cm,"J");},
  293
+    "Shift-J": function(cm) {yankTillMark(cm,"Shift-J");},
  294
+    "K": function(cm) {yankTillMark(cm,"K");},
  295
+    "Shift-K": function(cm) {yankTillMark(cm,"Shift-K");},
  296
+    "L": function(cm) {yankTillMark(cm,"L");},
  297
+    "Shift-L": function(cm) {yankTillMark(cm,"Shift-L");},
  298
+    "M": function(cm) {yankTillMark(cm,"M");},
  299
+    "Shift-M": function(cm) {yankTillMark(cm,"Shift-M");},
  300
+    "N": function(cm) {yankTillMark(cm,"N");},
  301
+    "Shift-N": function(cm) {yankTillMark(cm,"Shift-N");},
  302
+    "O": function(cm) {yankTillMark(cm,"O");},
  303
+    "Shift-O": function(cm) {yankTillMark(cm,"Shift-O");},
  304
+    "P": function(cm) {yankTillMark(cm,"P");},
  305
+    "Shift-P": function(cm) {yankTillMark(cm,"Shift-P");},
  306
+    "Q": function(cm) {yankTillMark(cm,"Q");},
  307
+    "Shift-Q": function(cm) {yankTillMark(cm,"Shift-Q");},
  308
+    "R": function(cm) {yankTillMark(cm,"R");},
  309
+    "Shift-R": function(cm) {yankTillMark(cm,"Shift-R");},
  310
+    "S": function(cm) {yankTillMark(cm,"S");},
  311
+    "Shift-S": function(cm) {yankTillMark(cm,"Shift-S");},
  312
+    "T": function(cm) {yankTillMark(cm,"T");},
  313
+    "Shift-T": function(cm) {yankTillMark(cm,"Shift-T");},
  314
+    "U": function(cm) {yankTillMark(cm,"U");},
  315
+    "Shift-U": function(cm) {yankTillMark(cm,"Shift-U");},
  316
+    "V": function(cm) {yankTillMark(cm,"V");},
  317
+    "Shift-V": function(cm) {yankTillMark(cm,"Shift-V");},
  318
+    "W": function(cm) {yankTillMark(cm,"W");},
  319
+    "Shift-W": function(cm) {yankTillMark(cm,"Shift-W");},
  320
+    "X": function(cm) {yankTillMark(cm,"X");},
  321
+    "Shift-X": function(cm) {yankTillMark(cm,"Shift-X");},
  322
+    "Y": function(cm) {yankTillMark(cm,"Y");},
  323
+    "Shift-Y": function(cm) {yankTillMark(cm,"Shift-Y");},
  324
+    "Z": function(cm) {yankTillMark(cm,"Z");},
  325
+    "Shift-Z": function(cm) {yankTillMark(cm,"Shift-Z");},
  326
+    auto: "vim", 
  327
+    catchall: function(cm) {/*ignore*/}
  328
+  };
  329
+
  330
+  CodeMirror.keyMap["vim-prefix-y"] = {
  331
+    "Y": countTimes(function(cm) { pushInBuffer("\n"+cm.getLine(cm.getCursor().line+yank)); yank++; }),
  332
+    "'": function(cm) {cm.setOption("keyMap", "vim-prefix-y'"); emptyBuffer();},
  333
+    auto: "vim", 
  334
+    catchall: function(cm) {/*ignore*/}
  335
+  };
  336
+
  337
+  CodeMirror.keyMap["vim-insert"] = {
  338
+    "Esc": function(cm) {
  339
+	     cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1, true); 
  340
+	     cm.setOption("keyMap", "vim");
  341
+	     editCursor("vim");
  342
+           },
  343
+    "Ctrl-N": function(cm) {/* Code to bring up autocomplete hint */},
  344
+    "Ctrl-P": function(cm) {/* Code to bring up autocomplete hint */},
  345
+    fallthrough: ["default"]
  346
+  };
  347
+})();
85  app/assets/stylesheets/app.css.scss.erb
@@ -39,3 +39,88 @@ footer {
39 39
     border-top: 1px solid #ccc;
40 40
   }
41 41
 }
  42
+
  43
+.segmented_control {
  44
+    padding-top: 3px;
  45
+    width: 400px;
  46
+    display: inline-block;
  47
+    -webkit-box-shadow: 0 1px 0 #fff;
  48
+    -moz-box-shadow: 0 1px 0 #fff;
  49
+    box-shadow: 0 1px 0 #fff;
  50
+    -webkit-border-radius: 3px;
  51
+    -moz-border-radius: 3px;
  52
+    border-radius: 3px;
  53
+    
  54
+    button {
  55
+        margin: 0;
  56
+        padding: 4px 12px;
  57
+        border: 1px solid #777;
  58
+        text-shadow: 0 1px 0 #fff;
  59
+        font-size: 12px;
  60
+        background: #eee;
  61
+        background: -webkit-gradient(
  62
+            linear, left top, left bottom,
  63
+            from(#fff), to(#ddd)
  64
+        );
  65
+        background: -moz-linear-gradient(top, #fff, #ddd);
  66
+    }
  67
+    
  68
+    button.left_section {
  69
+        border-right: 0;
  70
+        -webkit-border-top-left-radius: 4px;
  71
+        -webkit-border-bottom-left-radius: 4px;
  72
+        -moz-border-radius: 4px 0 0 4px;
  73
+        border-radius: 4px 0 0 4px;
  74
+        -webkit-background-clip: padding-box;
  75
+    }
  76
+    
  77
+    button.middle_section {
  78
+        margin-left: -8px;
  79
+        border-right: 0;
  80
+    }
  81
+    
  82
+    button.right_section {
  83
+        margin-left: -8px;
  84
+        -webkit-border-top-right-radius: 4px;
  85
+        -webkit-border-bottom-right-radius: 4px;
  86
+        -moz-border-radius: 0 4px 4px 0;
  87
+        border-radius: 0 4px 4px 0;
  88
+        -webkit-background-clip: padding-box;
  89
+    }
  90
+    
  91
+    button:active {
  92
+        background: #ccc;
  93
+        background: -webkit-gradient(
  94
+            linear, left top, left bottom,
  95
+            from(#ddd), to(#bbb)
  96
+        );
  97
+        background: -moz-linear-gradient(top, #ddd, #bbb);
  98
+        text-shadow: 0 1px 0 #eee;
  99
+        -webkit-box-shadow: inset 0 1px 4px #000;
  100
+        -moz-box-shadow: inset 0 1px 4px #000;
  101
+        box-shadow: inset 0 1px 4px #000;
  102
+    }
  103
+    
  104
+    button::-moz-focus-inner {
  105
+        border: 0;
  106
+    }
  107
+    
  108
+    button:focus {     
  109
+        outline: none; 
  110
+    }
  111
+    
  112
+    button.selected_binding{
  113
+      background: #ccc;
  114
+      color: white;
  115
+      background: -webkit-gradient(
  116
+          linear, left top, left bottom,
  117
+          from(#126EE4), to(#4F99FA)
  118
+      );
  119
+      background: -moz-linear-gradient(top, #126EE4, #4F99FA);
  120
+      text-shadow: 0 1px 0 #eee;
  121
+      -webkit-box-shadow: inset 0 1px 4px #000;
  122
+      -moz-box-shadow: inset 0 1px 4px #000;
  123
+      box-shadow: inset 0 1px 4px #000;
  124
+    }
  125
+    
  126
+}
7  app/views/riddles/index.html.haml
@@ -16,6 +16,13 @@
16 16
             =link_to "#", :id=>"save_riddle", :class=> "white small radius button" do
17 17
               %i.icon-edit.icon-large
18 18
               Save
  19
+        %li
  20
+          .segmented_control.left_section
  21
+            / .white.small KeyBindings
  22
+            %i.icon-cogs.icon-large
  23
+            %button#none.left_section.selected_binding{:type => 'button', :value => 'none'} none
  24
+            %button#vim.middle_section{:type => 'button', :value => 'vim'} vim
  25
+            %button#emacs.right_section{:type => 'button', :value => 'emacs'} emacs
19 26
   .row
20 27
     .five.columns
21 28
       =render partial: "form"
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.