1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-28 02:50:27 +00:00
TiddlyWiki5/plugins/tiddlywiki/codemirror-autocomplete/files/addon/hint/show-hint.js

4 lines
9.4 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(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(W){"use strict";var I="CodeMirror-hint-active";function o(t,i){this.cm=t,this.options=i,this.widget=null,this.debounce=0,this.tick=0,this.startPos=this.cm.getCursor("start"),this.startLen=this.cm.getLine(this.startPos.line).length-this.cm.getSelection().length;var e=this;t.on("cursorActivity",this.activityFunc=function(){e.cursorActivity()})}W.showHint=function(t,i,e){if(!i)return t.showHint(e);e&&e.async&&(i.async=!0);var n={hint:i};if(e)for(var o in e)n[o]=e[o];return t.showHint(n)},W.defineExtension("showHint",function(t){t=function(t,i,e){var n=t.options.hintOptions,o={};for(var s in l)o[s]=l[s];if(n)for(var s in n)void 0!==n[s]&&(o[s]=n[s]);if(e)for(var s in e)void 0!==e[s]&&(o[s]=e[s]);o.hint.resolve&&(o.hint=o.hint.resolve(t,i));return o}(this,this.getCursor("start"),t);var i=this.listSelections();if(!(1<i.length)){if(this.somethingSelected()){if(!t.hint.supportsSelection)return;for(var e=0;e<i.length;e++)if(i[e].head.line!=i[e].anchor.line)return}this.state.completionActive&&this.state.completionActive.close();var n=this.state.completionActive=new o(this,t);n.options.hint&&(W.signal(this,"startCompletion",this),n.update(!0))}}),W.defineExtension("closeHint",function(){this.state.completionActive&&this.state.completionActive.close()});var s=window.requestAnimationFrame||function(t){return setTimeout(t,1e3/60)},c=window.cancelAnimationFrame||clearTimeout;function B(t){return"string"==typeof t?t:t.text}function K(t,i){for(;i&&i!=t;){if("LI"===i.nodeName.toUpperCase()&&i.parentNode==t)return i;i=i.parentNode}}function n(o,t){this.completion=o,this.data=t,this.picked=!1;var e=this,s=o.cm,c=s.getInputField().ownerDocument,r=c.defaultView||c.parentWindow,l=this.hints=c.createElement("ul"),i=o.cm.options.theme;l.className="CodeMirror-hints "+i,this.selectedHint=t.selectedHint||0;for(var n=t.list,h=0;h<n.length;++h){var a=l.appendChild(c.createElement("li")),u=n[h],f="CodeMirror-hint"+(h!=this.selectedHint?"":" "+I);null!=u.className&&(f=u.className+" "+f),a.className=f,u.render?u.render(a,t,u):a.appendChild(c.createTextNode(u.displayText||B(u))),a.hintId=h}var p,d,m,g=o.options.container||c.body,v=s.cursorCoords(o.options.alignWithWord?t.from:null),y=v.left,w=v.bottom,H=!0,C=0,b=0;g!==c.body&&(d=(p=-1!==["absolute","relative","fixed"].indexOf(r.getComputedStyle(g).position)?g:g.offsetParent).getBoundingClientRect(),m=c.body.getBoundingClientRect(),C=d.left-m.left-p.scrollLeft,b=d.top-m.top-p.scrollTop),l.style.left=y-C+"px",l.style.top=w-b+"px";var k=r.innerWidth||Math.max(c.body.offsetWidth,c.documentElement.offsetWidth),A=r.innerHeight||Math.max(c.body.offsetHeight,c.documentElement.offsetHeight);g.appendChild(l);var x,T,S=l.getBoundingClientRect(),M=S.bottom-A,N=l.scrollHeight>l.clientHeight+1,F=s.getScrollInfo();0<M&&(x=S.bottom-S.top,0<v.top-(v.bottom-S.top)-x?(l.style.top=(w=v.top-x-b)+"px",H=!1):A<x&&(l.style.height=A-5+"px",l.style.top=(w=v.bottom-S.top-b)+"px",T=s.getCursor(),t.from.ch!=T.ch&&(v=s.cursorCoords(T),l.style.left=(y=v.left-C)+"px",S=l.getBoundingClientRect())));var E,O=S.right-k;if(0<O&&(S.right-S.left>k&&(l.style.width=k-5+"px",O-=S.right-S.left-k),l.style.left=(y=v.left-O-C)+"px"),N)for(var P=l.firstChild;P;P=P.nextSibling)P.style.paddingRight=s.display.nativeBarWidth+"px";return s.addKeyMap(this.keyMap=function(t,n){var o={Up:function(){n.moveFocus(-1)},Down:function(){n.moveFocus(1)},PageUp:function(){n.moveFocus(1-n.menuSize(),!0)},PageDown:function(){n.moveFocus(n.menuSize()-1,!0)},Home:function(){n.setFocus(0)},End:function(){n.setFocus(n.length-1)},Enter:n.pick,Tab:n.pick,Esc:n.close};/Mac/.test(navigator.platform)&&(o["Ctrl-P"]=function(){n.moveFocus(-1)},o["Ctrl-N"]=function(){n.moveFocus(1)});var i=t.options.customKeys,s=i?{}:o;function e(t,i){var e="string"!=typeof i?function(t){return i(t,n)}:o.hasOwnProperty(i)?o[i]:i;s[t]=e}if(i)for(var c in i)i.hasOwnProperty(c)&&e(c,i[c]);var r=t.options.ex