CodeMirror 5.36.0 modularized (#3184)

* v5.35.1

* codemirror 5.35.1

* v5.35.1

* v5.35.1

* v5.35.1

* v5.35.1

* v5.35.1

* adding search&replace and autocomplete

* update version number

* add jump-to-line.js required for search&replace

* adding show-hint.js required by autocomplete

* adding basic autocomplete for any word

* adding autocomplete css

* adding new files to tiddlywiki.files

* forgot adding search.js

* minify 'em all

* Delete vim.js

* Delete sublime.js

* Delete emacs.js

* Delete anyword-hint.js

* Delete show-hint.css

* Delete show-hint.js

* Update config.tid

* Update tiddlywiki.files

* Update tiddlywiki.files

* Update config.tid

* Update config.tid

* Update config.tid

* Delete dialog.js

* Delete dialog.css

* Delete jump-to-line.js

* Delete search.js

* Delete searchcursor.js

* Update tiddlywiki.files

* Update tiddlywiki.files

* Update tiddlywiki.files

* add search-and-replace cm-addon as plugin

* add autocomplete cm-addon as plugin

* add fullscreen-editing cm-addon as plugin

* add keymaps as plugins + cleanup

* add highlighting modes as plugins

* small update on usage.tid

* moved multiplex.js to htmlembedded mode - the only one using it

* config/CodeMirror update

* how to disable line numbers

* how to change CM theme

* add closebrackets and closetags addons

* packaging a base-addon

* move meta.js from codemirror to base addon

* inputStyle: textarea -> prevents contenteditable on mobile browsers, keeps focus when clicking toolbar buttons, prevents import on paste

* default config no line numbers

* temporary add panel plugin for demo

* put base-plugin back to codemirror editor

* searchcursor to searchnreplace plugin

* bad copypasta mistake

* another typo

* stripped down meta.js + moved matchbrackets to closebrackets plugin

* remove panel

* change module-type to codemirro and make init "require" dynamic.

* make config handling dynamic with sensible defaults

* make cm settings translateable

* delete multids. they will be replaced

* add auto-config tiddlers

* dynamically create config structure for CM

* fix filename

* change typo

* kitchensink config, plus change plugin description for better sorting.

* add matchBrackets config tiddler

* RIP codeblock

* removed install instructions from readme - codemirror usage tiddler still todo

* control panel settings for cm base

* add setting for auto-close tags

* adding fontfamily settings and theme settings

* change tags for settings from $:/tags/ControlPanel/Settings to $:/tags/ControlPanel/Settings/CodeMirror

* more usage info

* more usage info

* update to v5.36.0

* ugly hack enables highlighting and tag-closing for vnd.tiddlywiki and x-tiddlywiki

* disable auto-indent for vnd.tiddlywiki & x-tiddlywiki and add some hidden settings

* remove engine.js hack

* meta.js -> tw-meta.js

* codemirror settings tab

* rename tiddler to tw-meta.js

* make editor font monospace or sans-serif - dropdown select

* make editor font monospace or sans-serif - dropdown select

* now using correct tiddler for editor font setting

* better usage doc

* make markdown-mode require tw-meta

* add more themes info

* add active-line highlighting option

* mini usage change

* add integer type to engine.js config-getter

* blink rate config type string

* correct engine.js

* license for base-plugin, usage link in settings tab

* codemirrordemo hellothere update

* codemirrordemo hellothere update

* Update license.tid

* codemirror demo sidebarlayout, license

* license headers to addon files

* license formatting & forgot what year we have

* license formatting & forgot what year we have & codemirror demo sitetitle sitesubtitle

* more informations 'try-this-style' for codemirrordemo hellothere

* codemirror demo sitetitle & cm fontfamily

* hellothere

* font-family setting must be editor-font-family, not code-font-family

* add basic keyboard shortcuts table

* shortcuts change to not interfere with toolbar shortcuts - needs testing - vim and emacs todo

* formatting

* controlpanel change keymap - default keymap is default

* ctrl-T becomes Alt-T in default keymap

* adjustments for codemirror demo

* demo: hellothere - hint for sidebar keymap cheatsheet

* toolbar focus fix + remove console log

* engine.js cleanup

* formatting

* reverting focus fix

* indenting engine.js

* hoping that indenting gets better
This commit is contained in:
BurningTreeC
2018-04-06 18:34:50 +02:00
committed by Jeremy Ruston
parent 02529a51d0
commit 3d64d7d126
144 changed files with 1263 additions and 19750 deletions

View File

@@ -13,14 +13,17 @@ Text editor engine based on a CodeMirror instance
"use strict";
var CODEMIRROR_OPTIONS = "$:/config/CodeMirror",
HEIGHT_VALUE_TITLE = "$:/config/TextEditor/EditorHeight/Height"
HEIGHT_VALUE_TITLE = "$:/config/TextEditor/EditorHeight/Height",
CONFIG_FILTER = "[all[shadows+tiddlers]prefix[$:/config/codemirror/]]"
// Install CodeMirror
if($tw.browser && !window.CodeMirror) {
var modules = $tw.modules.types["codemirror"];
var req = Object.getOwnPropertyNames(modules);
window.CodeMirror = require("$:/plugins/tiddlywiki/codemirror/lib/codemirror.js");
// Install required CodeMirror plugins
var configOptions = $tw.wiki.getTiddlerData(CODEMIRROR_OPTIONS,{}),
req = configOptions.require;
if(req) {
if($tw.utils.isArray(req)) {
for(var index=0; index<req.length; index++) {
@@ -32,7 +35,55 @@ if($tw.browser && !window.CodeMirror) {
}
}
function getCmConfig() {
var type,
test,
value,
element,
extend,
tiddler,
config = {},
configTiddlers = $tw.wiki.filterTiddlers(CONFIG_FILTER);
if ($tw.utils.isArray(configTiddlers)) {
for (var i=0; i<configTiddlers.length; i++) {
tiddler = $tw.wiki.getTiddler(configTiddlers[i]);
if (tiddler) {
element = configTiddlers[i].replace(/\$:\/config\/codemirror\//ig,"");
type = (tiddler.fields.type) ? tiddler.fields.type.trim().toLocaleLowerCase() : "string";
switch (type) {
case "bool":
test = tiddler.fields.text.trim().toLowerCase();
value = (test === "true") ? true : false;
config[element] = value;
break;
case "string":
value = tiddler.fields.text.trim();
config[element] = value;
break;
case "integer":
value = parseInt(tiddler.fields.text.trim(), 10);
config[element] = value;
break;
case "json":
value = JSON.parse(tiddler.fields.text.trim());
extend = (tiddler.fields.extend) ? tiddler.fields.extend : element;
if (config[extend]) {
$tw.utils.extend(config[extend], value);
} else {
config[extend] = value;
}
break;
}
}
}
}
return config;
}
function CodeMirrorEngine(options) {
// Save our options
var self = this;
options = options || {};
@@ -48,14 +99,11 @@ function CodeMirrorEngine(options) {
this.domNode.style.display = "inline-block";
this.parentNode.insertBefore(this.domNode,this.nextSibling);
this.widget.domNodes.push(this.domNode);
// Set all cm-plugin defaults
// Get the configuration options for the CodeMirror object
var config = $tw.wiki.getTiddlerData(CODEMIRROR_OPTIONS,{}).configuration || {};
if(!("lineWrapping" in config)) {
config.lineWrapping = true;
}
if(!("lineNumbers" in config)) {
config.lineNumbers = true;
}
var config = getCmConfig();
config.mode = options.type;
config.value = options.value;
// Create the CodeMirror instance
@@ -63,6 +111,7 @@ function CodeMirrorEngine(options) {
// Note that this is a synchronous callback that is called before the constructor returns
self.domNode.appendChild(cmDomNode);
},config);
// Set up a change event handler
this.cm.on("change",function() {
self.widget.saveChanges(self.getText());
@@ -80,7 +129,8 @@ function CodeMirrorEngine(options) {
Set the text of the engine if it doesn't currently have focus
*/
CodeMirrorEngine.prototype.setText = function(text,type) {
this.cm.setOption("mode",type);
var self = this;
self.cm.setOption("mode",type);
if(!this.cm.hasFocus()) {
this.cm.setValue(text);
}
@@ -121,7 +171,7 @@ CodeMirrorEngine.prototype.createTextOperation = function() {
var selections = this.cm.listSelections();
if(selections.length > 0) {
var anchorPos = this.cm.indexFromPos(selections[0].anchor),
headPos = this.cm.indexFromPos(selections[0].head);
headPos = this.cm.indexFromPos(selections[0].head);
}
var operation = {
text: this.cm.getValue(),