1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-08-19 06:06:17 +00:00
TiddlyWiki5/plugins/tiddlywiki/codemirror-closetag/files/addon/edit/closetag.js

4 lines
3.5 KiB
JavaScript
Raw Normal View History

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 16:34:50 +00:00
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://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(y){y.defineOption("autoCloseTags",!1,function(e,t,n){var o;n!=y.Init&&n&&e.removeKeyMap("autoCloseTags"),t&&(o={name:"autoCloseTags"},"object"==typeof t&&!1===t.whenClosing||(o["'/'"]=function(e){return(t=e).getOption("disableInput")?y.Pass:r(t,!0);var t}),"object"==typeof t&&!1===t.whenOpening||(o["'>'"]=function(e){if(e.getOption("disableInput"))return y.Pass;for(var t=e.listSelections(),n=[],o=e.getOption("autoCloseTags"),r=0;r<t.length;r++){if(!t[r].empty())return y.Pass;var a=t[r].head,i=e.getTokenAt(a),l=y.innerMode(e.getMode(),i.state),s=l.state,d=l.mode.xmlCurrentTag&&l.mode.xmlCurrentTag(s),c=d&&d.name;if(!c)return y.Pass;var f="html"==l.mode.configuration,g="object"==typeof o&&o.dontCloseTags||f&&x,u="object"==typeof o&&o.indentTags||f&&P;i.end>a.ch&&(c=c.slice(0,c.length-i.end+a.ch));var m=c.toLowerCase();if(!c||"string"==i.type&&(i.end!=a.ch||!/[\"\']/.test(i.string.charAt(i.string.length-1))||1==i.string.length)||"tag"==i.type&&d.close||i.string.indexOf("/")==a.ch-i.start-1||g&&-1<T(g,m)||j(e,l.mode.xmlCurrentContext&&l.mode.xmlCurrentContext(s)||[],c,a,!0))return y.Pass;var h,p="object"==typeof o&&o.emptyTags;p&&-1<T(p,c)?n[r]={text:"/>",newPos:y.Pos(a.line,a.ch+2)}:(h=u&&-1<T(u,m),n[r]={indent:h,text:">"+(h?"\n\n":"")+"</"+c+">",newPos:h?y.Pos(a.line+1,0):y.Pos(a.line,a.ch+1)})}for(var C="object"==typeof o&&o.dontIndentOnAutoClose,r=t.length-1;0<=r;r--){var b=n[r];e.replaceRange(b.text,t[r].head,t[r].anchor,"+insert");var v=e.listSelections().slice(0);v[r]={head:b.newPos,anchor:b.newPos},e.setSelections(v),!C&&b.indent&&(e.indentLine(b.newPos.line,null,!0),e.indentLine(b.newPos.line+1,null,!0))}}),e.addKeyMap(o))});var x=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],P=["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 r(e,t){for(var n=e.listSelections(),o=[],r=t?"/":"</",a=e.getOption("autoCloseTags"),i="object"==typeof a&&a.dontIndentOnSlash,l=0;l<n.length;l++){if(!n[l].empty())return y.Pass;var s=n[l].head,d=e.getTokenAt(s),c=y.innerMode(e.getMode(),d.state),f=c.state;if(t&&("string"==d.type||"<"!=d.string.charAt(0)||d.start!=s.ch-1))return y.Pass;var g,u="xml"!=c.mode.name&&"htmlmixed"==e.getMode().name;if(u&&"javascript"==c.mode.name)g=r+"script";else if(u&&"css"==c.mode.name)g=r+"style";else{var m=c.mode.xmlCurrentContext&&c.mode.xmlCurrentContext(f);if(!m||m.length&&j(e,m,m[m.length-1],s))return y.Pass;g=r+m[m.length-1]}">"!=e.getLine(s.line).charAt(d.end)&&(g+=">"),o[l]=g}if(e.replaceSelections(o),n=e.listSelections(),!i)for(l=0;l<n.length;l++)(l==n.length-1||n[l].head.line<n[l+1].head.line)&&e.indentLine(n[l].head.line)}function T(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 j(e,t,n,o,r){if(y.scanForClosingTag){var a=Math.min(e.lastLine()+1,o.line+500),i=y.scanForClosingTag(e,o,null,a);if(i&&i.tag==n){for(var l=r?1:0,s=t.length-1;0<=s&&t[s]==n;s--)++l;o=i.to;for(s=1;s<l;s++){var d=y.scanForClosingTag(e,o,null,a);if(!d||d.tag!=n)return;o=d.to}return 1}}}y.commands.closeTag=function(e){return r(e)}});