mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-24 16:06:58 +00:00
all configuration and required libs in the config tiddler
This commit is contained in:
parent
17b542980f
commit
d7d5165847
@ -12,25 +12,41 @@ Extend the edit-text widget to use CodeMirror
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var CODEMIRROR_KEYMAP = "$:/CodeMirrorKeymap",
|
||||
kbinding, kbindingsAllowed = /^(vim|emacs)$/i;
|
||||
var CODEMIRROR_OPTIONS = "$:/config/CodeMirror", configOptions;
|
||||
/* e.g. to allow vim key bindings
|
||||
* {
|
||||
* "require": [
|
||||
* "$:/plugins/tiddlywiki/codemirror/addon/dialog.js",
|
||||
* "$:/plugins/tiddlywiki/codemirror/addon/searchcursor.js",
|
||||
* "$:/plugins/tiddlywiki/codemirror/keymap/vim.js"
|
||||
* ],
|
||||
* "configuration": {
|
||||
* "keyMap": "vim",
|
||||
* "showCursorWhenSelecting": true
|
||||
* }
|
||||
*}
|
||||
*/
|
||||
|
||||
var EditTextWidget = require("$:/core/modules/widgets/edit-text.js")["edit-text"];
|
||||
|
||||
if($tw.browser) {
|
||||
require("$:/plugins/tiddlywiki/codemirror/codemirror.js");
|
||||
kbinding = ($tw.wiki.getTiddlerText(CODEMIRROR_KEYMAP) || '').match(kbindingsAllowed);
|
||||
if(kbinding) {
|
||||
require("$:/plugins/tiddlywiki/codemirror/addon/dialog.js");
|
||||
require("$:/plugins/tiddlywiki/codemirror/addon/searchcursor.js");
|
||||
if(kbinding[0].toLowerCase() === 'emacs') {
|
||||
require("$:/plugins/tiddlywiki/codemirror/keymap/emacs.js");
|
||||
EditTextWidget._codemirrorMode = 'emacs';
|
||||
}
|
||||
else if(kbinding[0].toLowerCase() === 'vim') {
|
||||
require("$:/plugins/tiddlywiki/codemirror/keymap/vim.js");
|
||||
EditTextWidget._codemirrorMode = 'vim';
|
||||
|
||||
configOptions = $tw.wiki.getTiddlerData(CODEMIRROR_OPTIONS,{});
|
||||
|
||||
if(configOptions) {
|
||||
if(configOptions["require"]) {
|
||||
if(typeof configOptions["require"] === 'object' &&
|
||||
Object.prototype.toString.call(configOptions["require"]) == '[object Array]') {
|
||||
for (var idx=0; idx < configOptions["require"].length; idx++) {
|
||||
require(configOptions["require"][idx]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
require(configOptions["require"]);
|
||||
}
|
||||
}
|
||||
EditTextWidget._configuration = configOptions["configuration"];
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,14 +55,14 @@ The edit-text widget calls this method just after inserting its dom nodes
|
||||
*/
|
||||
EditTextWidget.prototype.postRender = function() {
|
||||
var self = this,
|
||||
cm, cm_opts = {
|
||||
cm, config, cv, 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;
|
||||
if(EditTextWidget._configuration) {
|
||||
for (cv in EditTextWidget._configuration) { cm_opts[cv] = EditTextWidget._configuration[cv]; }
|
||||
}
|
||||
cm = CodeMirror.fromTextArea(this.domNodes[0], cm_opts);
|
||||
cm.on("change",function() {
|
||||
|
Loading…
Reference in New Issue
Block a user