Add vim demo controls and addons.

This commit is contained in:
jkaplon 2016-05-27 13:39:49 -04:00
parent 2e1b33aea4
commit 6e16540912

View File

@ -3,7 +3,10 @@
<head> <head>
<title>Jody's CodeMirror</title> <title>Jody's CodeMirror</title>
<link rel="stylesheet" href="lib/codemirror.css"> <link rel="stylesheet" href="lib/codemirror.css">
<link rel="stylesheet" href="addon/dialog/dialog.css">
<script src="lib/codemirror.js"></script> <script src="lib/codemirror.js"></script>
<script src="addon/dialog/dialog.js"></script>
<script src="addon/search/searchcursor.js"></script>
<script src="mode/markdown/markdown.js"></script> <script src="mode/markdown/markdown.js"></script>
<script src="keymap/vim.js"></script> <script src="keymap/vim.js"></script>
<style type="text/css"> <style type="text/css">
@ -18,21 +21,38 @@
<form><textarea id="editor" name="editor"> <form><textarea id="editor" name="editor">
{{{notetxt}}} {{{notetxt}}}
</textarea></form> </textarea></form>
<div style="font-size: 13px; width: 300px; height: 30px;">Key buffer: <span id="command-display"></span></div>
<script> <script>
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), { var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
mode: "markdown", mode: "markdown",
lineNumbers: "true", lineNumbers: "true",
keyMap: "vim", keyMap: "vim",
showCursorWhenSelecting: true,
viewportMargin: Infinity viewportMargin: Infinity
}); });
// Add my .vimrc stuff.
CodeMirror.Vim.map('jj', '<Esc>', 'insert')
CodeMirror.Vim.map(';', ':')
CodeMirror.Vim.map(':', ';')
//CodeMirror.commands.save = function(){ alert("Saving"); }
var commandDisplay = document.getElementById('command-display');
var keys = ''
CodeMirror.on(editor, 'vim-keypress', function(key) {
keys = keys + key
commandDisplay.innerHTML = keys
})
CodeMirror.on(editor, 'vim-command-done', function(e) {
keys = ''
commandDisplay.innerHTML = keys
})
var typingTimer; var typingTimer;
editor.on("changes", function() { editor.on("changes", function() {
clearTimeout(typingTimer); clearTimeout(typingTimer);
typingTimer = setTimeout( typingTimer = setTimeout(
function() { function() {
console.log(editor.getValue()); //console.log(editor.getValue());
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onreadystatechange = function () { request.onreadystatechange = function () {
var DONE = this.DONE || 4; var DONE = this.DONE || 4;