1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-15 22:34:51 +00:00
TiddlyWiki5/plugins/tiddlywiki/codemirror-keymap-emacs/files/keymap/emacs.js

3 lines
7.2 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: http://codemirror.net/LICENSE
!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../lib/codemirror")):"function"==typeof define&&define.amd?define(["../lib/codemirror"],t):t(CodeMirror)}(function(t){"use strict";var e=t.Pos;function n(t,e){return t.line==e.line&&t.ch==e.ch}var r=[];function o(t){r.push(t),r.length>50&&r.shift()}function i(t){return r[r.length-(t?Math.min(t,1):1)]||""}var l=null;function a(t,e,i,a,c){null==c&&(c=t.getRange(e,i)),"grow"==a&&l&&l.cm==t&&n(e,l.pos)&&t.isClean(l.gen)?function(t){if(!r.length)return o(t);r[r.length-1]+=t}(c):!1!==a&&o(c),t.replaceRange("",e,i,"+delete"),l="grow"==a?{cm:t,pos:e,gen:t.changeGeneration()}:null}function c(t,e,n){return t.findPosH(e,n,"char",!0)}function u(t,e,n){return t.findPosH(e,n,"word",!0)}function f(t,e,n){return t.findPosV(e,n,"line",t.doc.sel.goalColumn)}function s(t,e,n){return t.findPosV(e,n,"page",t.doc.sel.goalColumn)}function g(t,n,r){for(var o=n.line,i=t.getLine(o),l=/\S/.test(r<0?i.slice(0,n.ch):i.slice(n.ch)),a=t.firstLine(),c=t.lastLine();;){if((o+=r)<a||o>c)return t.clipPos(e(o-r,r<0?0:null));if(i=t.getLine(o),/\S/.test(i))l=!0;else if(l)return e(o,0)}}function C(t,n,r){for(var o=n.line,i=n.ch,l=t.getLine(n.line),a=!1;;){var c=l.charAt(i+(r<0?-1:0));if(c){if(a&&/[!?.]/.test(c))return e(o,i+(r>0?1:0));a||(a=/\w/.test(c)),i+=r}else{if(o==(r<0?t.firstLine():t.lastLine()))return e(o,i);if(l=t.getLine(o+r),!/\S/.test(l))return e(o,i);o+=r,i=r<0?l.length:0}}}function d(t,r,o){var i;if(t.findMatchingBracket&&(i=t.findMatchingBracket(r,{strict:!0}))&&i.match&&(i.forward?1:-1)==o)return o>0?e(i.to.line,i.to.ch+1):i.to;for(var l=!0;;l=!1){var a=t.getTokenAt(r),c=e(r.line,o<0?a.start:a.end);if(!(l&&o>0&&a.end==r.ch)&&/\w/.test(a.string))return c;var u=t.findPosH(c,o,"char");if(n(c,u))return r;r=u}}function p(t,e){var n=t.state.emacsPrefix;return n?(L(t),"-"==n?-1:Number(n)):e?null:1}function h(t){var e="string"==typeof t?function(e){e.execCommand(t)}:t;return function(t){var n=p(t);e(t);for(var r=1;r<n;++r)e(t)}}function v(t,e,r,o){var i=p(t);i<0&&(o=-o,i=-i);for(var l=0;l<i;++l){var a=r(t,e,o);if(n(a,e))break;e=a}return e}function m(t,e){var n=function(n){n.extendSelection(v(n,n.getCursor(),t,e))};return n.motion=!0,n}function A(t,e,n,r){for(var o,i=t.listSelections(),l=i.length;l--;)a(t,o=i[l].head,v(t,o,e,n),r)}function S(t,e){if(t.somethingSelected()){for(var n,r=t.listSelections(),o=r.length;o--;)a(t,(n=r[o]).anchor,n.head,e);return!0}}function P(t,e){t.state.emacsPrefix?"-"!=e&&(t.state.emacsPrefix+=e):(t.state.emacsPrefix=e,t.on("keyHandled",x),t.on("inputRead",R))}var w={"Alt-G":!0,"Ctrl-X":!0,"Ctrl-Q":!0,"Ctrl-U":!0};function x(t,e){t.state.emacsPrefixMap||w.hasOwnProperty(e)||L(t)}function L(t){t.state.emacsPrefix=null,t.off("keyHandled",x),t.off("inputRead",R)}function R(t,e){var n=p(t);if(n>1&&"+input"==e.origin){for(var r=e.text.join("\n"),o="",i=1;i<n;++i)o+=r;t.replaceSelection(o)}}function y(t,e){("string"!=typeof e||!/^\d$/.test(e)&&"Ctrl-U"!=e)&&(t.removeKeyMap(D),t.state.emacsPrefixMap=!1,t.off("keyHandled",y),t.off("inputRead",y))}function k(t){t.setCursor(t.getCursor()),t.setExtending(!t.getExtending()),t.on("change",function(){t.setExtending(!1)})}function b(t){t.setExtending(!1),t.setCursor(t.getCursor())}function U(t,e){var n=t.getCursor(),r=t.findPosH(n,1,"word");t.replaceRange(e(t.getRange(n,r)),n,r),t.setCursor(r)}t.emacs={kill:a,killRegion:S,repeated:h};var X=t.keyMap.emacs=t.normalizeKeyMap({"Ctrl-W":function(t){a(t,t.getCursor("start"),t.getCursor("end"),!0)},"Ctrl-K":h(function(t){var n=t.getCursor(),r=t.clipPos(e(n.line)),o=t.getRange(n,r);/\S/.test(o)||(o+="\n",r=e(n.line+1,0)),a(t,n,r,"grow",o)}),"Alt-W":function(t){o(t.getSelection()),b(t)},"Ctrl-Y":function(t){var e=t.getCursor();t.replaceRange(i(p(t)),e,e,"paste"),t.setSelection(e,t.getCursor())},"Alt-Y":function(t){t.replaceSelection((r.length>1&&r.pop(),i()),"around","paste")},"Ctrl-Space":k,"Ctrl-Shift-2":k,"Ctrl-F":m(c,1),"Ctrl-B":m(c,-1),Right:m(c,1),Left:m(c,-1),"Ctrl-D":function(t){A(t,c,1,!1)},Delete:function(t){S(t,!1)||A(t,c,1,!1)},"Ctrl-H":function(t){A(t,c,-1,!1)},