1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-13 07:24:21 +00:00
TiddlyWiki5/plugins/tiddlywiki/codemirror-closetag/files/addon/edit/closetag.js
BurningTreeC 3d64d7d126 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
2018-04-06 17:34:50 +01:00

3 lines
3.4 KiB
JavaScript

// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror"),require("../fold/xml-fold")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../fold/xml-fold"],e):e(CodeMirror)}(function(e){e.defineOption("autoCloseTags",!1,function(i,s,l){if(l!=e.Init&&l&&i.removeKeyMap("autoCloseTags"),s){var d={name:"autoCloseTags"};("object"!=typeof s||s.whenClosing)&&(d["'/'"]=function(t){return(n=t).getOption("disableInput")?e.Pass:o(n,!0);var n}),("object"!=typeof s||s.whenOpening)&&(d["'>'"]=function(o){return function(o){if(o.getOption("disableInput"))return e.Pass;for(var i=o.listSelections(),s=[],l=o.getOption("autoCloseTags"),d=0;d<i.length;d++){if(!i[d].empty())return e.Pass;var c=i[d].head,f=o.getTokenAt(c),g=e.innerMode(o.getMode(),f.state),u=g.state;if("xml"!=g.mode.name||!u.tagName)return e.Pass;var m="html"==g.mode.configuration,h="object"==typeof l&&l.dontCloseTags||m&&t,p="object"==typeof l&&l.indentTags||m&&n,v=u.tagName;f.end>c.ch&&(v=v.slice(0,v.length-f.end+c.ch));var b=v.toLowerCase();if(!v||"string"==f.type&&(f.end!=c.ch||!/[\"\']/.test(f.string.charAt(f.string.length-1))||1==f.string.length)||"tag"==f.type&&"closeTag"==u.type||f.string.indexOf("/")==f.string.length-1||h&&a(h,b)>-1||r(o,v,c,u,!0))return e.Pass;var y=p&&a(p,b)>-1;s[d]={indent:y,text:">"+(y?"\n\n":"")+"</"+v+">",newPos:y?e.Pos(c.line+1,0):e.Pos(c.line,c.ch+1)}}for(var x="object"==typeof l&&l.dontIndentOnAutoClose,d=i.length-1;d>=0;d--){var P=s[d];o.replaceRange(P.text,i[d].head,i[d].anchor,"+insert");var T=o.listSelections().slice(0);T[d]={head:P.newPos,anchor:P.newPos},o.setSelections(T),!x&&P.indent&&(o.indentLine(P.newPos.line,null,!0),o.indentLine(P.newPos.line+1,null,!0))}}(o)}),i.addKeyMap(d)}});var t=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],n=["applet","blockquote","body","button","div","dl","fieldset","form","frameset","h1","h2","h3","h4","h5","h6","head","html","iframe","layer","legend","object","ol","p","select","table","ul"];function o(t,n){for(var o=t.listSelections(),a=[],i=n?"/":"</",s=t.getOption("autoCloseTags"),l="object"==typeof s&&s.dontIndentOnSlash,d=0;d<o.length;d++){if(!o[d].empty())return e.Pass;var c,f=o[d].head,g=t.getTokenAt(f),u=e.innerMode(t.getMode(),g.state),m=u.state;if(n&&("string"==g.type||"<"!=g.string.charAt(0)||g.start!=f.ch-1))return e.Pass;if("xml"!=u.mode.name)if("htmlmixed"==t.getMode().name&&"javascript"==u.mode.name)c=i+"script";else{if("htmlmixed"!=t.getMode().name||"css"!=u.mode.name)return e.Pass;c=i+"style"}else{if(!m.context||!m.context.tagName||r(t,m.context.tagName,f,m))return e.Pass;c=i+m.context.tagName}">"!=t.getLine(f.line).charAt(g.end)&&(c+=">"),a[d]=c}if(t.replaceSelections(a),o=t.listSelections(),!l)for(d=0;d<o.length;d++)(d==o.length-1||o[d].head.line<o[d+1].head.line)&&t.indentLine(o[d].head.line)}function a(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,o=e.length;n<o;++n)if(e[n]==t)return n;return-1}function r(t,n,o,a,r){if(!e.scanForClosingTag)return!1;var i=Math.min(t.lastLine()+1,o.line+500),s=e.scanForClosingTag(t,o,null,i);if(!s||s.tag!=n)return!1;for(var l=a.context,d=r?1:0;l&&l.tagName==n;l=l.prev)++d;o=s.to;for(var c=1;c<d;c++){var f=e.scanForClosingTag(t,o,null,i);if(!f||f.tag!=n)return!1;o=f.to}return!0}e.commands.closeTag=function(e){return o(e)}});