mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-29 05:06:36 +00:00
added suport for vim and emacs keymaps (codemirror updated to 3.20)
This commit is contained in:
@@ -12,23 +12,43 @@ Extend the edit-text widget to use CodeMirror
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
if($tw.browser) {
|
||||
require("$:/plugins/tiddlywiki/codemirror/codemirror.js");
|
||||
}
|
||||
var CODEMIRROR_KEYMAP = "$:/CodeMirrorKeymap",
|
||||
mode, modesAllowed = /^(vim|emacs)$/i;
|
||||
|
||||
var EditTextWidget = require("$:/core/modules/widgets/edit-text.js")["edit-text"];
|
||||
|
||||
if($tw.browser) {
|
||||
require("$:/plugins/tiddlywiki/codemirror/codemirror.js");
|
||||
mode = ($tw.wiki.getTiddlerText(CODEMIRROR_KEYMAP) || '').match(modesAllowed);
|
||||
if (mode) {
|
||||
require("$:/plugins/tiddlywiki/codemirror/addon/dialog.js");
|
||||
require("$:/plugins/tiddlywiki/codemirror/addon/searchcursor.js");
|
||||
if (mode[0].toLowerCase() === 'emacs') {
|
||||
require("$:/plugins/tiddlywiki/codemirror/keymap/emacs.js");
|
||||
EditTextWidget._codemirrorMode = 'emacs';
|
||||
}
|
||||
else {
|
||||
require("$:/plugins/tiddlywiki/codemirror/keymap/vim.js");
|
||||
EditTextWidget._codemirrorMode = 'vim';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The edit-text widget calls this method just after inserting its dom nodes
|
||||
*/
|
||||
EditTextWidget.prototype.postRender = function() {
|
||||
var self = this,
|
||||
cm;
|
||||
if($tw.browser && window.CodeMirror && this.editTag === "textarea") {
|
||||
cm = CodeMirror.fromTextArea(this.domNodes[0],{
|
||||
cm, cm_opts = {
|
||||
lineWrapping: true,
|
||||
lineNumbers: true
|
||||
});
|
||||
};
|
||||
if($tw.browser && window.CodeMirror && this.editTag === "textarea") {
|
||||
if (EditTextWidget._codemirrorMode) {
|
||||
cm_opts["keyMap"] = EditTextWidget._codemirrorMode;
|
||||
cm_opts["showCursorWhenSelecting"] = true;
|
||||
}
|
||||
cm = CodeMirror.fromTextArea(this.domNodes[0], cm_opts);
|
||||
cm.on("change",function() {
|
||||
self.saveChanges(cm.getValue());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user