sql-jarvis 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -1
- data/LICENSE.txt +1 -1
- data/README.md +153 -52
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.svg +0 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.woff2 +0 -0
- data/app/assets/images/blazer/favicon.png +0 -0
- data/app/assets/javascripts/blazer/Chart.js +4195 -3884
- data/app/assets/javascripts/blazer/Sortable.js +1493 -1097
- data/app/assets/javascripts/blazer/ace/ace.js +21294 -4
- data/app/assets/javascripts/blazer/ace/ext-language_tools.js +1991 -3
- data/app/assets/javascripts/blazer/ace/mode-sql.js +110 -1
- data/app/assets/javascripts/blazer/ace/snippets/sql.js +40 -1
- data/app/assets/javascripts/blazer/ace/snippets/text.js +14 -1
- data/app/assets/javascripts/blazer/ace/theme-twilight.js +116 -1
- data/app/assets/javascripts/blazer/application.js +4 -3
- data/app/assets/javascripts/blazer/bootstrap.js +623 -612
- data/app/assets/javascripts/blazer/chartkick.js +1769 -1248
- data/app/assets/javascripts/blazer/daterangepicker.js +263 -115
- data/app/assets/javascripts/blazer/highlight.min.js +3 -0
- data/app/assets/javascripts/blazer/{jquery_ujs.js → jquery-ujs.js} +161 -75
- data/app/assets/javascripts/blazer/jquery.js +9506 -9450
- data/app/assets/javascripts/blazer/jquery.stickytableheaders.js +321 -259
- data/app/assets/javascripts/blazer/moment-timezone-with-data.js +1212 -0
- data/app/assets/javascripts/blazer/queries.js +1 -1
- data/app/assets/javascripts/blazer/routes.js +3 -0
- data/app/assets/javascripts/blazer/selectize.js +3828 -3604
- data/app/assets/javascripts/blazer/stupidtable.js +255 -88
- data/app/assets/javascripts/blazer/vue.js +8015 -4583
- data/app/assets/stylesheets/blazer/application.css +41 -5
- data/app/assets/stylesheets/blazer/bootstrap.css.erb +879 -325
- data/app/assets/stylesheets/blazer/daterangepicker.css +269 -0
- data/app/assets/stylesheets/blazer/selectize.default.css +26 -10
- data/app/controllers/blazer/base_controller.rb +7 -0
- data/app/controllers/blazer/checks_controller.rb +1 -1
- data/app/controllers/blazer/dashboards_controller.rb +0 -4
- data/app/controllers/blazer/queries_controller.rb +20 -12
- data/app/helpers/blazer/base_helper.rb +1 -1
- data/app/mailers/blazer/slack_notifier.rb +76 -0
- data/app/models/blazer/check.rb +9 -0
- data/app/views/blazer/_nav.html.erb +0 -1
- data/app/views/blazer/_variables.html.erb +41 -19
- data/app/views/blazer/checks/_form.html.erb +16 -8
- data/app/views/blazer/checks/edit.html.erb +2 -0
- data/app/views/blazer/checks/index.html.erb +33 -4
- data/app/views/blazer/checks/new.html.erb +2 -0
- data/app/views/blazer/dashboards/_form.html.erb +4 -4
- data/app/views/blazer/dashboards/edit.html.erb +2 -0
- data/app/views/blazer/dashboards/new.html.erb +2 -0
- data/app/views/blazer/dashboards/show.html.erb +7 -3
- data/app/views/blazer/queries/_form.html.erb +11 -6
- data/app/views/blazer/queries/docs.html.erb +131 -0
- data/app/views/blazer/queries/home.html.erb +12 -3
- data/app/views/blazer/queries/run.html.erb +36 -6
- data/app/views/blazer/queries/schema.html.erb +46 -8
- data/app/views/blazer/queries/show.html.erb +4 -4
- data/app/views/layouts/blazer/application.html.erb +3 -3
- data/config/routes.rb +5 -1
- data/lib/blazer.rb +32 -13
- data/lib/blazer/adapters/athena_adapter.rb +1 -1
- data/lib/blazer/adapters/elasticsearch_adapter.rb +14 -17
- data/lib/blazer/adapters/mongodb_adapter.rb +1 -1
- data/lib/blazer/adapters/sql_adapter.rb +7 -1
- data/lib/blazer/engine.rb +4 -0
- data/lib/blazer/result.rb +62 -29
- data/lib/blazer/run_statement_job.rb +6 -9
- data/lib/blazer/version.rb +1 -1
- data/lib/generators/blazer/templates/config.yml.tt +13 -2
- data/lib/generators/blazer/templates/install.rb.tt +1 -0
- data/lib/tasks/blazer.rake +1 -0
- metadata +33 -37
- data/.gitattributes +0 -1
- data/.github/ISSUE_TEMPLATE.md +0 -7
- data/.gitignore +0 -14
- data/Gemfile +0 -7
- data/Rakefile +0 -1
- data/app/assets/javascripts/blazer/highlight.pack.js +0 -1
- data/app/assets/javascripts/blazer/moment-timezone.js +0 -1007
- data/app/assets/stylesheets/blazer/daterangepicker-bs3.css +0 -375
- data/blazer.gemspec +0 -30
@@ -1,5 +1,1993 @@
|
|
1
|
-
ace.define("ace/snippets",["require","exports","module","ace/lib/oop","ace/lib/event_emitter","ace/lib/lang","ace/range","ace/anchor","ace/keyboard/hash_handler","ace/tokenizer","ace/lib/dom","ace/editor"],function(e,t,n){"use strict";var r=e("./lib/oop"),i=e("./lib/event_emitter").EventEmitter,s=e("./lib/lang"),o=e("./range").Range,u=e("./anchor").Anchor,a=e("./keyboard/hash_handler").HashHandler,f=e("./tokenizer").Tokenizer,l=o.comparePoints,c=function(){this.snippetMap={},this.snippetNameMap={}};(function(){r.implement(this,i),this.getTokenizer=function(){function e(e,t,n){return e=e.substr(1),/^\d+$/.test(e)&&!n.inFormatString?[{tabstopId:parseInt(e,10)}]:[{text:e}]}function t(e){return"(?:[^\\\\"+e+"]|\\\\.)"}return c.$tokenizer=new f({start:[{regex:/:/,onMatch:function(e,t,n){return n.length&&n[0].expectIf?(n[0].expectIf=!1,n[0].elseBranch=n[0],[n[0]]):":"}},{regex:/\\./,onMatch:function(e,t,n){var r=e[1];return r=="}"&&n.length?e=r:"`$\\".indexOf(r)!=-1?e=r:n.inFormatString&&(r=="n"?e="\n":r=="t"?e="\n":"ulULE".indexOf(r)!=-1&&(e={changeCase:r,local:r>"a"})),[e]}},{regex:/}/,onMatch:function(e,t,n){return[n.length?n.shift():e]}},{regex:/\$(?:\d+|\w+)/,onMatch:e},{regex:/\$\{[\dA-Z_a-z]+/,onMatch:function(t,n,r){var i=e(t.substr(1),n,r);return r.unshift(i[0]),i},next:"snippetVar"},{regex:/\n/,token:"newline",merge:!1}],snippetVar:[{regex:"\\|"+t("\\|")+"*\\|",onMatch:function(e,t,n){n[0].choices=e.slice(1,-1).split(",")},next:"start"},{regex:"/("+t("/")+"+)/(?:("+t("/")+"*)/)(\\w*):?",onMatch:function(e,t,n){var r=n[0];return r.fmtString=e,e=this.splitRegex.exec(e),r.guard=e[1],r.fmt=e[2],r.flag=e[3],""},next:"start"},{regex:"`"+t("`")+"*`",onMatch:function(e,t,n){return n[0].code=e.splice(1,-1),""},next:"start"},{regex:"\\?",onMatch:function(e,t,n){n[0]&&(n[0].expectIf=!0)},next:"start"},{regex:"([^:}\\\\]|\\\\.)*:?",token:"",next:"start"}],formatString:[{regex:"/("+t("/")+"+)/",token:"regex"},{regex:"",onMatch:function(e,t,n){n.inFormatString=!0},next:"start"}]}),c.prototype.getTokenizer=function(){return c.$tokenizer},c.$tokenizer},this.tokenizeTmSnippet=function(e,t){return this.getTokenizer().getLineTokens(e,t).tokens.map(function(e){return e.value||e})},this.$getDefaultValue=function(e,t){if(/^[A-Z]\d+$/.test(t)){var n=t.substr(1);return(this.variables[t[0]+"__"]||{})[n]}if(/^\d+$/.test(t))return(this.variables.__||{})[t];t=t.replace(/^TM_/,"");if(!e)return;var r=e.session;switch(t){case"CURRENT_WORD":var i=r.getWordRange();case"SELECTION":case"SELECTED_TEXT":return r.getTextRange(i);case"CURRENT_LINE":return r.getLine(e.getCursorPosition().row);case"PREV_LINE":return r.getLine(e.getCursorPosition().row-1);case"LINE_INDEX":return e.getCursorPosition().column;case"LINE_NUMBER":return e.getCursorPosition().row+1;case"SOFT_TABS":return r.getUseSoftTabs()?"YES":"NO";case"TAB_SIZE":return r.getTabSize();case"FILENAME":case"FILEPATH":return"";case"FULLNAME":return"Ace"}},this.variables={},this.getVariableValue=function(e,t){return this.variables.hasOwnProperty(t)?this.variables[t](e,t)||"":this.$getDefaultValue(e,t)||""},this.tmStrFormat=function(e,t,n){var r=t.flag||"",i=t.guard;i=new RegExp(i,r.replace(/[^gi]/,""));var s=this.tokenizeTmSnippet(t.fmt,"formatString"),o=this,u=e.replace(i,function(){o.variables.__=arguments;var e=o.resolveVariables(s,n),t="E";for(var r=0;r<e.length;r++){var i=e[r];if(typeof i=="object"){e[r]="";if(i.changeCase&&i.local){var u=e[r+1];u&&typeof u=="string"&&(i.changeCase=="u"?e[r]=u[0].toUpperCase():e[r]=u[0].toLowerCase(),e[r+1]=u.substr(1))}else i.changeCase&&(t=i.changeCase)}else t=="U"?e[r]=i.toUpperCase():t=="L"&&(e[r]=i.toLowerCase())}return e.join("")});return this.variables.__=null,u},this.resolveVariables=function(e,t){function o(t){var n=e.indexOf(t,r+1);n!=-1&&(r=n)}var n=[];for(var r=0;r<e.length;r++){var i=e[r];if(typeof i=="string")n.push(i);else{if(typeof i!="object")continue;if(i.skip)o(i);else{if(i.processed<r)continue;if(i.text){var s=this.getVariableValue(t,i.text);s&&i.fmtString&&(s=this.tmStrFormat(s,i)),i.processed=r,i.expectIf==null?s&&(n.push(s),o(i)):s?i.skip=i.elseBranch:o(i)}else i.tabstopId!=null?n.push(i):i.changeCase!=null&&n.push(i)}}}return n},this.insertSnippetForSelection=function(e,t){function f(e){var t=[];for(var n=0;n<e.length;n++){var r=e[n];if(typeof r=="object"){if(a[r.tabstopId])continue;var i=e.lastIndexOf(r,n-1);r=t[i]||{tabstopId:r.tabstopId}}t[n]=r}return t}var n=e.getCursorPosition(),r=e.session.getLine(n.row),i=e.session.getTabString(),s=r.match(/^\s*/)[0];n.column<s.length&&(s=s.slice(0,n.column));var o=this.tokenizeTmSnippet(t);o=this.resolveVariables(o,e),o=o.map(function(e){return e=="\n"?e+s:typeof e=="string"?e.replace(/\t/g,i):e});var u=[];o.forEach(function(e,t){if(typeof e!="object")return;var n=e.tabstopId,r=u[n];r||(r=u[n]=[],r.index=n,r.value="");if(r.indexOf(e)!==-1)return;r.push(e);var i=o.indexOf(e,t+1);if(i===-1)return;var s=o.slice(t+1,i),a=s.some(function(e){return typeof e=="object"});a&&!r.value?r.value=s:s.length&&(!r.value||typeof r.value!="string")&&(r.value=s.join(""))}),u.forEach(function(e){e.length=0});var a={};for(var l=0;l<o.length;l++){var c=o[l];if(typeof c!="object")continue;var p=c.tabstopId,d=o.indexOf(c,l+1);if(a[p]){a[p]===c&&(a[p]=null);continue}var v=u[p],m=typeof v.value=="string"?[v.value]:f(v.value);m.unshift(l+1,Math.max(0,d-l)),m.push(c),a[p]=c,o.splice.apply(o,m),v.indexOf(c)===-1&&v.push(c)}var g=0,y=0,b="";o.forEach(function(e){typeof e=="string"?(e[0]==="\n"?(y=e.length-1,g++):y+=e.length,b+=e):e.start?e.end={row:g,column:y}:e.start={row:g,column:y}});var w=e.getSelectionRange(),E=e.session.replace(w,b),S=new h(e),x=e.inVirtualSelectionMode&&e.selection.index;S.addTabstops(u,w.start,E,x)},this.insertSnippet=function(e,t){var n=this;if(e.inVirtualSelectionMode)return n.insertSnippetForSelection(e,t);e.forEachSelection(function(){n.insertSnippetForSelection(e,t)},null,{keepOrder:!0}),e.tabstopManager&&e.tabstopManager.tabNext()},this.$getScope=function(e){var t=e.session.$mode.$id||"";t=t.split("/").pop();if(t==="html"||t==="php"){t==="php"&&!e.session.$mode.inlinePhp&&(t="html");var n=e.getCursorPosition(),r=e.session.getState(n.row);typeof r=="object"&&(r=r[0]),r.substring&&(r.substring(0,3)=="js-"?t="javascript":r.substring(0,4)=="css-"?t="css":r.substring(0,4)=="php-"&&(t="php"))}return t},this.getActiveScopes=function(e){var t=this.$getScope(e),n=[t],r=this.snippetMap;return r[t]&&r[t].includeScopes&&n.push.apply(n,r[t].includeScopes),n.push("_"),n},this.expandWithTab=function(e,t){var n=this,r=e.forEachSelection(function(){return n.expandSnippetForSelection(e,t)},null,{keepOrder:!0});return r&&e.tabstopManager&&e.tabstopManager.tabNext(),r},this.expandSnippetForSelection=function(e,t){var n=e.getCursorPosition(),r=e.session.getLine(n.row),i=r.substring(0,n.column),s=r.substr(n.column),o=this.snippetMap,u;return this.getActiveScopes(e).some(function(e){var t=o[e];return t&&(u=this.findMatchingSnippet(t,i,s)),!!u},this),u?t&&t.dryRun?!0:(e.session.doc.removeInLine(n.row,n.column-u.replaceBefore.length,n.column+u.replaceAfter.length),this.variables.M__=u.matchBefore,this.variables.T__=u.matchAfter,this.insertSnippetForSelection(e,u.content),this.variables.M__=this.variables.T__=null,!0):!1},this.findMatchingSnippet=function(e,t,n){for(var r=e.length;r--;){var i=e[r];if(i.startRe&&!i.startRe.test(t))continue;if(i.endRe&&!i.endRe.test(n))continue;if(!i.startRe&&!i.endRe)continue;return i.matchBefore=i.startRe?i.startRe.exec(t):[""],i.matchAfter=i.endRe?i.endRe.exec(n):[""],i.replaceBefore=i.triggerRe?i.triggerRe.exec(t)[0]:"",i.replaceAfter=i.endTriggerRe?i.endTriggerRe.exec(n)[0]:"",i}},this.snippetMap={},this.snippetNameMap={},this.register=function(e,t){function o(e){return e&&!/^\^?\(.*\)\$?$|^\\b$/.test(e)&&(e="(?:"+e+")"),e||""}function u(e,t,n){return e=o(e),t=o(t),n?(e=t+e,e&&e[e.length-1]!="$"&&(e+="$")):(e+=t,e&&e[0]!="^"&&(e="^"+e)),new RegExp(e)}function a(e){e.scope||(e.scope=t||"_"),t=e.scope,n[t]||(n[t]=[],r[t]={});var o=r[t];if(e.name){var a=o[e.name];a&&i.unregister(a),o[e.name]=e}n[t].push(e),e.tabTrigger&&!e.trigger&&(!e.guard&&/^\w/.test(e.tabTrigger)&&(e.guard="\\b"),e.trigger=s.escapeRegExp(e.tabTrigger)),e.startRe=u(e.trigger,e.guard,!0),e.triggerRe=new RegExp(e.trigger,"",!0),e.endRe=u(e.endTrigger,e.endGuard,!0),e.endTriggerRe=new RegExp(e.endTrigger,"",!0)}var n=this.snippetMap,r=this.snippetNameMap,i=this;e||(e=[]),e&&e.content?a(e):Array.isArray(e)&&e.forEach(a),this._signal("registerSnippets",{scope:t})},this.unregister=function(e,t){function i(e){var i=r[e.scope||t];if(i&&i[e.name]){delete i[e.name];var s=n[e.scope||t],o=s&&s.indexOf(e);o>=0&&s.splice(o,1)}}var n=this.snippetMap,r=this.snippetNameMap;e.content?i(e):Array.isArray(e)&&e.forEach(i)},this.parseSnippetFile=function(e){e=e.replace(/\r/g,"");var t=[],n={},r=/^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm,i;while(i=r.exec(e)){if(i[1])try{n=JSON.parse(i[1]),t.push(n)}catch(s){}if(i[4])n.content=i[4].replace(/^\t/gm,""),t.push(n),n={};else{var o=i[2],u=i[3];if(o=="regex"){var a=/\/((?:[^\/\\]|\\.)*)|$/g;n.guard=a.exec(u)[1],n.trigger=a.exec(u)[1],n.endTrigger=a.exec(u)[1],n.endGuard=a.exec(u)[1]}else o=="snippet"?(n.tabTrigger=u.match(/^\S*/)[0],n.name||(n.name=u)):n[o]=u}}return t},this.getSnippetByName=function(e,t){var n=this.snippetNameMap,r;return this.getActiveScopes(t).some(function(t){var i=n[t];return i&&(r=i[e]),!!r},this),r}}).call(c.prototype);var h=function(e){if(e.tabstopManager)return e.tabstopManager;e.tabstopManager=this,this.$onChange=this.onChange.bind(this),this.$onChangeSelection=s.delayedCall(this.onChangeSelection.bind(this)).schedule,this.$onChangeSession=this.onChangeSession.bind(this),this.$onAfterExec=this.onAfterExec.bind(this),this.attach(e)};(function(){this.attach=function(e){this.index=0,this.ranges=[],this.tabstops=[],this.$openTabstops=null,this.selectedTabstop=null,this.editor=e,this.editor.on("change",this.$onChange),this.editor.on("changeSelection",this.$onChangeSelection),this.editor.on("changeSession",this.$onChangeSession),this.editor.commands.on("afterExec",this.$onAfterExec),this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler)},this.detach=function(){this.tabstops.forEach(this.removeTabstopMarkers,this),this.ranges=null,this.tabstops=null,this.selectedTabstop=null,this.editor.removeListener("change",this.$onChange),this.editor.removeListener("changeSelection",this.$onChangeSelection),this.editor.removeListener("changeSession",this.$onChangeSession),this.editor.commands.removeListener("afterExec",this.$onAfterExec),this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler),this.editor.tabstopManager=null,this.editor=null},this.onChange=function(e){var t=e.data.range,n=e.data.action[0]=="r",r=t.start,i=t.end,s=r.row,o=i.row,u=o-s,a=i.column-r.column;n&&(u=-u,a=-a);if(!this.$inChange&&n){var f=this.selectedTabstop,c=f&&!f.some(function(e){return l(e.start,r)<=0&&l(e.end,i)>=0});if(c)return this.detach()}var h=this.ranges;for(var p=0;p<h.length;p++){var d=h[p];if(d.end.row<r.row)continue;if(n&&l(r,d.start)<0&&l(i,d.end)>0){this.removeRange(d),p--;continue}d.start.row==s&&d.start.column>r.column&&(d.start.column+=a),d.end.row==s&&d.end.column>=r.column&&(d.end.column+=a),d.start.row>=s&&(d.start.row+=u),d.end.row>=s&&(d.end.row+=u),l(d.start,d.end)>0&&this.removeRange(d)}h.length||this.detach()},this.updateLinkedFields=function(){var e=this.selectedTabstop;if(!e||!e.hasLinkedRanges)return;this.$inChange=!0;var n=this.editor.session,r=n.getTextRange(e.firstNonLinked);for(var i=e.length;i--;){var s=e[i];if(!s.linked)continue;var o=t.snippetManager.tmStrFormat(r,s.original);n.replace(s,o)}this.$inChange=!1},this.onAfterExec=function(e){e.command&&!e.command.readOnly&&this.updateLinkedFields()},this.onChangeSelection=function(){if(!this.editor)return;var e=this.editor.selection.lead,t=this.editor.selection.anchor,n=this.editor.selection.isEmpty();for(var r=this.ranges.length;r--;){if(this.ranges[r].linked)continue;var i=this.ranges[r].contains(e.row,e.column),s=n||this.ranges[r].contains(t.row,t.column);if(i&&s)return}this.detach()},this.onChangeSession=function(){this.detach()},this.tabNext=function(e){var t=this.tabstops.length,n=this.index+(e||1);n=Math.min(Math.max(n,1),t),n==t&&(n=0),this.selectTabstop(n),n===0&&this.detach()},this.selectTabstop=function(e){this.$openTabstops=null;var t=this.tabstops[this.index];t&&this.addTabstopMarkers(t),this.index=e,t=this.tabstops[this.index];if(!t||!t.length)return;this.selectedTabstop=t;if(!this.editor.inVirtualSelectionMode){var n=this.editor.multiSelect;n.toSingleRange(t.firstNonLinked.clone());for(var r=t.length;r--;){if(t.hasLinkedRanges&&t[r].linked)continue;n.addRange(t[r].clone(),!0)}n.ranges[0]&&n.addRange(n.ranges[0].clone())}else this.editor.selection.setRange(t.firstNonLinked);this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler)},this.addTabstops=function(e,t,n){this.$openTabstops||(this.$openTabstops=[]);if(!e[0]){var r=o.fromPoints(n,n);v(r.start,t),v(r.end,t),e[0]=[r],e[0].index=0}var i=this.index,s=[i+1,0],u=this.ranges;e.forEach(function(e,n){var r=this.$openTabstops[n]||e;for(var i=e.length;i--;){var a=e[i],f=o.fromPoints(a.start,a.end||a.start);d(f.start,t),d(f.end,t),f.original=a,f.tabstop=r,u.push(f),r!=e?r.unshift(f):r[i]=f,a.fmtString?(f.linked=!0,r.hasLinkedRanges=!0):r.firstNonLinked||(r.firstNonLinked=f)}r.firstNonLinked||(r.hasLinkedRanges=!1),r===e&&(s.push(r),this.$openTabstops[n]=r),this.addTabstopMarkers(r)},this),s.length>2&&(this.tabstops.length&&s.push(s.splice(2,1)[0]),this.tabstops.splice.apply(this.tabstops,s))},this.addTabstopMarkers=function(e){var t=this.editor.session;e.forEach(function(e){e.markerId||(e.markerId=t.addMarker(e,"ace_snippet-marker","text"))})},this.removeTabstopMarkers=function(e){var t=this.editor.session;e.forEach(function(e){t.removeMarker(e.markerId),e.markerId=null})},this.removeRange=function(e){var t=e.tabstop.indexOf(e);e.tabstop.splice(t,1),t=this.ranges.indexOf(e),this.ranges.splice(t,1),this.editor.session.removeMarker(e.markerId),e.tabstop.length||(t=this.tabstops.indexOf(e.tabstop),t!=-1&&this.tabstops.splice(t,1),this.tabstops.length||this.detach())},this.keyboardHandler=new a,this.keyboardHandler.bindKeys({Tab:function(e){if(t.snippetManager&&t.snippetManager.expandWithTab(e))return;e.tabstopManager.tabNext(1)},"Shift-Tab":function(e){e.tabstopManager.tabNext(-1)},Esc:function(e){e.tabstopManager.detach()},Return:function(e){return!1}})}).call(h.prototype);var p={};p.onChange=u.prototype.onChange,p.setPosition=function(e,t){this.pos.row=e,this.pos.column=t},p.update=function(e,t,n){this.$insertRight=n,this.pos=e,this.onChange(t)};var d=function(e,t){e.row==0&&(e.column+=t.column),e.row+=t.row},v=function(e,t){e.row==t.row&&(e.column-=t.column),e.row-=t.row};e("./lib/dom").importCssString(".ace_snippet-marker { -moz-box-sizing: border-box; box-sizing: border-box; background: rgba(194, 193, 208, 0.09); border: 1px dotted rgba(211, 208, 235, 0.62); position: absolute;}"),t.snippetManager=new c;var m=e("./editor").Editor;(function(){this.insertSnippet=function(e,n){return t.snippetManager.insertSnippet(this,e,n)},this.expandSnippet=function(e){return t.snippetManager.expandWithTab(this,e)}}).call(m.prototype)}),ace.define("ace/autocomplete/popup",["require","exports","module","ace/edit_session","ace/virtual_renderer","ace/editor","ace/range","ace/lib/event","ace/lib/lang","ace/lib/dom"],function(e,t,n){"use strict";var r=e("../edit_session").EditSession,i=e("../virtual_renderer").VirtualRenderer,s=e("../editor").Editor,o=e("../range").Range,u=e("../lib/event"),a=e("../lib/lang"),f=e("../lib/dom"),l=function(e){var t=new i(e);t.$maxLines=4;var n=new s(t);return n.setHighlightActiveLine(!1),n.setShowPrintMargin(!1),n.renderer.setShowGutter(!1),n.renderer.setHighlightGutterLine(!1),n.$mouseHandler.$focusWaitTimout=0,n.$highlightTagPending=!0,n},c=function(e){var t=f.createElement("div"),n=new l(t);e&&e.appendChild(t),t.style.display="none",n.renderer.content.style.cursor="default",n.renderer.setStyle("ace_autocomplete"),n.setOption("displayIndentGuides",!1),n.setOption("dragDelay",150);var r=function(){};n.focus=r,n.$isFocused=!0,n.renderer.$cursorLayer.restartTimer=r,n.renderer.$cursorLayer.element.style.opacity=0,n.renderer.$maxLines=8,n.renderer.$keepTextAreaAtCursor=!1,n.setHighlightActiveLine(!1),n.session.highlight(""),n.session.$searchHighlight.clazz="ace_highlight-marker",n.on("mousedown",function(e){var t=e.getDocumentPosition();n.selection.moveToPosition(t),c.start.row=c.end.row=t.row,e.stop()});var i,s=new o(-1,0,-1,Infinity),c=new o(-1,0,-1,Infinity);c.id=n.session.addMarker(c,"ace_active-line","fullLine"),n.setSelectOnHover=function(e){e?s.id&&(n.session.removeMarker(s.id),s.id=null):s.id=n.session.addMarker(s,"ace_line-hover","fullLine")},n.setSelectOnHover(!1),n.on("mousemove",function(e){if(!i){i=e;return}if(i.x==e.x&&i.y==e.y)return;i=e,i.scrollTop=n.renderer.scrollTop;var t=i.getDocumentPosition().row;s.start.row!=t&&(s.id||n.setRow(t),p(t))}),n.renderer.on("beforeRender",function(){if(i&&s.start.row!=-1){i.$pos=null;var e=i.getDocumentPosition().row;s.id||n.setRow(e),p(e,!0)}}),n.renderer.on("afterRender",function(){var e=n.getRow(),t=n.renderer.$textLayer,r=t.element.childNodes[e-t.config.firstRow];if(r==t.selectedNode)return;t.selectedNode&&f.removeCssClass(t.selectedNode,"ace_selected"),t.selectedNode=r,r&&f.addCssClass(r,"ace_selected")});var h=function(){p(-1)},p=function(e,t){e!==s.start.row&&(s.start.row=s.end.row=e,t||n.session._emit("changeBackMarker"),n._emit("changeHoverMarker"))};n.getHoveredRow=function(){return s.start.row},u.addListener(n.container,"mouseout",h),n.on("hide",h),n.on("changeSelection",h),n.session.doc.getLength=function(){return n.data.length},n.session.doc.getLine=function(e){var t=n.data[e];return typeof t=="string"?t:t&&t.value||""};var d=n.session.bgTokenizer;return d.$tokenizeRow=function(e){var t=n.data[e],r=[];if(!t)return r;typeof t=="string"&&(t={value:t}),t.caption||(t.caption=t.value||t.name);var i=-1,s,o;for(var u=0;u<t.caption.length;u++)o=t.caption[u],s=t.matchMask&1<<u?1:0,i!==s?(r.push({type:t.className||""+(s?"completion-highlight":""),value:o}),i=s):r[r.length-1].value+=o;if(t.meta){var a=n.renderer.$size.scrollerWidth/n.renderer.layerConfig.characterWidth;t.meta.length+t.caption.length<a-2&&r.push({type:"rightAlignedText",value:t.meta})}return r},d.$updateOnChange=r,d.start=r,n.session.$computeWidth=function(){return this.screenWidth=0},n.isOpen=!1,n.isTopdown=!1,n.data=[],n.setData=function(e){n.data=e||[],n.setValue(a.stringRepeat("\n",e.length),-1),n.setRow(0)},n.getData=function(e){return n.data[e]},n.getRow=function(){return c.start.row},n.setRow=function(e){e=Math.max(-1,Math.min(this.data.length,e)),c.start.row!=e&&(n.selection.clearSelection(),c.start.row=c.end.row=e||0,n.session._emit("changeBackMarker"),n.moveCursorTo(e||0,0),n.isOpen&&n._signal("select"))},n.on("changeSelection",function(){n.isOpen&&n.setRow(n.selection.lead.row)}),n.hide=function(){this.container.style.display="none",this._signal("hide"),n.isOpen=!1},n.show=function(e,t,r){var s=this.container,o=window.innerHeight,u=window.innerWidth,a=this.renderer,f=a.$maxLines*t*1.4,l=e.top+this.$borderSize;l+f>o-t&&!r?(s.style.top="",s.style.bottom=o-l+"px",n.isTopdown=!1):(l+=t,s.style.top=l+"px",s.style.bottom="",n.isTopdown=!0),s.style.display="",this.renderer.$textLayer.checkForSizeChanges();var c=e.left;c+s.offsetWidth>u&&(c=u-s.offsetWidth),s.style.left=c+"px",this._signal("show"),i=null,n.isOpen=!0},n.getTextLeftOffset=function(){return this.$borderSize+this.renderer.$padding+this.$imageSize},n.$imageSize=0,n.$borderSize=1,n};f.importCssString(".ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line { background-color: #CAD6FA; z-index: 1;}.ace_editor.ace_autocomplete .ace_line-hover { border: 1px solid #abbffe; margin-top: -1px; background: rgba(233,233,253,0.4);}.ace_editor.ace_autocomplete .ace_line-hover { position: absolute; z-index: 2;}.ace_editor.ace_autocomplete .ace_scroller { background: none; border: none; box-shadow: none;}.ace_rightAlignedText { color: gray; display: inline-block; position: absolute; right: 4px; text-align: right; z-index: -1;}.ace_editor.ace_autocomplete .ace_completion-highlight{ color: #000; text-shadow: 0 0 0.01em;}.ace_editor.ace_autocomplete { width: 280px; z-index: 200000; background: #fbfbfb; color: #444; border: 1px lightgray solid; position: fixed; box-shadow: 2px 3px 5px rgba(0,0,0,.2); line-height: 1.4;}"),t.AcePopup=c}),ace.define("ace/autocomplete/util",["require","exports","module"],function(e,t,n){"use strict";t.parForEach=function(e,t,n){var r=0,i=e.length;i===0&&n();for(var s=0;s<i;s++)t(e[s],function(e,t){r++,r===i&&n(e,t)})};var r=/[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/;t.retrievePrecedingIdentifier=function(e,t,n){n=n||r;var i=[];for(var s=t-1;s>=0;s--){if(!n.test(e[s]))break;i.push(e[s])}return i.reverse().join("")},t.retrieveFollowingIdentifier=function(e,t,n){n=n||r;var i=[];for(var s=t;s<e.length;s++){if(!n.test(e[s]))break;i.push(e[s])}return i}}),ace.define("ace/autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/popup","ace/autocomplete/util","ace/lib/event","ace/lib/lang","ace/snippets"],function(e,t,n){"use strict";var r=e("./keyboard/hash_handler").HashHandler,i=e("./autocomplete/popup").AcePopup,s=e("./autocomplete/util"),o=e("./lib/event"),u=e("./lib/lang"),a=e("./snippets").snippetManager,f=function(){this.autoInsert=!0,this.autoSelect=!0,this.keyboardHandler=new r,this.keyboardHandler.bindKeys(this.commands),this.blurListener=this.blurListener.bind(this),this.changeListener=this.changeListener.bind(this),this.mousedownListener=this.mousedownListener.bind(this),this.mousewheelListener=this.mousewheelListener.bind(this),this.changeTimer=u.delayedCall(function(){this.updateCompletions(!0)}.bind(this))};(function(){this.gatherCompletionsId=0,this.$init=function(){this.popup=new i(document.body||document.documentElement),this.popup.on("click",function(e){this.insertMatch(),e.stop()}.bind(this)),this.popup.focus=this.editor.focus.bind(this.editor)},this.openPopup=function(e,t,n){this.popup||this.$init(),this.popup.setData(this.completions.filtered);var r=e.renderer;this.popup.setRow(this.autoSelect?0:-1);if(!n){this.popup.setTheme(e.getTheme()),this.popup.setFontSize(e.getFontSize());var i=r.layerConfig.lineHeight,s=r.$cursorLayer.getPixelPosition(this.base,!0);s.left-=this.popup.getTextLeftOffset();var o=e.container.getBoundingClientRect();s.top+=o.top-r.layerConfig.offset,s.left+=o.left-e.renderer.scrollLeft,s.left+=r.$gutterLayer.gutterWidth,this.popup.show(s,i)}},this.detach=function(){this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler),this.editor.off("changeSelection",this.changeListener),this.editor.off("blur",this.blurListener),this.editor.off("mousedown",this.mousedownListener),this.editor.off("mousewheel",this.mousewheelListener),this.changeTimer.cancel(),this.popup&&this.popup.isOpen&&(this.gatherCompletionsId+=1,this.popup.hide()),this.base&&this.base.detach(),this.activated=!1,this.completions=this.base=null},this.changeListener=function(e){var t=this.editor.selection.lead;(t.row!=this.base.row||t.column<this.base.column)&&this.detach(),this.activated?this.changeTimer.schedule():this.detach()},this.blurListener=function(){var e=document.activeElement;e!=this.editor.textInput.getElement()&&e.parentNode!=this.popup.container&&this.detach()},this.mousedownListener=function(e){this.detach()},this.mousewheelListener=function(e){this.detach()},this.goTo=function(e){var t=this.popup.getRow(),n=this.popup.session.getLength()-1;switch(e){case"up":t=t<=0?n:t-1;break;case"down":t=t>=n?-1:t+1;break;case"start":t=0;break;case"end":t=n}this.popup.setRow(t)},this.insertMatch=function(e){e||(e=this.popup.getData(this.popup.getRow()));if(!e)return!1;if(e.completer&&e.completer.insertMatch)e.completer.insertMatch(this.editor);else{if(this.completions.filterText){var t=this.editor.selection.getAllRanges();for(var n=0,r;r=t[n];n++)r.start.column-=this.completions.filterText.length,this.editor.session.remove(r)}e.snippet?a.insertSnippet(this.editor,e.snippet):this.editor.execCommand("insertstring",e.value||e)}this.detach()},this.commands={Up:function(e){e.completer.goTo("up")},Down:function(e){e.completer.goTo("down")},"Ctrl-Up|Ctrl-Home":function(e){e.completer.goTo("start")},"Ctrl-Down|Ctrl-End":function(e){e.completer.goTo("end")},Esc:function(e){e.completer.detach()},Space:function(e){e.completer.detach(),e.insert(" ")},Return:function(e){return e.completer.insertMatch()},"Shift-Return":function(e){e.completer.insertMatch(!0)},Tab:function(e){var t=e.completer.insertMatch();if(!!t||!!e.tabstopManager)return t;e.completer.goTo("down")},PageUp:function(e){e.completer.popup.gotoPageUp()},PageDown:function(e){e.completer.popup.gotoPageDown()}},this.gatherCompletions=function(e,t){var n=e.getSession(),r=e.getCursorPosition(),i=n.getLine(r.row),o=s.retrievePrecedingIdentifier(i,r.column);this.base=n.doc.createAnchor(r.row,r.column-o.length);var u=[],a=e.completers.length;return e.completers.forEach(function(i,f){i.getCompletions(e,n,r,o,function(r,i){r||(u=u.concat(i));var o=e.getCursorPosition(),f=n.getLine(o.row);t(null,{prefix:s.retrievePrecedingIdentifier(f,o.column,i[0]&&i[0].identifierRegex),matches:u,finished:--a===0})})}),!0},this.showPopup=function(e){this.editor&&this.detach(),this.activated=!0,this.editor=e,e.completer!=this&&(e.completer&&e.completer.detach(),e.completer=this),e.keyBinding.addKeyboardHandler(this.keyboardHandler),e.on("changeSelection",this.changeListener),e.on("blur",this.blurListener),e.on("mousedown",this.mousedownListener),e.on("mousewheel",this.mousewheelListener),this.updateCompletions()},this.updateCompletions=function(e){if(e&&this.base&&this.completions){var t=this.editor.getCursorPosition(),n=this.editor.session.getTextRange({start:this.base,end:t});if(n==this.completions.filterText)return;this.completions.setFilter(n);if(!this.completions.filtered.length)return this.detach();if(this.completions.filtered.length==1&&this.completions.filtered[0].value==n&&!this.completions.filtered[0].snippet)return this.detach();this.openPopup(this.editor,n,e);return}var r=this.gatherCompletionsId;this.gatherCompletions(this.editor,function(t,n){var i=function(){if(!n.finished)return;return this.detach()}.bind(this),s=n.prefix,o=n&&n.matches;if(!o||!o.length)return i();if(s.indexOf(n.prefix)!==0||r!=this.gatherCompletionsId)return;this.completions=new l(o),this.completions.setFilter(s);var u=this.completions.filtered;if(!u.length)return i();if(u.length==1&&u[0].value==s&&!u[0].snippet)return i();if(this.autoInsert&&u.length==1)return this.insertMatch(u[0]);this.openPopup(this.editor,s,e)}.bind(this))},this.cancelContextMenu=function(){this.editor.$mouseHandler.cancelContextMenu()}}).call(f.prototype),f.startCommand={name:"startAutocomplete",exec:function(e){e.completer||(e.completer=new f),e.completer.autoInsert=e.completer.autoSelect=!0,e.completer.showPopup(e),e.completer.cancelContextMenu()},bindKey:"Ctrl-Space|Ctrl-Shift-Space|Alt-Space"};var l=function(e,t,n){this.all=e,this.filtered=e,this.filterText=t||""};(function(){this.setFilter=function(e){if(e.length>this.filterText&&e.lastIndexOf(this.filterText,0)===0)var t=this.filtered;else var t=this.all;this.filterText=e,t=this.filterCompletions(t,this.filterText),t=t.sort(function(e,t){return t.exactMatch-e.exactMatch||t.score-e.score});var n=null;t=t.filter(function(e){var t=e.value||e.caption||e.snippet;return t===n?!1:(n=t,!0)}),this.filtered=t},this.filterCompletions=function(e,t){var n=[],r=t.toUpperCase(),i=t.toLowerCase();e:for(var s=0,o;o=e[s];s++){var u=o.value||o.caption||o.snippet;if(!u)continue;var a=-1,f=0,l=0,c,h;for(var p=0;p<t.length;p++){var d=u.indexOf(i[p],a+1),v=u.indexOf(r[p],a+1);c=d>=0?v<0||d<v?d:v:v;if(c<0)continue e;h=c-a-1,h>0&&(a===-1&&(l+=10),l+=h),f|=1<<c,a=c}o.matchMask=f,o.exactMatch=l?0:1,o.score=(o.score||0)-l,n.push(o)}return n}}).call(l.prototype),t.Autocomplete=f,t.FilteredList=l}),ace.define("ace/autocomplete/text_completer",["require","exports","module","ace/range"],function(e,t,n){function s(e,t){var n=e.getTextRange(r.fromPoints({row:0,column:0},t));return n.split(i).length-1}function o(e,t){var n=s(e,t),r=e.getValue().split(i),o=Object.create(null),u=r[n];return r.forEach(function(e,t){if(!e||e===u)return;var i=Math.abs(n-t),s=r.length-i;o[e]?o[e]=Math.max(s,o[e]):o[e]=s}),o}var r=e("../range").Range,i=/[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;t.getCompletions=function(e,t,n,r,i){var s=o(t,n,r),u=Object.keys(s);i(null,u.map(function(e){return{caption:e,value:e,score:s[e],meta:"local"}}))}}),ace.define("ace/ext/language_tools",["require","exports","module","ace/snippets","ace/autocomplete","ace/config","ace/autocomplete/util","ace/autocomplete/text_completer","ace/editor","ace/config"],function(e,t,n){"use strict";function v(e){var t=e.getCursorPosition(),n=e.session.getLine(t.row),r=o.retrievePrecedingIdentifier(n,t.column);return e.completers.forEach(function(e){e.identifierRegexps&&e.identifierRegexps.forEach(function(e){!r&&e&&(r=o.retrievePrecedingIdentifier(n,t.column,e))})}),r}var r=e("../snippets").snippetManager,i=e("../autocomplete").Autocomplete,s=e("../config"),o=e("../autocomplete/util"),u=e("../autocomplete/text_completer"),a={getCompletions:function(e,t,n,r,i){var s=e.session.getState(n.row),o=t.$mode.getCompletions(s,t,n,r);i(null,o)}},f={getCompletions:function(e,t,n,i,s){var o=r.snippetMap,u=[];r.getActiveScopes(e).forEach(function(e){var t=o[e]||[];for(var n=t.length;n--;){var r=t[n],i=r.name||r.tabTrigger;if(!i)continue;u.push({caption:i,snippet:r.content,meta:r.tabTrigger&&!r.name?r.tabTrigger+"\u21e5 ":"snippet"})}},this),s(null,u)}},l=[f,u,a];t.addCompleter=function(e){l.push(e)},t.textCompleter=u,t.keyWordCompleter=a,t.snippetCompleter=f;var c={name:"expandSnippet",exec:function(e){var t=r.expandWithTab(e);t||e.execCommand("indent")},bindKey:"Tab"},h=function(e,t){p(t.session.$mode)},p=function(e){var t=e.$id;r.files||(r.files={}),d(t),e.modes&&e.modes.forEach(p)},d=function(e){if(!e||r.files[e])return;var t=e.replace("mode","snippets");r.files[e]={},s.loadModule(t,function(t){t&&(r.files[e]=t,!t.snippets&&t.snippetText&&(t.snippets=r.parseSnippetFile(t.snippetText)),r.register(t.snippets||[],t.scope),t.includeScopes&&(r.snippetMap[t.scope].includeScopes=t.includeScopes,t.includeScopes.forEach(function(e){d("ace/mode/"+e)})))})},m=function(e){var t=e.editor,n=e.args||"",r=t.completer&&t.completer.activated;if(e.command.name==="backspace")r&&!v(t)&&t.completer.detach();else if(e.command.name==="insertstring"){var s=v(t);s&&!r&&(t.completer||(t.completer=new i),t.completer.autoSelect=!1,t.completer.autoInsert=!1,t.completer.showPopup(t))}},g=e("../editor").Editor;e("../config").defineOptions(g.prototype,"editor",{enableBasicAutocompletion:{set:function(e){e?(this.completers||(this.completers=Array.isArray(e)?e:l),this.commands.addCommand(i.startCommand)):this.commands.removeCommand(i.startCommand)},value:!1},enableLiveAutocompletion:{set:function(e){e?(this.completers||(this.completers=Array.isArray(e)?e:l),this.commands.on("afterExec",m)):this.commands.removeListener("afterExec",m)},value:!1},enableSnippets:{set:function(e){e?(this.commands.addCommand(c),this.on("changeMode",h),h(null,this)):(this.commands.removeCommand(c),this.off("changeMode",h))},value:!1}})});
|
2
|
-
|
3
|
-
|
1
|
+
define("ace/snippets",["require","exports","module","ace/lib/oop","ace/lib/event_emitter","ace/lib/lang","ace/range","ace/anchor","ace/keyboard/hash_handler","ace/tokenizer","ace/lib/dom","ace/editor"], function(require, exports, module) {
|
2
|
+
"use strict";
|
3
|
+
var oop = require("./lib/oop");
|
4
|
+
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
5
|
+
var lang = require("./lib/lang");
|
6
|
+
var Range = require("./range").Range;
|
7
|
+
var Anchor = require("./anchor").Anchor;
|
8
|
+
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
9
|
+
var Tokenizer = require("./tokenizer").Tokenizer;
|
10
|
+
var comparePoints = Range.comparePoints;
|
11
|
+
|
12
|
+
var SnippetManager = function() {
|
13
|
+
this.snippetMap = {};
|
14
|
+
this.snippetNameMap = {};
|
15
|
+
};
|
16
|
+
|
17
|
+
(function() {
|
18
|
+
oop.implement(this, EventEmitter);
|
19
|
+
|
20
|
+
this.getTokenizer = function() {
|
21
|
+
function TabstopToken(str, _, stack) {
|
22
|
+
str = str.substr(1);
|
23
|
+
if (/^\d+$/.test(str) && !stack.inFormatString)
|
24
|
+
return [{tabstopId: parseInt(str, 10)}];
|
25
|
+
return [{text: str}];
|
26
|
+
}
|
27
|
+
function escape(ch) {
|
28
|
+
return "(?:[^\\\\" + ch + "]|\\\\.)";
|
29
|
+
}
|
30
|
+
SnippetManager.$tokenizer = new Tokenizer({
|
31
|
+
start: [
|
32
|
+
{regex: /:/, onMatch: function(val, state, stack) {
|
33
|
+
if (stack.length && stack[0].expectIf) {
|
34
|
+
stack[0].expectIf = false;
|
35
|
+
stack[0].elseBranch = stack[0];
|
36
|
+
return [stack[0]];
|
37
|
+
}
|
38
|
+
return ":";
|
39
|
+
}},
|
40
|
+
{regex: /\\./, onMatch: function(val, state, stack) {
|
41
|
+
var ch = val[1];
|
42
|
+
if (ch == "}" && stack.length) {
|
43
|
+
val = ch;
|
44
|
+
}else if ("`$\\".indexOf(ch) != -1) {
|
45
|
+
val = ch;
|
46
|
+
} else if (stack.inFormatString) {
|
47
|
+
if (ch == "n")
|
48
|
+
val = "\n";
|
49
|
+
else if (ch == "t")
|
50
|
+
val = "\n";
|
51
|
+
else if ("ulULE".indexOf(ch) != -1) {
|
52
|
+
val = {changeCase: ch, local: ch > "a"};
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return [val];
|
57
|
+
}},
|
58
|
+
{regex: /}/, onMatch: function(val, state, stack) {
|
59
|
+
return [stack.length ? stack.shift() : val];
|
60
|
+
}},
|
61
|
+
{regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken},
|
62
|
+
{regex: /\$\{[\dA-Z_a-z]+/, onMatch: function(str, state, stack) {
|
63
|
+
var t = TabstopToken(str.substr(1), state, stack);
|
64
|
+
stack.unshift(t[0]);
|
65
|
+
return t;
|
66
|
+
}, next: "snippetVar"},
|
67
|
+
{regex: /\n/, token: "newline", merge: false}
|
68
|
+
],
|
69
|
+
snippetVar: [
|
70
|
+
{regex: "\\|" + escape("\\|") + "*\\|", onMatch: function(val, state, stack) {
|
71
|
+
stack[0].choices = val.slice(1, -1).split(",");
|
72
|
+
}, next: "start"},
|
73
|
+
{regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
|
74
|
+
onMatch: function(val, state, stack) {
|
75
|
+
var ts = stack[0];
|
76
|
+
ts.fmtString = val;
|
77
|
+
|
78
|
+
val = this.splitRegex.exec(val);
|
79
|
+
ts.guard = val[1];
|
80
|
+
ts.fmt = val[2];
|
81
|
+
ts.flag = val[3];
|
82
|
+
return "";
|
83
|
+
}, next: "start"},
|
84
|
+
{regex: "`" + escape("`") + "*`", onMatch: function(val, state, stack) {
|
85
|
+
stack[0].code = val.splice(1, -1);
|
86
|
+
return "";
|
87
|
+
}, next: "start"},
|
88
|
+
{regex: "\\?", onMatch: function(val, state, stack) {
|
89
|
+
if (stack[0])
|
90
|
+
stack[0].expectIf = true;
|
91
|
+
}, next: "start"},
|
92
|
+
{regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start"}
|
93
|
+
],
|
94
|
+
formatString: [
|
95
|
+
{regex: "/(" + escape("/") + "+)/", token: "regex"},
|
96
|
+
{regex: "", onMatch: function(val, state, stack) {
|
97
|
+
stack.inFormatString = true;
|
98
|
+
}, next: "start"}
|
99
|
+
]
|
100
|
+
});
|
101
|
+
SnippetManager.prototype.getTokenizer = function() {
|
102
|
+
return SnippetManager.$tokenizer;
|
103
|
+
};
|
104
|
+
return SnippetManager.$tokenizer;
|
105
|
+
};
|
106
|
+
|
107
|
+
this.tokenizeTmSnippet = function(str, startState) {
|
108
|
+
return this.getTokenizer().getLineTokens(str, startState).tokens.map(function(x) {
|
109
|
+
return x.value || x;
|
110
|
+
});
|
111
|
+
};
|
112
|
+
|
113
|
+
this.$getDefaultValue = function(editor, name) {
|
114
|
+
if (/^[A-Z]\d+$/.test(name)) {
|
115
|
+
var i = name.substr(1);
|
116
|
+
return (this.variables[name[0] + "__"] || {})[i];
|
117
|
+
}
|
118
|
+
if (/^\d+$/.test(name)) {
|
119
|
+
return (this.variables.__ || {})[name];
|
120
|
+
}
|
121
|
+
name = name.replace(/^TM_/, "");
|
122
|
+
|
123
|
+
if (!editor)
|
124
|
+
return;
|
125
|
+
var s = editor.session;
|
126
|
+
switch(name) {
|
127
|
+
case "CURRENT_WORD":
|
128
|
+
var r = s.getWordRange();
|
129
|
+
case "SELECTION":
|
130
|
+
case "SELECTED_TEXT":
|
131
|
+
return s.getTextRange(r);
|
132
|
+
case "CURRENT_LINE":
|
133
|
+
return s.getLine(editor.getCursorPosition().row);
|
134
|
+
case "PREV_LINE": // not possible in textmate
|
135
|
+
return s.getLine(editor.getCursorPosition().row - 1);
|
136
|
+
case "LINE_INDEX":
|
137
|
+
return editor.getCursorPosition().column;
|
138
|
+
case "LINE_NUMBER":
|
139
|
+
return editor.getCursorPosition().row + 1;
|
140
|
+
case "SOFT_TABS":
|
141
|
+
return s.getUseSoftTabs() ? "YES" : "NO";
|
142
|
+
case "TAB_SIZE":
|
143
|
+
return s.getTabSize();
|
144
|
+
case "FILENAME":
|
145
|
+
case "FILEPATH":
|
146
|
+
return "";
|
147
|
+
case "FULLNAME":
|
148
|
+
return "Ace";
|
149
|
+
}
|
150
|
+
};
|
151
|
+
this.variables = {};
|
152
|
+
this.getVariableValue = function(editor, varName) {
|
153
|
+
if (this.variables.hasOwnProperty(varName))
|
154
|
+
return this.variables[varName](editor, varName) || "";
|
155
|
+
return this.$getDefaultValue(editor, varName) || "";
|
156
|
+
};
|
157
|
+
this.tmStrFormat = function(str, ch, editor) {
|
158
|
+
var flag = ch.flag || "";
|
159
|
+
var re = ch.guard;
|
160
|
+
re = new RegExp(re, flag.replace(/[^gi]/, ""));
|
161
|
+
var fmtTokens = this.tokenizeTmSnippet(ch.fmt, "formatString");
|
162
|
+
var _self = this;
|
163
|
+
var formatted = str.replace(re, function() {
|
164
|
+
_self.variables.__ = arguments;
|
165
|
+
var fmtParts = _self.resolveVariables(fmtTokens, editor);
|
166
|
+
var gChangeCase = "E";
|
167
|
+
for (var i = 0; i < fmtParts.length; i++) {
|
168
|
+
var ch = fmtParts[i];
|
169
|
+
if (typeof ch == "object") {
|
170
|
+
fmtParts[i] = "";
|
171
|
+
if (ch.changeCase && ch.local) {
|
172
|
+
var next = fmtParts[i + 1];
|
173
|
+
if (next && typeof next == "string") {
|
174
|
+
if (ch.changeCase == "u")
|
175
|
+
fmtParts[i] = next[0].toUpperCase();
|
176
|
+
else
|
177
|
+
fmtParts[i] = next[0].toLowerCase();
|
178
|
+
fmtParts[i + 1] = next.substr(1);
|
179
|
+
}
|
180
|
+
} else if (ch.changeCase) {
|
181
|
+
gChangeCase = ch.changeCase;
|
182
|
+
}
|
183
|
+
} else if (gChangeCase == "U") {
|
184
|
+
fmtParts[i] = ch.toUpperCase();
|
185
|
+
} else if (gChangeCase == "L") {
|
186
|
+
fmtParts[i] = ch.toLowerCase();
|
187
|
+
}
|
188
|
+
}
|
189
|
+
return fmtParts.join("");
|
190
|
+
});
|
191
|
+
this.variables.__ = null;
|
192
|
+
return formatted;
|
193
|
+
};
|
194
|
+
|
195
|
+
this.resolveVariables = function(snippet, editor) {
|
196
|
+
var result = [];
|
197
|
+
for (var i = 0; i < snippet.length; i++) {
|
198
|
+
var ch = snippet[i];
|
199
|
+
if (typeof ch == "string") {
|
200
|
+
result.push(ch);
|
201
|
+
} else if (typeof ch != "object") {
|
202
|
+
continue;
|
203
|
+
} else if (ch.skip) {
|
204
|
+
gotoNext(ch);
|
205
|
+
} else if (ch.processed < i) {
|
206
|
+
continue;
|
207
|
+
} else if (ch.text) {
|
208
|
+
var value = this.getVariableValue(editor, ch.text);
|
209
|
+
if (value && ch.fmtString)
|
210
|
+
value = this.tmStrFormat(value, ch);
|
211
|
+
ch.processed = i;
|
212
|
+
if (ch.expectIf == null) {
|
213
|
+
if (value) {
|
214
|
+
result.push(value);
|
215
|
+
gotoNext(ch);
|
216
|
+
}
|
217
|
+
} else {
|
218
|
+
if (value) {
|
219
|
+
ch.skip = ch.elseBranch;
|
220
|
+
} else
|
221
|
+
gotoNext(ch);
|
222
|
+
}
|
223
|
+
} else if (ch.tabstopId != null) {
|
224
|
+
result.push(ch);
|
225
|
+
} else if (ch.changeCase != null) {
|
226
|
+
result.push(ch);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
function gotoNext(ch) {
|
230
|
+
var i1 = snippet.indexOf(ch, i + 1);
|
231
|
+
if (i1 != -1)
|
232
|
+
i = i1;
|
233
|
+
}
|
234
|
+
return result;
|
235
|
+
};
|
236
|
+
|
237
|
+
this.insertSnippetForSelection = function(editor, snippetText) {
|
238
|
+
var cursor = editor.getCursorPosition();
|
239
|
+
var line = editor.session.getLine(cursor.row);
|
240
|
+
var tabString = editor.session.getTabString();
|
241
|
+
var indentString = line.match(/^\s*/)[0];
|
242
|
+
|
243
|
+
if (cursor.column < indentString.length)
|
244
|
+
indentString = indentString.slice(0, cursor.column);
|
245
|
+
|
246
|
+
snippetText = snippetText.replace(/\r/g, "");
|
247
|
+
var tokens = this.tokenizeTmSnippet(snippetText);
|
248
|
+
tokens = this.resolveVariables(tokens, editor);
|
249
|
+
tokens = tokens.map(function(x) {
|
250
|
+
if (x == "\n")
|
251
|
+
return x + indentString;
|
252
|
+
if (typeof x == "string")
|
253
|
+
return x.replace(/\t/g, tabString);
|
254
|
+
return x;
|
255
|
+
});
|
256
|
+
var tabstops = [];
|
257
|
+
tokens.forEach(function(p, i) {
|
258
|
+
if (typeof p != "object")
|
259
|
+
return;
|
260
|
+
var id = p.tabstopId;
|
261
|
+
var ts = tabstops[id];
|
262
|
+
if (!ts) {
|
263
|
+
ts = tabstops[id] = [];
|
264
|
+
ts.index = id;
|
265
|
+
ts.value = "";
|
266
|
+
}
|
267
|
+
if (ts.indexOf(p) !== -1)
|
268
|
+
return;
|
269
|
+
ts.push(p);
|
270
|
+
var i1 = tokens.indexOf(p, i + 1);
|
271
|
+
if (i1 === -1)
|
272
|
+
return;
|
273
|
+
|
274
|
+
var value = tokens.slice(i + 1, i1);
|
275
|
+
var isNested = value.some(function(t) {return typeof t === "object";});
|
276
|
+
if (isNested && !ts.value) {
|
277
|
+
ts.value = value;
|
278
|
+
} else if (value.length && (!ts.value || typeof ts.value !== "string")) {
|
279
|
+
ts.value = value.join("");
|
280
|
+
}
|
281
|
+
});
|
282
|
+
tabstops.forEach(function(ts) {ts.length = 0;});
|
283
|
+
var expanding = {};
|
284
|
+
function copyValue(val) {
|
285
|
+
var copy = [];
|
286
|
+
for (var i = 0; i < val.length; i++) {
|
287
|
+
var p = val[i];
|
288
|
+
if (typeof p == "object") {
|
289
|
+
if (expanding[p.tabstopId])
|
290
|
+
continue;
|
291
|
+
var j = val.lastIndexOf(p, i - 1);
|
292
|
+
p = copy[j] || {tabstopId: p.tabstopId};
|
293
|
+
}
|
294
|
+
copy[i] = p;
|
295
|
+
}
|
296
|
+
return copy;
|
297
|
+
}
|
298
|
+
for (var i = 0; i < tokens.length; i++) {
|
299
|
+
var p = tokens[i];
|
300
|
+
if (typeof p != "object")
|
301
|
+
continue;
|
302
|
+
var id = p.tabstopId;
|
303
|
+
var i1 = tokens.indexOf(p, i + 1);
|
304
|
+
if (expanding[id]) {
|
305
|
+
if (expanding[id] === p)
|
306
|
+
expanding[id] = null;
|
307
|
+
continue;
|
308
|
+
}
|
309
|
+
|
310
|
+
var ts = tabstops[id];
|
311
|
+
var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value);
|
312
|
+
arg.unshift(i + 1, Math.max(0, i1 - i));
|
313
|
+
arg.push(p);
|
314
|
+
expanding[id] = p;
|
315
|
+
tokens.splice.apply(tokens, arg);
|
316
|
+
|
317
|
+
if (ts.indexOf(p) === -1)
|
318
|
+
ts.push(p);
|
319
|
+
}
|
320
|
+
var row = 0, column = 0;
|
321
|
+
var text = "";
|
322
|
+
tokens.forEach(function(t) {
|
323
|
+
if (typeof t === "string") {
|
324
|
+
var lines = t.split("\n");
|
325
|
+
if (lines.length > 1){
|
326
|
+
column = lines[lines.length - 1].length;
|
327
|
+
row += lines.length - 1;
|
328
|
+
} else
|
329
|
+
column += t.length;
|
330
|
+
text += t;
|
331
|
+
} else {
|
332
|
+
if (!t.start)
|
333
|
+
t.start = {row: row, column: column};
|
334
|
+
else
|
335
|
+
t.end = {row: row, column: column};
|
336
|
+
}
|
337
|
+
});
|
338
|
+
var range = editor.getSelectionRange();
|
339
|
+
var end = editor.session.replace(range, text);
|
340
|
+
|
341
|
+
var tabstopManager = new TabstopManager(editor);
|
342
|
+
var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
|
343
|
+
tabstopManager.addTabstops(tabstops, range.start, end, selectionId);
|
344
|
+
};
|
345
|
+
|
346
|
+
this.insertSnippet = function(editor, snippetText) {
|
347
|
+
var self = this;
|
348
|
+
if (editor.inVirtualSelectionMode)
|
349
|
+
return self.insertSnippetForSelection(editor, snippetText);
|
350
|
+
|
351
|
+
editor.forEachSelection(function() {
|
352
|
+
self.insertSnippetForSelection(editor, snippetText);
|
353
|
+
}, null, {keepOrder: true});
|
354
|
+
|
355
|
+
if (editor.tabstopManager)
|
356
|
+
editor.tabstopManager.tabNext();
|
357
|
+
};
|
358
|
+
|
359
|
+
this.$getScope = function(editor) {
|
360
|
+
var scope = editor.session.$mode.$id || "";
|
361
|
+
scope = scope.split("/").pop();
|
362
|
+
if (scope === "html" || scope === "php") {
|
363
|
+
if (scope === "php" && !editor.session.$mode.inlinePhp)
|
364
|
+
scope = "html";
|
365
|
+
var c = editor.getCursorPosition();
|
366
|
+
var state = editor.session.getState(c.row);
|
367
|
+
if (typeof state === "object") {
|
368
|
+
state = state[0];
|
369
|
+
}
|
370
|
+
if (state.substring) {
|
371
|
+
if (state.substring(0, 3) == "js-")
|
372
|
+
scope = "javascript";
|
373
|
+
else if (state.substring(0, 4) == "css-")
|
374
|
+
scope = "css";
|
375
|
+
else if (state.substring(0, 4) == "php-")
|
376
|
+
scope = "php";
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
return scope;
|
381
|
+
};
|
382
|
+
|
383
|
+
this.getActiveScopes = function(editor) {
|
384
|
+
var scope = this.$getScope(editor);
|
385
|
+
var scopes = [scope];
|
386
|
+
var snippetMap = this.snippetMap;
|
387
|
+
if (snippetMap[scope] && snippetMap[scope].includeScopes) {
|
388
|
+
scopes.push.apply(scopes, snippetMap[scope].includeScopes);
|
389
|
+
}
|
390
|
+
scopes.push("_");
|
391
|
+
return scopes;
|
392
|
+
};
|
393
|
+
|
394
|
+
this.expandWithTab = function(editor, options) {
|
395
|
+
var self = this;
|
396
|
+
var result = editor.forEachSelection(function() {
|
397
|
+
return self.expandSnippetForSelection(editor, options);
|
398
|
+
}, null, {keepOrder: true});
|
399
|
+
if (result && editor.tabstopManager)
|
400
|
+
editor.tabstopManager.tabNext();
|
401
|
+
return result;
|
402
|
+
};
|
403
|
+
|
404
|
+
this.expandSnippetForSelection = function(editor, options) {
|
405
|
+
var cursor = editor.getCursorPosition();
|
406
|
+
var line = editor.session.getLine(cursor.row);
|
407
|
+
var before = line.substring(0, cursor.column);
|
408
|
+
var after = line.substr(cursor.column);
|
409
|
+
|
410
|
+
var snippetMap = this.snippetMap;
|
411
|
+
var snippet;
|
412
|
+
this.getActiveScopes(editor).some(function(scope) {
|
413
|
+
var snippets = snippetMap[scope];
|
414
|
+
if (snippets)
|
415
|
+
snippet = this.findMatchingSnippet(snippets, before, after);
|
416
|
+
return !!snippet;
|
417
|
+
}, this);
|
418
|
+
if (!snippet)
|
419
|
+
return false;
|
420
|
+
if (options && options.dryRun)
|
421
|
+
return true;
|
422
|
+
editor.session.doc.removeInLine(cursor.row,
|
423
|
+
cursor.column - snippet.replaceBefore.length,
|
424
|
+
cursor.column + snippet.replaceAfter.length
|
425
|
+
);
|
426
|
+
|
427
|
+
this.variables.M__ = snippet.matchBefore;
|
428
|
+
this.variables.T__ = snippet.matchAfter;
|
429
|
+
this.insertSnippetForSelection(editor, snippet.content);
|
430
|
+
|
431
|
+
this.variables.M__ = this.variables.T__ = null;
|
432
|
+
return true;
|
433
|
+
};
|
434
|
+
|
435
|
+
this.findMatchingSnippet = function(snippetList, before, after) {
|
436
|
+
for (var i = snippetList.length; i--;) {
|
437
|
+
var s = snippetList[i];
|
438
|
+
if (s.startRe && !s.startRe.test(before))
|
439
|
+
continue;
|
440
|
+
if (s.endRe && !s.endRe.test(after))
|
441
|
+
continue;
|
442
|
+
if (!s.startRe && !s.endRe)
|
443
|
+
continue;
|
444
|
+
|
445
|
+
s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
|
446
|
+
s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
|
447
|
+
s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
|
448
|
+
s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
|
449
|
+
return s;
|
450
|
+
}
|
451
|
+
};
|
452
|
+
|
453
|
+
this.snippetMap = {};
|
454
|
+
this.snippetNameMap = {};
|
455
|
+
this.register = function(snippets, scope) {
|
456
|
+
var snippetMap = this.snippetMap;
|
457
|
+
var snippetNameMap = this.snippetNameMap;
|
458
|
+
var self = this;
|
459
|
+
|
460
|
+
if (!snippets)
|
461
|
+
snippets = [];
|
462
|
+
|
463
|
+
function wrapRegexp(src) {
|
464
|
+
if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
|
465
|
+
src = "(?:" + src + ")";
|
466
|
+
|
467
|
+
return src || "";
|
468
|
+
}
|
469
|
+
function guardedRegexp(re, guard, opening) {
|
470
|
+
re = wrapRegexp(re);
|
471
|
+
guard = wrapRegexp(guard);
|
472
|
+
if (opening) {
|
473
|
+
re = guard + re;
|
474
|
+
if (re && re[re.length - 1] != "$")
|
475
|
+
re = re + "$";
|
476
|
+
} else {
|
477
|
+
re = re + guard;
|
478
|
+
if (re && re[0] != "^")
|
479
|
+
re = "^" + re;
|
480
|
+
}
|
481
|
+
return new RegExp(re);
|
482
|
+
}
|
483
|
+
|
484
|
+
function addSnippet(s) {
|
485
|
+
if (!s.scope)
|
486
|
+
s.scope = scope || "_";
|
487
|
+
scope = s.scope;
|
488
|
+
if (!snippetMap[scope]) {
|
489
|
+
snippetMap[scope] = [];
|
490
|
+
snippetNameMap[scope] = {};
|
491
|
+
}
|
492
|
+
|
493
|
+
var map = snippetNameMap[scope];
|
494
|
+
if (s.name) {
|
495
|
+
var old = map[s.name];
|
496
|
+
if (old)
|
497
|
+
self.unregister(old);
|
498
|
+
map[s.name] = s;
|
499
|
+
}
|
500
|
+
snippetMap[scope].push(s);
|
501
|
+
|
502
|
+
if (s.tabTrigger && !s.trigger) {
|
503
|
+
if (!s.guard && /^\w/.test(s.tabTrigger))
|
504
|
+
s.guard = "\\b";
|
505
|
+
s.trigger = lang.escapeRegExp(s.tabTrigger);
|
506
|
+
}
|
507
|
+
|
508
|
+
if (!s.trigger && !s.guard && !s.endTrigger && !s.endGuard)
|
509
|
+
return;
|
510
|
+
|
511
|
+
s.startRe = guardedRegexp(s.trigger, s.guard, true);
|
512
|
+
s.triggerRe = new RegExp(s.trigger);
|
513
|
+
|
514
|
+
s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
|
515
|
+
s.endTriggerRe = new RegExp(s.endTrigger);
|
516
|
+
}
|
517
|
+
|
518
|
+
if (snippets && snippets.content)
|
519
|
+
addSnippet(snippets);
|
520
|
+
else if (Array.isArray(snippets))
|
521
|
+
snippets.forEach(addSnippet);
|
522
|
+
|
523
|
+
this._signal("registerSnippets", {scope: scope});
|
524
|
+
};
|
525
|
+
this.unregister = function(snippets, scope) {
|
526
|
+
var snippetMap = this.snippetMap;
|
527
|
+
var snippetNameMap = this.snippetNameMap;
|
528
|
+
|
529
|
+
function removeSnippet(s) {
|
530
|
+
var nameMap = snippetNameMap[s.scope||scope];
|
531
|
+
if (nameMap && nameMap[s.name]) {
|
532
|
+
delete nameMap[s.name];
|
533
|
+
var map = snippetMap[s.scope||scope];
|
534
|
+
var i = map && map.indexOf(s);
|
535
|
+
if (i >= 0)
|
536
|
+
map.splice(i, 1);
|
537
|
+
}
|
538
|
+
}
|
539
|
+
if (snippets.content)
|
540
|
+
removeSnippet(snippets);
|
541
|
+
else if (Array.isArray(snippets))
|
542
|
+
snippets.forEach(removeSnippet);
|
543
|
+
};
|
544
|
+
this.parseSnippetFile = function(str) {
|
545
|
+
str = str.replace(/\r/g, "");
|
546
|
+
var list = [], snippet = {};
|
547
|
+
var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
|
548
|
+
var m;
|
549
|
+
while (m = re.exec(str)) {
|
550
|
+
if (m[1]) {
|
551
|
+
try {
|
552
|
+
snippet = JSON.parse(m[1]);
|
553
|
+
list.push(snippet);
|
554
|
+
} catch (e) {}
|
555
|
+
} if (m[4]) {
|
556
|
+
snippet.content = m[4].replace(/^\t/gm, "");
|
557
|
+
list.push(snippet);
|
558
|
+
snippet = {};
|
559
|
+
} else {
|
560
|
+
var key = m[2], val = m[3];
|
561
|
+
if (key == "regex") {
|
562
|
+
var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
|
563
|
+
snippet.guard = guardRe.exec(val)[1];
|
564
|
+
snippet.trigger = guardRe.exec(val)[1];
|
565
|
+
snippet.endTrigger = guardRe.exec(val)[1];
|
566
|
+
snippet.endGuard = guardRe.exec(val)[1];
|
567
|
+
} else if (key == "snippet") {
|
568
|
+
snippet.tabTrigger = val.match(/^\S*/)[0];
|
569
|
+
if (!snippet.name)
|
570
|
+
snippet.name = val;
|
571
|
+
} else {
|
572
|
+
snippet[key] = val;
|
573
|
+
}
|
574
|
+
}
|
575
|
+
}
|
576
|
+
return list;
|
577
|
+
};
|
578
|
+
this.getSnippetByName = function(name, editor) {
|
579
|
+
var snippetMap = this.snippetNameMap;
|
580
|
+
var snippet;
|
581
|
+
this.getActiveScopes(editor).some(function(scope) {
|
582
|
+
var snippets = snippetMap[scope];
|
583
|
+
if (snippets)
|
584
|
+
snippet = snippets[name];
|
585
|
+
return !!snippet;
|
586
|
+
}, this);
|
587
|
+
return snippet;
|
588
|
+
};
|
589
|
+
|
590
|
+
}).call(SnippetManager.prototype);
|
591
|
+
|
592
|
+
|
593
|
+
var TabstopManager = function(editor) {
|
594
|
+
if (editor.tabstopManager)
|
595
|
+
return editor.tabstopManager;
|
596
|
+
editor.tabstopManager = this;
|
597
|
+
this.$onChange = this.onChange.bind(this);
|
598
|
+
this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
|
599
|
+
this.$onChangeSession = this.onChangeSession.bind(this);
|
600
|
+
this.$onAfterExec = this.onAfterExec.bind(this);
|
601
|
+
this.attach(editor);
|
602
|
+
};
|
603
|
+
(function() {
|
604
|
+
this.attach = function(editor) {
|
605
|
+
this.index = 0;
|
606
|
+
this.ranges = [];
|
607
|
+
this.tabstops = [];
|
608
|
+
this.$openTabstops = null;
|
609
|
+
this.selectedTabstop = null;
|
610
|
+
|
611
|
+
this.editor = editor;
|
612
|
+
this.editor.on("change", this.$onChange);
|
613
|
+
this.editor.on("changeSelection", this.$onChangeSelection);
|
614
|
+
this.editor.on("changeSession", this.$onChangeSession);
|
615
|
+
this.editor.commands.on("afterExec", this.$onAfterExec);
|
616
|
+
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
617
|
+
};
|
618
|
+
this.detach = function() {
|
619
|
+
this.tabstops.forEach(this.removeTabstopMarkers, this);
|
620
|
+
this.ranges = null;
|
621
|
+
this.tabstops = null;
|
622
|
+
this.selectedTabstop = null;
|
623
|
+
this.editor.removeListener("change", this.$onChange);
|
624
|
+
this.editor.removeListener("changeSelection", this.$onChangeSelection);
|
625
|
+
this.editor.removeListener("changeSession", this.$onChangeSession);
|
626
|
+
this.editor.commands.removeListener("afterExec", this.$onAfterExec);
|
627
|
+
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
|
628
|
+
this.editor.tabstopManager = null;
|
629
|
+
this.editor = null;
|
630
|
+
};
|
631
|
+
|
632
|
+
this.onChange = function(delta) {
|
633
|
+
var changeRange = delta;
|
634
|
+
var isRemove = delta.action[0] == "r";
|
635
|
+
var start = delta.start;
|
636
|
+
var end = delta.end;
|
637
|
+
var startRow = start.row;
|
638
|
+
var endRow = end.row;
|
639
|
+
var lineDif = endRow - startRow;
|
640
|
+
var colDiff = end.column - start.column;
|
641
|
+
|
642
|
+
if (isRemove) {
|
643
|
+
lineDif = -lineDif;
|
644
|
+
colDiff = -colDiff;
|
645
|
+
}
|
646
|
+
if (!this.$inChange && isRemove) {
|
647
|
+
var ts = this.selectedTabstop;
|
648
|
+
var changedOutside = ts && !ts.some(function(r) {
|
649
|
+
return comparePoints(r.start, start) <= 0 && comparePoints(r.end, end) >= 0;
|
650
|
+
});
|
651
|
+
if (changedOutside)
|
652
|
+
return this.detach();
|
653
|
+
}
|
654
|
+
var ranges = this.ranges;
|
655
|
+
for (var i = 0; i < ranges.length; i++) {
|
656
|
+
var r = ranges[i];
|
657
|
+
if (r.end.row < start.row)
|
658
|
+
continue;
|
659
|
+
|
660
|
+
if (isRemove && comparePoints(start, r.start) < 0 && comparePoints(end, r.end) > 0) {
|
661
|
+
this.removeRange(r);
|
662
|
+
i--;
|
663
|
+
continue;
|
664
|
+
}
|
665
|
+
|
666
|
+
if (r.start.row == startRow && r.start.column > start.column)
|
667
|
+
r.start.column += colDiff;
|
668
|
+
if (r.end.row == startRow && r.end.column >= start.column)
|
669
|
+
r.end.column += colDiff;
|
670
|
+
if (r.start.row >= startRow)
|
671
|
+
r.start.row += lineDif;
|
672
|
+
if (r.end.row >= startRow)
|
673
|
+
r.end.row += lineDif;
|
674
|
+
|
675
|
+
if (comparePoints(r.start, r.end) > 0)
|
676
|
+
this.removeRange(r);
|
677
|
+
}
|
678
|
+
if (!ranges.length)
|
679
|
+
this.detach();
|
680
|
+
};
|
681
|
+
this.updateLinkedFields = function() {
|
682
|
+
var ts = this.selectedTabstop;
|
683
|
+
if (!ts || !ts.hasLinkedRanges)
|
684
|
+
return;
|
685
|
+
this.$inChange = true;
|
686
|
+
var session = this.editor.session;
|
687
|
+
var text = session.getTextRange(ts.firstNonLinked);
|
688
|
+
for (var i = ts.length; i--;) {
|
689
|
+
var range = ts[i];
|
690
|
+
if (!range.linked)
|
691
|
+
continue;
|
692
|
+
var fmt = exports.snippetManager.tmStrFormat(text, range.original);
|
693
|
+
session.replace(range, fmt);
|
694
|
+
}
|
695
|
+
this.$inChange = false;
|
696
|
+
};
|
697
|
+
this.onAfterExec = function(e) {
|
698
|
+
if (e.command && !e.command.readOnly)
|
699
|
+
this.updateLinkedFields();
|
700
|
+
};
|
701
|
+
this.onChangeSelection = function() {
|
702
|
+
if (!this.editor)
|
703
|
+
return;
|
704
|
+
var lead = this.editor.selection.lead;
|
705
|
+
var anchor = this.editor.selection.anchor;
|
706
|
+
var isEmpty = this.editor.selection.isEmpty();
|
707
|
+
for (var i = this.ranges.length; i--;) {
|
708
|
+
if (this.ranges[i].linked)
|
709
|
+
continue;
|
710
|
+
var containsLead = this.ranges[i].contains(lead.row, lead.column);
|
711
|
+
var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
|
712
|
+
if (containsLead && containsAnchor)
|
713
|
+
return;
|
714
|
+
}
|
715
|
+
this.detach();
|
716
|
+
};
|
717
|
+
this.onChangeSession = function() {
|
718
|
+
this.detach();
|
719
|
+
};
|
720
|
+
this.tabNext = function(dir) {
|
721
|
+
var max = this.tabstops.length;
|
722
|
+
var index = this.index + (dir || 1);
|
723
|
+
index = Math.min(Math.max(index, 1), max);
|
724
|
+
if (index == max)
|
725
|
+
index = 0;
|
726
|
+
this.selectTabstop(index);
|
727
|
+
if (index === 0)
|
728
|
+
this.detach();
|
729
|
+
};
|
730
|
+
this.selectTabstop = function(index) {
|
731
|
+
this.$openTabstops = null;
|
732
|
+
var ts = this.tabstops[this.index];
|
733
|
+
if (ts)
|
734
|
+
this.addTabstopMarkers(ts);
|
735
|
+
this.index = index;
|
736
|
+
ts = this.tabstops[this.index];
|
737
|
+
if (!ts || !ts.length)
|
738
|
+
return;
|
739
|
+
|
740
|
+
this.selectedTabstop = ts;
|
741
|
+
if (!this.editor.inVirtualSelectionMode) {
|
742
|
+
var sel = this.editor.multiSelect;
|
743
|
+
sel.toSingleRange(ts.firstNonLinked.clone());
|
744
|
+
for (var i = ts.length; i--;) {
|
745
|
+
if (ts.hasLinkedRanges && ts[i].linked)
|
746
|
+
continue;
|
747
|
+
sel.addRange(ts[i].clone(), true);
|
748
|
+
}
|
749
|
+
if (sel.ranges[0])
|
750
|
+
sel.addRange(sel.ranges[0].clone());
|
751
|
+
} else {
|
752
|
+
this.editor.selection.setRange(ts.firstNonLinked);
|
753
|
+
}
|
754
|
+
|
755
|
+
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
756
|
+
};
|
757
|
+
this.addTabstops = function(tabstops, start, end) {
|
758
|
+
if (!this.$openTabstops)
|
759
|
+
this.$openTabstops = [];
|
760
|
+
if (!tabstops[0]) {
|
761
|
+
var p = Range.fromPoints(end, end);
|
762
|
+
moveRelative(p.start, start);
|
763
|
+
moveRelative(p.end, start);
|
764
|
+
tabstops[0] = [p];
|
765
|
+
tabstops[0].index = 0;
|
766
|
+
}
|
767
|
+
|
768
|
+
var i = this.index;
|
769
|
+
var arg = [i + 1, 0];
|
770
|
+
var ranges = this.ranges;
|
771
|
+
tabstops.forEach(function(ts, index) {
|
772
|
+
var dest = this.$openTabstops[index] || ts;
|
773
|
+
|
774
|
+
for (var i = ts.length; i--;) {
|
775
|
+
var p = ts[i];
|
776
|
+
var range = Range.fromPoints(p.start, p.end || p.start);
|
777
|
+
movePoint(range.start, start);
|
778
|
+
movePoint(range.end, start);
|
779
|
+
range.original = p;
|
780
|
+
range.tabstop = dest;
|
781
|
+
ranges.push(range);
|
782
|
+
if (dest != ts)
|
783
|
+
dest.unshift(range);
|
784
|
+
else
|
785
|
+
dest[i] = range;
|
786
|
+
if (p.fmtString) {
|
787
|
+
range.linked = true;
|
788
|
+
dest.hasLinkedRanges = true;
|
789
|
+
} else if (!dest.firstNonLinked)
|
790
|
+
dest.firstNonLinked = range;
|
791
|
+
}
|
792
|
+
if (!dest.firstNonLinked)
|
793
|
+
dest.hasLinkedRanges = false;
|
794
|
+
if (dest === ts) {
|
795
|
+
arg.push(dest);
|
796
|
+
this.$openTabstops[index] = dest;
|
797
|
+
}
|
798
|
+
this.addTabstopMarkers(dest);
|
799
|
+
}, this);
|
800
|
+
|
801
|
+
if (arg.length > 2) {
|
802
|
+
if (this.tabstops.length)
|
803
|
+
arg.push(arg.splice(2, 1)[0]);
|
804
|
+
this.tabstops.splice.apply(this.tabstops, arg);
|
805
|
+
}
|
806
|
+
};
|
807
|
+
|
808
|
+
this.addTabstopMarkers = function(ts) {
|
809
|
+
var session = this.editor.session;
|
810
|
+
ts.forEach(function(range) {
|
811
|
+
if (!range.markerId)
|
812
|
+
range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
|
813
|
+
});
|
814
|
+
};
|
815
|
+
this.removeTabstopMarkers = function(ts) {
|
816
|
+
var session = this.editor.session;
|
817
|
+
ts.forEach(function(range) {
|
818
|
+
session.removeMarker(range.markerId);
|
819
|
+
range.markerId = null;
|
820
|
+
});
|
821
|
+
};
|
822
|
+
this.removeRange = function(range) {
|
823
|
+
var i = range.tabstop.indexOf(range);
|
824
|
+
range.tabstop.splice(i, 1);
|
825
|
+
i = this.ranges.indexOf(range);
|
826
|
+
this.ranges.splice(i, 1);
|
827
|
+
this.editor.session.removeMarker(range.markerId);
|
828
|
+
if (!range.tabstop.length) {
|
829
|
+
i = this.tabstops.indexOf(range.tabstop);
|
830
|
+
if (i != -1)
|
831
|
+
this.tabstops.splice(i, 1);
|
832
|
+
if (!this.tabstops.length)
|
833
|
+
this.detach();
|
834
|
+
}
|
835
|
+
};
|
836
|
+
|
837
|
+
this.keyboardHandler = new HashHandler();
|
838
|
+
this.keyboardHandler.bindKeys({
|
839
|
+
"Tab": function(ed) {
|
840
|
+
if (exports.snippetManager && exports.snippetManager.expandWithTab(ed)) {
|
841
|
+
return;
|
842
|
+
}
|
843
|
+
|
844
|
+
ed.tabstopManager.tabNext(1);
|
845
|
+
},
|
846
|
+
"Shift-Tab": function(ed) {
|
847
|
+
ed.tabstopManager.tabNext(-1);
|
848
|
+
},
|
849
|
+
"Esc": function(ed) {
|
850
|
+
ed.tabstopManager.detach();
|
851
|
+
},
|
852
|
+
"Return": function(ed) {
|
853
|
+
return false;
|
854
|
+
}
|
855
|
+
});
|
856
|
+
}).call(TabstopManager.prototype);
|
857
|
+
|
858
|
+
|
859
|
+
|
860
|
+
var changeTracker = {};
|
861
|
+
changeTracker.onChange = Anchor.prototype.onChange;
|
862
|
+
changeTracker.setPosition = function(row, column) {
|
863
|
+
this.pos.row = row;
|
864
|
+
this.pos.column = column;
|
865
|
+
};
|
866
|
+
changeTracker.update = function(pos, delta, $insertRight) {
|
867
|
+
this.$insertRight = $insertRight;
|
868
|
+
this.pos = pos;
|
869
|
+
this.onChange(delta);
|
870
|
+
};
|
871
|
+
|
872
|
+
var movePoint = function(point, diff) {
|
873
|
+
if (point.row == 0)
|
874
|
+
point.column += diff.column;
|
875
|
+
point.row += diff.row;
|
876
|
+
};
|
877
|
+
|
878
|
+
var moveRelative = function(point, start) {
|
879
|
+
if (point.row == start.row)
|
880
|
+
point.column -= start.column;
|
881
|
+
point.row -= start.row;
|
882
|
+
};
|
883
|
+
|
884
|
+
|
885
|
+
require("./lib/dom").importCssString("\
|
886
|
+
.ace_snippet-marker {\
|
887
|
+
-moz-box-sizing: border-box;\
|
888
|
+
box-sizing: border-box;\
|
889
|
+
background: rgba(194, 193, 208, 0.09);\
|
890
|
+
border: 1px dotted rgba(211, 208, 235, 0.62);\
|
891
|
+
position: absolute;\
|
892
|
+
}");
|
893
|
+
|
894
|
+
exports.snippetManager = new SnippetManager();
|
895
|
+
|
896
|
+
|
897
|
+
var Editor = require("./editor").Editor;
|
898
|
+
(function() {
|
899
|
+
this.insertSnippet = function(content, options) {
|
900
|
+
return exports.snippetManager.insertSnippet(this, content, options);
|
901
|
+
};
|
902
|
+
this.expandSnippet = function(options) {
|
903
|
+
return exports.snippetManager.expandWithTab(this, options);
|
904
|
+
};
|
905
|
+
}).call(Editor.prototype);
|
906
|
+
|
907
|
+
});
|
908
|
+
|
909
|
+
define("ace/autocomplete/popup",["require","exports","module","ace/virtual_renderer","ace/editor","ace/range","ace/lib/event","ace/lib/lang","ace/lib/dom"], function(require, exports, module) {
|
910
|
+
"use strict";
|
911
|
+
|
912
|
+
var Renderer = require("../virtual_renderer").VirtualRenderer;
|
913
|
+
var Editor = require("../editor").Editor;
|
914
|
+
var Range = require("../range").Range;
|
915
|
+
var event = require("../lib/event");
|
916
|
+
var lang = require("../lib/lang");
|
917
|
+
var dom = require("../lib/dom");
|
918
|
+
|
919
|
+
var $singleLineEditor = function(el) {
|
920
|
+
var renderer = new Renderer(el);
|
921
|
+
|
922
|
+
renderer.$maxLines = 4;
|
923
|
+
|
924
|
+
var editor = new Editor(renderer);
|
925
|
+
|
926
|
+
editor.setHighlightActiveLine(false);
|
927
|
+
editor.setShowPrintMargin(false);
|
928
|
+
editor.renderer.setShowGutter(false);
|
929
|
+
editor.renderer.setHighlightGutterLine(false);
|
930
|
+
|
931
|
+
editor.$mouseHandler.$focusTimeout = 0;
|
932
|
+
editor.$highlightTagPending = true;
|
933
|
+
|
934
|
+
return editor;
|
935
|
+
};
|
936
|
+
|
937
|
+
var AcePopup = function(parentNode) {
|
938
|
+
var el = dom.createElement("div");
|
939
|
+
var popup = new $singleLineEditor(el);
|
940
|
+
|
941
|
+
if (parentNode)
|
942
|
+
parentNode.appendChild(el);
|
943
|
+
el.style.display = "none";
|
944
|
+
popup.renderer.content.style.cursor = "default";
|
945
|
+
popup.renderer.setStyle("ace_autocomplete");
|
946
|
+
|
947
|
+
popup.setOption("displayIndentGuides", false);
|
948
|
+
popup.setOption("dragDelay", 150);
|
949
|
+
|
950
|
+
var noop = function(){};
|
951
|
+
|
952
|
+
popup.focus = noop;
|
953
|
+
popup.$isFocused = true;
|
954
|
+
|
955
|
+
popup.renderer.$cursorLayer.restartTimer = noop;
|
956
|
+
popup.renderer.$cursorLayer.element.style.opacity = 0;
|
957
|
+
|
958
|
+
popup.renderer.$maxLines = 8;
|
959
|
+
popup.renderer.$keepTextAreaAtCursor = false;
|
960
|
+
|
961
|
+
popup.setHighlightActiveLine(false);
|
962
|
+
popup.session.highlight("");
|
963
|
+
popup.session.$searchHighlight.clazz = "ace_highlight-marker";
|
964
|
+
|
965
|
+
popup.on("mousedown", function(e) {
|
966
|
+
var pos = e.getDocumentPosition();
|
967
|
+
popup.selection.moveToPosition(pos);
|
968
|
+
selectionMarker.start.row = selectionMarker.end.row = pos.row;
|
969
|
+
e.stop();
|
970
|
+
});
|
971
|
+
|
972
|
+
var lastMouseEvent;
|
973
|
+
var hoverMarker = new Range(-1,0,-1,Infinity);
|
974
|
+
var selectionMarker = new Range(-1,0,-1,Infinity);
|
975
|
+
selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
|
976
|
+
popup.setSelectOnHover = function(val) {
|
977
|
+
if (!val) {
|
978
|
+
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
|
979
|
+
} else if (hoverMarker.id) {
|
980
|
+
popup.session.removeMarker(hoverMarker.id);
|
981
|
+
hoverMarker.id = null;
|
982
|
+
}
|
983
|
+
};
|
984
|
+
popup.setSelectOnHover(false);
|
985
|
+
popup.on("mousemove", function(e) {
|
986
|
+
if (!lastMouseEvent) {
|
987
|
+
lastMouseEvent = e;
|
988
|
+
return;
|
989
|
+
}
|
990
|
+
if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
|
991
|
+
return;
|
992
|
+
}
|
993
|
+
lastMouseEvent = e;
|
994
|
+
lastMouseEvent.scrollTop = popup.renderer.scrollTop;
|
995
|
+
var row = lastMouseEvent.getDocumentPosition().row;
|
996
|
+
if (hoverMarker.start.row != row) {
|
997
|
+
if (!hoverMarker.id)
|
998
|
+
popup.setRow(row);
|
999
|
+
setHoverMarker(row);
|
1000
|
+
}
|
1001
|
+
});
|
1002
|
+
popup.renderer.on("beforeRender", function() {
|
1003
|
+
if (lastMouseEvent && hoverMarker.start.row != -1) {
|
1004
|
+
lastMouseEvent.$pos = null;
|
1005
|
+
var row = lastMouseEvent.getDocumentPosition().row;
|
1006
|
+
if (!hoverMarker.id)
|
1007
|
+
popup.setRow(row);
|
1008
|
+
setHoverMarker(row, true);
|
1009
|
+
}
|
1010
|
+
});
|
1011
|
+
popup.renderer.on("afterRender", function() {
|
1012
|
+
var row = popup.getRow();
|
1013
|
+
var t = popup.renderer.$textLayer;
|
1014
|
+
var selected = t.element.childNodes[row - t.config.firstRow];
|
1015
|
+
if (selected !== t.selectedNode && t.selectedNode)
|
1016
|
+
dom.removeCssClass(t.selectedNode, "ace_selected");
|
1017
|
+
t.selectedNode = selected;
|
1018
|
+
if (selected)
|
1019
|
+
dom.addCssClass(selected, "ace_selected");
|
1020
|
+
});
|
1021
|
+
var hideHoverMarker = function() { setHoverMarker(-1); };
|
1022
|
+
var setHoverMarker = function(row, suppressRedraw) {
|
1023
|
+
if (row !== hoverMarker.start.row) {
|
1024
|
+
hoverMarker.start.row = hoverMarker.end.row = row;
|
1025
|
+
if (!suppressRedraw)
|
1026
|
+
popup.session._emit("changeBackMarker");
|
1027
|
+
popup._emit("changeHoverMarker");
|
1028
|
+
}
|
1029
|
+
};
|
1030
|
+
popup.getHoveredRow = function() {
|
1031
|
+
return hoverMarker.start.row;
|
1032
|
+
};
|
1033
|
+
|
1034
|
+
event.addListener(popup.container, "mouseout", hideHoverMarker);
|
1035
|
+
popup.on("hide", hideHoverMarker);
|
1036
|
+
popup.on("changeSelection", hideHoverMarker);
|
1037
|
+
|
1038
|
+
popup.session.doc.getLength = function() {
|
1039
|
+
return popup.data.length;
|
1040
|
+
};
|
1041
|
+
popup.session.doc.getLine = function(i) {
|
1042
|
+
var data = popup.data[i];
|
1043
|
+
if (typeof data == "string")
|
1044
|
+
return data;
|
1045
|
+
return (data && data.value) || "";
|
1046
|
+
};
|
1047
|
+
|
1048
|
+
var bgTokenizer = popup.session.bgTokenizer;
|
1049
|
+
bgTokenizer.$tokenizeRow = function(row) {
|
1050
|
+
var data = popup.data[row];
|
1051
|
+
var tokens = [];
|
1052
|
+
if (!data)
|
1053
|
+
return tokens;
|
1054
|
+
if (typeof data == "string")
|
1055
|
+
data = {value: data};
|
1056
|
+
var caption = data.caption || data.value || data.name;
|
1057
|
+
|
1058
|
+
function addToken(value, className) {
|
1059
|
+
value && tokens.push({
|
1060
|
+
type: (data.className || "") + (className || ""),
|
1061
|
+
value: value
|
1062
|
+
});
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
var lower = caption.toLowerCase();
|
1066
|
+
var filterText = (popup.filterText || "").toLowerCase();
|
1067
|
+
var lastIndex = 0;
|
1068
|
+
var lastI = 0;
|
1069
|
+
for (var i = 0; i <= filterText.length; i++) {
|
1070
|
+
if (i != lastI && (data.matchMask & (1 << i) || i == filterText.length)) {
|
1071
|
+
var sub = filterText.slice(lastI, i);
|
1072
|
+
lastI = i;
|
1073
|
+
var index = lower.indexOf(sub, lastIndex);
|
1074
|
+
if (index == -1) continue;
|
1075
|
+
addToken(caption.slice(lastIndex, index), "");
|
1076
|
+
lastIndex = index + sub.length;
|
1077
|
+
addToken(caption.slice(index, lastIndex), "completion-highlight");
|
1078
|
+
}
|
1079
|
+
}
|
1080
|
+
addToken(caption.slice(lastIndex, caption.length), "");
|
1081
|
+
|
1082
|
+
if (data.meta)
|
1083
|
+
tokens.push({type: "completion-meta", value: data.meta});
|
1084
|
+
|
1085
|
+
return tokens;
|
1086
|
+
};
|
1087
|
+
bgTokenizer.$updateOnChange = noop;
|
1088
|
+
bgTokenizer.start = noop;
|
1089
|
+
|
1090
|
+
popup.session.$computeWidth = function() {
|
1091
|
+
return this.screenWidth = 0;
|
1092
|
+
};
|
1093
|
+
popup.isOpen = false;
|
1094
|
+
popup.isTopdown = false;
|
1095
|
+
popup.autoSelect = true;
|
1096
|
+
popup.filterText = "";
|
1097
|
+
|
1098
|
+
popup.data = [];
|
1099
|
+
popup.setData = function(list, filterText) {
|
1100
|
+
popup.filterText = filterText || "";
|
1101
|
+
popup.setValue(lang.stringRepeat("\n", list.length), -1);
|
1102
|
+
popup.data = list || [];
|
1103
|
+
popup.setRow(0);
|
1104
|
+
};
|
1105
|
+
popup.getData = function(row) {
|
1106
|
+
return popup.data[row];
|
1107
|
+
};
|
1108
|
+
|
1109
|
+
popup.getRow = function() {
|
1110
|
+
return selectionMarker.start.row;
|
1111
|
+
};
|
1112
|
+
popup.setRow = function(line) {
|
1113
|
+
line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length, line));
|
1114
|
+
if (selectionMarker.start.row != line) {
|
1115
|
+
popup.selection.clearSelection();
|
1116
|
+
selectionMarker.start.row = selectionMarker.end.row = line || 0;
|
1117
|
+
popup.session._emit("changeBackMarker");
|
1118
|
+
popup.moveCursorTo(line || 0, 0);
|
1119
|
+
if (popup.isOpen)
|
1120
|
+
popup._signal("select");
|
1121
|
+
}
|
1122
|
+
};
|
1123
|
+
|
1124
|
+
popup.on("changeSelection", function() {
|
1125
|
+
if (popup.isOpen)
|
1126
|
+
popup.setRow(popup.selection.lead.row);
|
1127
|
+
popup.renderer.scrollCursorIntoView();
|
1128
|
+
});
|
1129
|
+
|
1130
|
+
popup.hide = function() {
|
1131
|
+
this.container.style.display = "none";
|
1132
|
+
this._signal("hide");
|
1133
|
+
popup.isOpen = false;
|
1134
|
+
};
|
1135
|
+
popup.show = function(pos, lineHeight, topdownOnly) {
|
1136
|
+
var el = this.container;
|
1137
|
+
var screenHeight = window.innerHeight;
|
1138
|
+
var screenWidth = window.innerWidth;
|
1139
|
+
var renderer = this.renderer;
|
1140
|
+
var maxH = renderer.$maxLines * lineHeight * 1.4;
|
1141
|
+
var top = pos.top + this.$borderSize;
|
1142
|
+
var allowTopdown = top > screenHeight / 2 && !topdownOnly;
|
1143
|
+
if (allowTopdown && top + lineHeight + maxH > screenHeight) {
|
1144
|
+
renderer.$maxPixelHeight = top - 2 * this.$borderSize;
|
1145
|
+
el.style.top = "";
|
1146
|
+
el.style.bottom = screenHeight - top + "px";
|
1147
|
+
popup.isTopdown = false;
|
1148
|
+
} else {
|
1149
|
+
top += lineHeight;
|
1150
|
+
renderer.$maxPixelHeight = screenHeight - top - 0.2 * lineHeight;
|
1151
|
+
el.style.top = top + "px";
|
1152
|
+
el.style.bottom = "";
|
1153
|
+
popup.isTopdown = true;
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
el.style.display = "";
|
1157
|
+
|
1158
|
+
var left = pos.left;
|
1159
|
+
if (left + el.offsetWidth > screenWidth)
|
1160
|
+
left = screenWidth - el.offsetWidth;
|
1161
|
+
|
1162
|
+
el.style.left = left + "px";
|
1163
|
+
|
1164
|
+
this._signal("show");
|
1165
|
+
lastMouseEvent = null;
|
1166
|
+
popup.isOpen = true;
|
1167
|
+
};
|
1168
|
+
|
1169
|
+
popup.getTextLeftOffset = function() {
|
1170
|
+
return this.$borderSize + this.renderer.$padding + this.$imageSize;
|
1171
|
+
};
|
1172
|
+
|
1173
|
+
popup.$imageSize = 0;
|
1174
|
+
popup.$borderSize = 1;
|
1175
|
+
|
1176
|
+
return popup;
|
1177
|
+
};
|
1178
|
+
|
1179
|
+
dom.importCssString("\
|
1180
|
+
.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\
|
1181
|
+
background-color: #CAD6FA;\
|
1182
|
+
z-index: 1;\
|
1183
|
+
}\
|
1184
|
+
.ace_dark.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\
|
1185
|
+
background-color: #3a674e;\
|
1186
|
+
}\
|
1187
|
+
.ace_editor.ace_autocomplete .ace_line-hover {\
|
1188
|
+
border: 1px solid #abbffe;\
|
1189
|
+
margin-top: -1px;\
|
1190
|
+
background: rgba(233,233,253,0.4);\
|
1191
|
+
position: absolute;\
|
1192
|
+
z-index: 2;\
|
1193
|
+
}\
|
1194
|
+
.ace_dark.ace_editor.ace_autocomplete .ace_line-hover {\
|
1195
|
+
border: 1px solid rgba(109, 150, 13, 0.8);\
|
1196
|
+
background: rgba(58, 103, 78, 0.62);\
|
1197
|
+
}\
|
1198
|
+
.ace_completion-meta {\
|
1199
|
+
opacity: 0.5;\
|
1200
|
+
margin: 0.9em;\
|
1201
|
+
}\
|
1202
|
+
.ace_editor.ace_autocomplete .ace_completion-highlight{\
|
1203
|
+
color: #2d69c7;\
|
1204
|
+
}\
|
1205
|
+
.ace_dark.ace_editor.ace_autocomplete .ace_completion-highlight{\
|
1206
|
+
color: #93ca12;\
|
1207
|
+
}\
|
1208
|
+
.ace_editor.ace_autocomplete {\
|
1209
|
+
width: 300px;\
|
1210
|
+
z-index: 200000;\
|
1211
|
+
border: 1px lightgray solid;\
|
1212
|
+
position: fixed;\
|
1213
|
+
box-shadow: 2px 3px 5px rgba(0,0,0,.2);\
|
1214
|
+
line-height: 1.4;\
|
1215
|
+
background: #fefefe;\
|
1216
|
+
color: #111;\
|
1217
|
+
}\
|
1218
|
+
.ace_dark.ace_editor.ace_autocomplete {\
|
1219
|
+
border: 1px #484747 solid;\
|
1220
|
+
box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.51);\
|
1221
|
+
line-height: 1.4;\
|
1222
|
+
background: #25282c;\
|
1223
|
+
color: #c1c1c1;\
|
1224
|
+
}", "autocompletion.css");
|
1225
|
+
|
1226
|
+
exports.AcePopup = AcePopup;
|
1227
|
+
|
1228
|
+
});
|
1229
|
+
|
1230
|
+
define("ace/autocomplete/util",["require","exports","module"], function(require, exports, module) {
|
1231
|
+
"use strict";
|
1232
|
+
|
1233
|
+
exports.parForEach = function(array, fn, callback) {
|
1234
|
+
var completed = 0;
|
1235
|
+
var arLength = array.length;
|
1236
|
+
if (arLength === 0)
|
1237
|
+
callback();
|
1238
|
+
for (var i = 0; i < arLength; i++) {
|
1239
|
+
fn(array[i], function(result, err) {
|
1240
|
+
completed++;
|
1241
|
+
if (completed === arLength)
|
1242
|
+
callback(result, err);
|
1243
|
+
});
|
1244
|
+
}
|
1245
|
+
};
|
1246
|
+
|
1247
|
+
var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/;
|
1248
|
+
|
1249
|
+
exports.retrievePrecedingIdentifier = function(text, pos, regex) {
|
1250
|
+
regex = regex || ID_REGEX;
|
1251
|
+
var buf = [];
|
1252
|
+
for (var i = pos-1; i >= 0; i--) {
|
1253
|
+
if (regex.test(text[i]))
|
1254
|
+
buf.push(text[i]);
|
1255
|
+
else
|
1256
|
+
break;
|
1257
|
+
}
|
1258
|
+
return buf.reverse().join("");
|
1259
|
+
};
|
1260
|
+
|
1261
|
+
exports.retrieveFollowingIdentifier = function(text, pos, regex) {
|
1262
|
+
regex = regex || ID_REGEX;
|
1263
|
+
var buf = [];
|
1264
|
+
for (var i = pos; i < text.length; i++) {
|
1265
|
+
if (regex.test(text[i]))
|
1266
|
+
buf.push(text[i]);
|
1267
|
+
else
|
1268
|
+
break;
|
1269
|
+
}
|
1270
|
+
return buf;
|
1271
|
+
};
|
1272
|
+
|
1273
|
+
exports.getCompletionPrefix = function (editor) {
|
1274
|
+
var pos = editor.getCursorPosition();
|
1275
|
+
var line = editor.session.getLine(pos.row);
|
1276
|
+
var prefix;
|
1277
|
+
editor.completers.forEach(function(completer) {
|
1278
|
+
if (completer.identifierRegexps) {
|
1279
|
+
completer.identifierRegexps.forEach(function(identifierRegex) {
|
1280
|
+
if (!prefix && identifierRegex)
|
1281
|
+
prefix = this.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
|
1282
|
+
}.bind(this));
|
1283
|
+
}
|
1284
|
+
}.bind(this));
|
1285
|
+
return prefix || this.retrievePrecedingIdentifier(line, pos.column);
|
1286
|
+
};
|
1287
|
+
|
1288
|
+
});
|
1289
|
+
|
1290
|
+
define("ace/autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/popup","ace/autocomplete/util","ace/lib/event","ace/lib/lang","ace/lib/dom","ace/snippets"], function(require, exports, module) {
|
1291
|
+
"use strict";
|
1292
|
+
|
1293
|
+
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
1294
|
+
var AcePopup = require("./autocomplete/popup").AcePopup;
|
1295
|
+
var util = require("./autocomplete/util");
|
1296
|
+
var event = require("./lib/event");
|
1297
|
+
var lang = require("./lib/lang");
|
1298
|
+
var dom = require("./lib/dom");
|
1299
|
+
var snippetManager = require("./snippets").snippetManager;
|
1300
|
+
|
1301
|
+
var Autocomplete = function() {
|
1302
|
+
this.autoInsert = false;
|
1303
|
+
this.autoSelect = true;
|
1304
|
+
this.exactMatch = false;
|
1305
|
+
this.gatherCompletionsId = 0;
|
1306
|
+
this.keyboardHandler = new HashHandler();
|
1307
|
+
this.keyboardHandler.bindKeys(this.commands);
|
1308
|
+
|
1309
|
+
this.blurListener = this.blurListener.bind(this);
|
1310
|
+
this.changeListener = this.changeListener.bind(this);
|
1311
|
+
this.mousedownListener = this.mousedownListener.bind(this);
|
1312
|
+
this.mousewheelListener = this.mousewheelListener.bind(this);
|
1313
|
+
|
1314
|
+
this.changeTimer = lang.delayedCall(function() {
|
1315
|
+
this.updateCompletions(true);
|
1316
|
+
}.bind(this));
|
1317
|
+
|
1318
|
+
this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50);
|
1319
|
+
};
|
1320
|
+
|
1321
|
+
(function() {
|
1322
|
+
|
1323
|
+
this.$init = function() {
|
1324
|
+
this.popup = new AcePopup(document.body || document.documentElement);
|
1325
|
+
this.popup.on("click", function(e) {
|
1326
|
+
this.insertMatch();
|
1327
|
+
e.stop();
|
1328
|
+
}.bind(this));
|
1329
|
+
this.popup.focus = this.editor.focus.bind(this.editor);
|
1330
|
+
this.popup.on("show", this.tooltipTimer.bind(null, null));
|
1331
|
+
this.popup.on("select", this.tooltipTimer.bind(null, null));
|
1332
|
+
this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null));
|
1333
|
+
return this.popup;
|
1334
|
+
};
|
1335
|
+
|
1336
|
+
this.getPopup = function() {
|
1337
|
+
return this.popup || this.$init();
|
1338
|
+
};
|
1339
|
+
|
1340
|
+
this.openPopup = function(editor, prefix, keepPopupPosition) {
|
1341
|
+
if (!this.popup)
|
1342
|
+
this.$init();
|
1343
|
+
|
1344
|
+
this.popup.autoSelect = this.autoSelect;
|
1345
|
+
|
1346
|
+
this.popup.setData(this.completions.filtered, this.completions.filterText);
|
1347
|
+
|
1348
|
+
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
1349
|
+
|
1350
|
+
var renderer = editor.renderer;
|
1351
|
+
this.popup.setRow(this.autoSelect ? 0 : -1);
|
1352
|
+
if (!keepPopupPosition) {
|
1353
|
+
this.popup.setTheme(editor.getTheme());
|
1354
|
+
this.popup.setFontSize(editor.getFontSize());
|
1355
|
+
|
1356
|
+
var lineHeight = renderer.layerConfig.lineHeight;
|
1357
|
+
|
1358
|
+
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
|
1359
|
+
pos.left -= this.popup.getTextLeftOffset();
|
1360
|
+
|
1361
|
+
var rect = editor.container.getBoundingClientRect();
|
1362
|
+
pos.top += rect.top - renderer.layerConfig.offset;
|
1363
|
+
pos.left += rect.left - editor.renderer.scrollLeft;
|
1364
|
+
pos.left += renderer.gutterWidth;
|
1365
|
+
|
1366
|
+
this.popup.show(pos, lineHeight);
|
1367
|
+
} else if (keepPopupPosition && !prefix) {
|
1368
|
+
this.detach();
|
1369
|
+
}
|
1370
|
+
};
|
1371
|
+
|
1372
|
+
this.detach = function() {
|
1373
|
+
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
|
1374
|
+
this.editor.off("changeSelection", this.changeListener);
|
1375
|
+
this.editor.off("blur", this.blurListener);
|
1376
|
+
this.editor.off("mousedown", this.mousedownListener);
|
1377
|
+
this.editor.off("mousewheel", this.mousewheelListener);
|
1378
|
+
this.changeTimer.cancel();
|
1379
|
+
this.hideDocTooltip();
|
1380
|
+
|
1381
|
+
this.gatherCompletionsId += 1;
|
1382
|
+
if (this.popup && this.popup.isOpen)
|
1383
|
+
this.popup.hide();
|
1384
|
+
|
1385
|
+
if (this.base)
|
1386
|
+
this.base.detach();
|
1387
|
+
this.activated = false;
|
1388
|
+
this.completions = this.base = null;
|
1389
|
+
};
|
1390
|
+
|
1391
|
+
this.changeListener = function(e) {
|
1392
|
+
var cursor = this.editor.selection.lead;
|
1393
|
+
if (cursor.row != this.base.row || cursor.column < this.base.column) {
|
1394
|
+
this.detach();
|
1395
|
+
}
|
1396
|
+
if (this.activated)
|
1397
|
+
this.changeTimer.schedule();
|
1398
|
+
else
|
1399
|
+
this.detach();
|
1400
|
+
};
|
1401
|
+
|
1402
|
+
this.blurListener = function(e) {
|
1403
|
+
var el = document.activeElement;
|
1404
|
+
var text = this.editor.textInput.getElement();
|
1405
|
+
var fromTooltip = e.relatedTarget && this.tooltipNode && this.tooltipNode.contains(e.relatedTarget);
|
1406
|
+
var container = this.popup && this.popup.container;
|
1407
|
+
if (el != text && el.parentNode != container && !fromTooltip
|
1408
|
+
&& el != this.tooltipNode && e.relatedTarget != text
|
1409
|
+
) {
|
1410
|
+
this.detach();
|
1411
|
+
}
|
1412
|
+
};
|
1413
|
+
|
1414
|
+
this.mousedownListener = function(e) {
|
1415
|
+
this.detach();
|
1416
|
+
};
|
1417
|
+
|
1418
|
+
this.mousewheelListener = function(e) {
|
1419
|
+
this.detach();
|
1420
|
+
};
|
1421
|
+
|
1422
|
+
this.goTo = function(where) {
|
1423
|
+
var row = this.popup.getRow();
|
1424
|
+
var max = this.popup.session.getLength() - 1;
|
1425
|
+
|
1426
|
+
switch(where) {
|
1427
|
+
case "up": row = row <= 0 ? max : row - 1; break;
|
1428
|
+
case "down": row = row >= max ? -1 : row + 1; break;
|
1429
|
+
case "start": row = 0; break;
|
1430
|
+
case "end": row = max; break;
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
this.popup.setRow(row);
|
1434
|
+
};
|
1435
|
+
|
1436
|
+
this.insertMatch = function(data, options) {
|
1437
|
+
if (!data)
|
1438
|
+
data = this.popup.getData(this.popup.getRow());
|
1439
|
+
if (!data)
|
1440
|
+
return false;
|
1441
|
+
|
1442
|
+
if (data.completer && data.completer.insertMatch) {
|
1443
|
+
data.completer.insertMatch(this.editor, data);
|
1444
|
+
} else {
|
1445
|
+
if (this.completions.filterText) {
|
1446
|
+
var ranges = this.editor.selection.getAllRanges();
|
1447
|
+
for (var i = 0, range; range = ranges[i]; i++) {
|
1448
|
+
range.start.column -= this.completions.filterText.length;
|
1449
|
+
this.editor.session.remove(range);
|
1450
|
+
}
|
1451
|
+
}
|
1452
|
+
if (data.snippet)
|
1453
|
+
snippetManager.insertSnippet(this.editor, data.snippet);
|
1454
|
+
else
|
1455
|
+
this.editor.execCommand("insertstring", data.value || data);
|
1456
|
+
}
|
1457
|
+
this.detach();
|
1458
|
+
};
|
1459
|
+
|
1460
|
+
|
1461
|
+
this.commands = {
|
1462
|
+
"Up": function(editor) { editor.completer.goTo("up"); },
|
1463
|
+
"Down": function(editor) { editor.completer.goTo("down"); },
|
1464
|
+
"Ctrl-Up|Ctrl-Home": function(editor) { editor.completer.goTo("start"); },
|
1465
|
+
"Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); },
|
1466
|
+
|
1467
|
+
"Esc": function(editor) { editor.completer.detach(); },
|
1468
|
+
"Return": function(editor) { return editor.completer.insertMatch(); },
|
1469
|
+
"Shift-Return": function(editor) { editor.completer.insertMatch(null, {deleteSuffix: true}); },
|
1470
|
+
"Tab": function(editor) {
|
1471
|
+
var result = editor.completer.insertMatch();
|
1472
|
+
if (!result && !editor.tabstopManager)
|
1473
|
+
editor.completer.goTo("down");
|
1474
|
+
else
|
1475
|
+
return result;
|
1476
|
+
},
|
1477
|
+
|
1478
|
+
"PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
|
1479
|
+
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
|
1480
|
+
};
|
1481
|
+
|
1482
|
+
this.gatherCompletions = function(editor, callback) {
|
1483
|
+
var session = editor.getSession();
|
1484
|
+
var pos = editor.getCursorPosition();
|
1485
|
+
|
1486
|
+
var prefix = util.getCompletionPrefix(editor);
|
1487
|
+
|
1488
|
+
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
|
1489
|
+
this.base.$insertRight = true;
|
1490
|
+
|
1491
|
+
var matches = [];
|
1492
|
+
var total = editor.completers.length;
|
1493
|
+
editor.completers.forEach(function(completer, i) {
|
1494
|
+
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
|
1495
|
+
if (!err && results)
|
1496
|
+
matches = matches.concat(results);
|
1497
|
+
callback(null, {
|
1498
|
+
prefix: util.getCompletionPrefix(editor),
|
1499
|
+
matches: matches,
|
1500
|
+
finished: (--total === 0)
|
1501
|
+
});
|
1502
|
+
});
|
1503
|
+
});
|
1504
|
+
return true;
|
1505
|
+
};
|
1506
|
+
|
1507
|
+
this.showPopup = function(editor) {
|
1508
|
+
if (this.editor)
|
1509
|
+
this.detach();
|
1510
|
+
|
1511
|
+
this.activated = true;
|
1512
|
+
|
1513
|
+
this.editor = editor;
|
1514
|
+
if (editor.completer != this) {
|
1515
|
+
if (editor.completer)
|
1516
|
+
editor.completer.detach();
|
1517
|
+
editor.completer = this;
|
1518
|
+
}
|
1519
|
+
|
1520
|
+
editor.on("changeSelection", this.changeListener);
|
1521
|
+
editor.on("blur", this.blurListener);
|
1522
|
+
editor.on("mousedown", this.mousedownListener);
|
1523
|
+
editor.on("mousewheel", this.mousewheelListener);
|
1524
|
+
|
1525
|
+
this.updateCompletions();
|
1526
|
+
};
|
1527
|
+
|
1528
|
+
this.updateCompletions = function(keepPopupPosition) {
|
1529
|
+
if (keepPopupPosition && this.base && this.completions) {
|
1530
|
+
var pos = this.editor.getCursorPosition();
|
1531
|
+
var prefix = this.editor.session.getTextRange({start: this.base, end: pos});
|
1532
|
+
if (prefix == this.completions.filterText)
|
1533
|
+
return;
|
1534
|
+
this.completions.setFilter(prefix);
|
1535
|
+
if (!this.completions.filtered.length)
|
1536
|
+
return this.detach();
|
1537
|
+
if (this.completions.filtered.length == 1
|
1538
|
+
&& this.completions.filtered[0].value == prefix
|
1539
|
+
&& !this.completions.filtered[0].snippet)
|
1540
|
+
return this.detach();
|
1541
|
+
this.openPopup(this.editor, prefix, keepPopupPosition);
|
1542
|
+
return;
|
1543
|
+
}
|
1544
|
+
var _id = this.gatherCompletionsId;
|
1545
|
+
this.gatherCompletions(this.editor, function(err, results) {
|
1546
|
+
var detachIfFinished = function() {
|
1547
|
+
if (!results.finished) return;
|
1548
|
+
return this.detach();
|
1549
|
+
}.bind(this);
|
1550
|
+
|
1551
|
+
var prefix = results.prefix;
|
1552
|
+
var matches = results && results.matches;
|
1553
|
+
|
1554
|
+
if (!matches || !matches.length)
|
1555
|
+
return detachIfFinished();
|
1556
|
+
if (prefix.indexOf(results.prefix) !== 0 || _id != this.gatherCompletionsId)
|
1557
|
+
return;
|
1558
|
+
|
1559
|
+
this.completions = new FilteredList(matches);
|
1560
|
+
|
1561
|
+
if (this.exactMatch)
|
1562
|
+
this.completions.exactMatch = true;
|
1563
|
+
|
1564
|
+
this.completions.setFilter(prefix);
|
1565
|
+
var filtered = this.completions.filtered;
|
1566
|
+
if (!filtered.length)
|
1567
|
+
return detachIfFinished();
|
1568
|
+
if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet)
|
1569
|
+
return detachIfFinished();
|
1570
|
+
if (this.autoInsert && filtered.length == 1 && results.finished)
|
1571
|
+
return this.insertMatch(filtered[0]);
|
1572
|
+
|
1573
|
+
this.openPopup(this.editor, prefix, keepPopupPosition);
|
1574
|
+
}.bind(this));
|
1575
|
+
};
|
1576
|
+
|
1577
|
+
this.cancelContextMenu = function() {
|
1578
|
+
this.editor.$mouseHandler.cancelContextMenu();
|
1579
|
+
};
|
1580
|
+
|
1581
|
+
this.updateDocTooltip = function() {
|
1582
|
+
var popup = this.popup;
|
1583
|
+
var all = popup.data;
|
1584
|
+
var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]);
|
1585
|
+
var doc = null;
|
1586
|
+
if (!selected || !this.editor || !this.popup.isOpen)
|
1587
|
+
return this.hideDocTooltip();
|
1588
|
+
this.editor.completers.some(function(completer) {
|
1589
|
+
if (completer.getDocTooltip)
|
1590
|
+
doc = completer.getDocTooltip(selected);
|
1591
|
+
return doc;
|
1592
|
+
});
|
1593
|
+
if (!doc)
|
1594
|
+
doc = selected;
|
1595
|
+
|
1596
|
+
if (typeof doc == "string")
|
1597
|
+
doc = {docText: doc};
|
1598
|
+
if (!doc || !(doc.docHTML || doc.docText))
|
1599
|
+
return this.hideDocTooltip();
|
1600
|
+
this.showDocTooltip(doc);
|
1601
|
+
};
|
1602
|
+
|
1603
|
+
this.showDocTooltip = function(item) {
|
1604
|
+
if (!this.tooltipNode) {
|
1605
|
+
this.tooltipNode = dom.createElement("div");
|
1606
|
+
this.tooltipNode.className = "ace_tooltip ace_doc-tooltip";
|
1607
|
+
this.tooltipNode.style.margin = 0;
|
1608
|
+
this.tooltipNode.style.pointerEvents = "auto";
|
1609
|
+
this.tooltipNode.tabIndex = -1;
|
1610
|
+
this.tooltipNode.onblur = this.blurListener.bind(this);
|
1611
|
+
this.tooltipNode.onclick = this.onTooltipClick.bind(this);
|
1612
|
+
}
|
1613
|
+
|
1614
|
+
var tooltipNode = this.tooltipNode;
|
1615
|
+
if (item.docHTML) {
|
1616
|
+
tooltipNode.innerHTML = item.docHTML;
|
1617
|
+
} else if (item.docText) {
|
1618
|
+
tooltipNode.textContent = item.docText;
|
1619
|
+
}
|
1620
|
+
|
1621
|
+
if (!tooltipNode.parentNode)
|
1622
|
+
document.body.appendChild(tooltipNode);
|
1623
|
+
var popup = this.popup;
|
1624
|
+
var rect = popup.container.getBoundingClientRect();
|
1625
|
+
tooltipNode.style.top = popup.container.style.top;
|
1626
|
+
tooltipNode.style.bottom = popup.container.style.bottom;
|
1627
|
+
|
1628
|
+
tooltipNode.style.display = "block";
|
1629
|
+
if (window.innerWidth - rect.right < 320) {
|
1630
|
+
if (rect.left < 320) {
|
1631
|
+
if(popup.isTopdown) {
|
1632
|
+
tooltipNode.style.top = rect.bottom + "px";
|
1633
|
+
tooltipNode.style.left = rect.left + "px";
|
1634
|
+
tooltipNode.style.right = "";
|
1635
|
+
tooltipNode.style.bottom = "";
|
1636
|
+
} else {
|
1637
|
+
tooltipNode.style.top = popup.container.offsetTop - tooltipNode.offsetHeight + "px";
|
1638
|
+
tooltipNode.style.left = rect.left + "px";
|
1639
|
+
tooltipNode.style.right = "";
|
1640
|
+
tooltipNode.style.bottom = "";
|
1641
|
+
}
|
1642
|
+
} else {
|
1643
|
+
tooltipNode.style.right = window.innerWidth - rect.left + "px";
|
1644
|
+
tooltipNode.style.left = "";
|
1645
|
+
}
|
1646
|
+
} else {
|
1647
|
+
tooltipNode.style.left = (rect.right + 1) + "px";
|
1648
|
+
tooltipNode.style.right = "";
|
1649
|
+
}
|
1650
|
+
};
|
1651
|
+
|
1652
|
+
this.hideDocTooltip = function() {
|
1653
|
+
this.tooltipTimer.cancel();
|
1654
|
+
if (!this.tooltipNode) return;
|
1655
|
+
var el = this.tooltipNode;
|
1656
|
+
if (!this.editor.isFocused() && document.activeElement == el)
|
1657
|
+
this.editor.focus();
|
1658
|
+
this.tooltipNode = null;
|
1659
|
+
if (el.parentNode)
|
1660
|
+
el.parentNode.removeChild(el);
|
1661
|
+
};
|
1662
|
+
|
1663
|
+
this.onTooltipClick = function(e) {
|
1664
|
+
var a = e.target;
|
1665
|
+
while (a && a != this.tooltipNode) {
|
1666
|
+
if (a.nodeName == "A" && a.href) {
|
1667
|
+
a.rel = "noreferrer";
|
1668
|
+
a.target = "_blank";
|
1669
|
+
break;
|
1670
|
+
}
|
1671
|
+
a = a.parentNode;
|
1672
|
+
}
|
1673
|
+
};
|
1674
|
+
|
1675
|
+
}).call(Autocomplete.prototype);
|
1676
|
+
|
1677
|
+
Autocomplete.startCommand = {
|
1678
|
+
name: "startAutocomplete",
|
1679
|
+
exec: function(editor) {
|
1680
|
+
if (!editor.completer)
|
1681
|
+
editor.completer = new Autocomplete();
|
1682
|
+
editor.completer.autoInsert = false;
|
1683
|
+
editor.completer.autoSelect = true;
|
1684
|
+
editor.completer.showPopup(editor);
|
1685
|
+
editor.completer.cancelContextMenu();
|
1686
|
+
},
|
1687
|
+
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
|
1688
|
+
};
|
1689
|
+
|
1690
|
+
var FilteredList = function(array, filterText) {
|
1691
|
+
this.all = array;
|
1692
|
+
this.filtered = array;
|
1693
|
+
this.filterText = filterText || "";
|
1694
|
+
this.exactMatch = false;
|
1695
|
+
};
|
1696
|
+
(function(){
|
1697
|
+
this.setFilter = function(str) {
|
1698
|
+
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
|
1699
|
+
var matches = this.filtered;
|
1700
|
+
else
|
1701
|
+
var matches = this.all;
|
1702
|
+
|
1703
|
+
this.filterText = str;
|
1704
|
+
matches = this.filterCompletions(matches, this.filterText);
|
1705
|
+
matches = matches.sort(function(a, b) {
|
1706
|
+
return b.exactMatch - a.exactMatch || b.$score - a.$score
|
1707
|
+
|| (a.caption || a.value) < (b.caption || b.value);
|
1708
|
+
});
|
1709
|
+
var prev = null;
|
1710
|
+
matches = matches.filter(function(item){
|
1711
|
+
var caption = item.snippet || item.caption || item.value;
|
1712
|
+
if (caption === prev) return false;
|
1713
|
+
prev = caption;
|
1714
|
+
return true;
|
1715
|
+
});
|
1716
|
+
|
1717
|
+
this.filtered = matches;
|
1718
|
+
};
|
1719
|
+
this.filterCompletions = function(items, needle) {
|
1720
|
+
var results = [];
|
1721
|
+
var upper = needle.toUpperCase();
|
1722
|
+
var lower = needle.toLowerCase();
|
1723
|
+
loop: for (var i = 0, item; item = items[i]; i++) {
|
1724
|
+
var caption = item.caption || item.value || item.snippet;
|
1725
|
+
if (!caption) continue;
|
1726
|
+
var lastIndex = -1;
|
1727
|
+
var matchMask = 0;
|
1728
|
+
var penalty = 0;
|
1729
|
+
var index, distance;
|
1730
|
+
|
1731
|
+
if (this.exactMatch) {
|
1732
|
+
if (needle !== caption.substr(0, needle.length))
|
1733
|
+
continue loop;
|
1734
|
+
} else {
|
1735
|
+
var fullMatchIndex = caption.toLowerCase().indexOf(lower);
|
1736
|
+
if (fullMatchIndex > -1) {
|
1737
|
+
penalty = fullMatchIndex;
|
1738
|
+
} else {
|
1739
|
+
for (var j = 0; j < needle.length; j++) {
|
1740
|
+
var i1 = caption.indexOf(lower[j], lastIndex + 1);
|
1741
|
+
var i2 = caption.indexOf(upper[j], lastIndex + 1);
|
1742
|
+
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
|
1743
|
+
if (index < 0)
|
1744
|
+
continue loop;
|
1745
|
+
distance = index - lastIndex - 1;
|
1746
|
+
if (distance > 0) {
|
1747
|
+
if (lastIndex === -1)
|
1748
|
+
penalty += 10;
|
1749
|
+
penalty += distance;
|
1750
|
+
matchMask = matchMask | (1 << j);
|
1751
|
+
}
|
1752
|
+
lastIndex = index;
|
1753
|
+
}
|
1754
|
+
}
|
1755
|
+
}
|
1756
|
+
item.matchMask = matchMask;
|
1757
|
+
item.exactMatch = penalty ? 0 : 1;
|
1758
|
+
item.$score = (item.score || 0) - penalty;
|
1759
|
+
results.push(item);
|
1760
|
+
}
|
1761
|
+
return results;
|
1762
|
+
};
|
1763
|
+
}).call(FilteredList.prototype);
|
1764
|
+
|
1765
|
+
exports.Autocomplete = Autocomplete;
|
1766
|
+
exports.FilteredList = FilteredList;
|
1767
|
+
|
1768
|
+
});
|
1769
|
+
|
1770
|
+
define("ace/autocomplete/text_completer",["require","exports","module","ace/range"], function(require, exports, module) {
|
1771
|
+
var Range = require("../range").Range;
|
1772
|
+
|
1773
|
+
var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
|
1774
|
+
|
1775
|
+
function getWordIndex(doc, pos) {
|
1776
|
+
var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos));
|
1777
|
+
return textBefore.split(splitRegex).length - 1;
|
1778
|
+
}
|
1779
|
+
function wordDistance(doc, pos) {
|
1780
|
+
var prefixPos = getWordIndex(doc, pos);
|
1781
|
+
var words = doc.getValue().split(splitRegex);
|
1782
|
+
var wordScores = Object.create(null);
|
1783
|
+
|
1784
|
+
var currentWord = words[prefixPos];
|
1785
|
+
|
1786
|
+
words.forEach(function(word, idx) {
|
1787
|
+
if (!word || word === currentWord) return;
|
1788
|
+
|
1789
|
+
var distance = Math.abs(prefixPos - idx);
|
1790
|
+
var score = words.length - distance;
|
1791
|
+
if (wordScores[word]) {
|
1792
|
+
wordScores[word] = Math.max(score, wordScores[word]);
|
1793
|
+
} else {
|
1794
|
+
wordScores[word] = score;
|
1795
|
+
}
|
1796
|
+
});
|
1797
|
+
return wordScores;
|
1798
|
+
}
|
1799
|
+
|
1800
|
+
exports.getCompletions = function(editor, session, pos, prefix, callback) {
|
1801
|
+
var wordScore = wordDistance(session, pos);
|
1802
|
+
var wordList = Object.keys(wordScore);
|
1803
|
+
callback(null, wordList.map(function(word) {
|
1804
|
+
return {
|
1805
|
+
caption: word,
|
1806
|
+
value: word,
|
1807
|
+
score: wordScore[word],
|
1808
|
+
meta: "local"
|
1809
|
+
};
|
1810
|
+
}));
|
1811
|
+
};
|
1812
|
+
});
|
1813
|
+
|
1814
|
+
define("ace/ext/language_tools",["require","exports","module","ace/snippets","ace/autocomplete","ace/config","ace/lib/lang","ace/autocomplete/util","ace/autocomplete/text_completer","ace/editor","ace/config"], function(require, exports, module) {
|
1815
|
+
"use strict";
|
1816
|
+
|
1817
|
+
var snippetManager = require("../snippets").snippetManager;
|
1818
|
+
var Autocomplete = require("../autocomplete").Autocomplete;
|
1819
|
+
var config = require("../config");
|
1820
|
+
var lang = require("../lib/lang");
|
1821
|
+
var util = require("../autocomplete/util");
|
1822
|
+
|
1823
|
+
var textCompleter = require("../autocomplete/text_completer");
|
1824
|
+
var keyWordCompleter = {
|
1825
|
+
getCompletions: function(editor, session, pos, prefix, callback) {
|
1826
|
+
if (session.$mode.completer) {
|
1827
|
+
return session.$mode.completer.getCompletions(editor, session, pos, prefix, callback);
|
1828
|
+
}
|
1829
|
+
var state = editor.session.getState(pos.row);
|
1830
|
+
var completions = session.$mode.getCompletions(state, session, pos, prefix);
|
1831
|
+
callback(null, completions);
|
1832
|
+
}
|
1833
|
+
};
|
1834
|
+
|
1835
|
+
var snippetCompleter = {
|
1836
|
+
getCompletions: function(editor, session, pos, prefix, callback) {
|
1837
|
+
var scopes = [];
|
1838
|
+
var token = session.getTokenAt(pos.row, pos.column);
|
1839
|
+
if (token && token.type.match(/(tag-name|tag-open|tag-whitespace|attribute-name|attribute-value)\.xml$/))
|
1840
|
+
scopes.push('html-tag');
|
1841
|
+
else
|
1842
|
+
scopes = snippetManager.getActiveScopes(editor);
|
1843
|
+
|
1844
|
+
var snippetMap = snippetManager.snippetMap;
|
1845
|
+
var completions = [];
|
1846
|
+
scopes.forEach(function(scope) {
|
1847
|
+
var snippets = snippetMap[scope] || [];
|
1848
|
+
for (var i = snippets.length; i--;) {
|
1849
|
+
var s = snippets[i];
|
1850
|
+
var caption = s.name || s.tabTrigger;
|
1851
|
+
if (!caption)
|
1852
|
+
continue;
|
1853
|
+
completions.push({
|
1854
|
+
caption: caption,
|
1855
|
+
snippet: s.content,
|
1856
|
+
meta: s.tabTrigger && !s.name ? s.tabTrigger + "\u21E5 " : "snippet",
|
1857
|
+
type: "snippet"
|
1858
|
+
});
|
1859
|
+
}
|
1860
|
+
}, this);
|
1861
|
+
callback(null, completions);
|
1862
|
+
},
|
1863
|
+
getDocTooltip: function(item) {
|
1864
|
+
if (item.type == "snippet" && !item.docHTML) {
|
1865
|
+
item.docHTML = [
|
1866
|
+
"<b>", lang.escapeHTML(item.caption), "</b>", "<hr></hr>",
|
1867
|
+
lang.escapeHTML(item.snippet)
|
1868
|
+
].join("");
|
1869
|
+
}
|
1870
|
+
}
|
1871
|
+
};
|
1872
|
+
|
1873
|
+
var completers = [snippetCompleter, textCompleter, keyWordCompleter];
|
1874
|
+
exports.setCompleters = function(val) {
|
1875
|
+
completers.length = 0;
|
1876
|
+
if (val) completers.push.apply(completers, val);
|
1877
|
+
};
|
1878
|
+
exports.addCompleter = function(completer) {
|
1879
|
+
completers.push(completer);
|
1880
|
+
};
|
1881
|
+
exports.textCompleter = textCompleter;
|
1882
|
+
exports.keyWordCompleter = keyWordCompleter;
|
1883
|
+
exports.snippetCompleter = snippetCompleter;
|
1884
|
+
|
1885
|
+
var expandSnippet = {
|
1886
|
+
name: "expandSnippet",
|
1887
|
+
exec: function(editor) {
|
1888
|
+
return snippetManager.expandWithTab(editor);
|
1889
|
+
},
|
1890
|
+
bindKey: "Tab"
|
1891
|
+
};
|
1892
|
+
|
1893
|
+
var onChangeMode = function(e, editor) {
|
1894
|
+
loadSnippetsForMode(editor.session.$mode);
|
1895
|
+
};
|
1896
|
+
|
1897
|
+
var loadSnippetsForMode = function(mode) {
|
1898
|
+
var id = mode.$id;
|
1899
|
+
if (!snippetManager.files)
|
1900
|
+
snippetManager.files = {};
|
1901
|
+
loadSnippetFile(id);
|
1902
|
+
if (mode.modes)
|
1903
|
+
mode.modes.forEach(loadSnippetsForMode);
|
1904
|
+
};
|
1905
|
+
|
1906
|
+
var loadSnippetFile = function(id) {
|
1907
|
+
if (!id || snippetManager.files[id])
|
1908
|
+
return;
|
1909
|
+
var snippetFilePath = id.replace("mode", "snippets");
|
1910
|
+
snippetManager.files[id] = {};
|
1911
|
+
config.loadModule(snippetFilePath, function(m) {
|
1912
|
+
if (m) {
|
1913
|
+
snippetManager.files[id] = m;
|
1914
|
+
if (!m.snippets && m.snippetText)
|
1915
|
+
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
|
1916
|
+
snippetManager.register(m.snippets || [], m.scope);
|
1917
|
+
if (m.includeScopes) {
|
1918
|
+
snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
|
1919
|
+
m.includeScopes.forEach(function(x) {
|
1920
|
+
loadSnippetFile("ace/mode/" + x);
|
1921
|
+
});
|
1922
|
+
}
|
1923
|
+
}
|
1924
|
+
});
|
1925
|
+
};
|
1926
|
+
|
1927
|
+
var doLiveAutocomplete = function(e) {
|
1928
|
+
var editor = e.editor;
|
1929
|
+
var hasCompleter = editor.completer && editor.completer.activated;
|
1930
|
+
if (e.command.name === "backspace") {
|
1931
|
+
if (hasCompleter && !util.getCompletionPrefix(editor))
|
1932
|
+
editor.completer.detach();
|
1933
|
+
}
|
1934
|
+
else if (e.command.name === "insertstring") {
|
1935
|
+
var prefix = util.getCompletionPrefix(editor);
|
1936
|
+
if (prefix && !hasCompleter) {
|
1937
|
+
if (!editor.completer) {
|
1938
|
+
editor.completer = new Autocomplete();
|
1939
|
+
}
|
1940
|
+
editor.completer.autoInsert = false;
|
1941
|
+
editor.completer.showPopup(editor);
|
1942
|
+
}
|
1943
|
+
}
|
1944
|
+
};
|
1945
|
+
|
1946
|
+
var Editor = require("../editor").Editor;
|
1947
|
+
require("../config").defineOptions(Editor.prototype, "editor", {
|
1948
|
+
enableBasicAutocompletion: {
|
1949
|
+
set: function(val) {
|
1950
|
+
if (val) {
|
1951
|
+
if (!this.completers)
|
1952
|
+
this.completers = Array.isArray(val)? val: completers;
|
1953
|
+
this.commands.addCommand(Autocomplete.startCommand);
|
1954
|
+
} else {
|
1955
|
+
this.commands.removeCommand(Autocomplete.startCommand);
|
1956
|
+
}
|
1957
|
+
},
|
1958
|
+
value: false
|
1959
|
+
},
|
1960
|
+
enableLiveAutocompletion: {
|
1961
|
+
set: function(val) {
|
1962
|
+
if (val) {
|
1963
|
+
if (!this.completers)
|
1964
|
+
this.completers = Array.isArray(val)? val: completers;
|
1965
|
+
this.commands.on('afterExec', doLiveAutocomplete);
|
1966
|
+
} else {
|
1967
|
+
this.commands.removeListener('afterExec', doLiveAutocomplete);
|
1968
|
+
}
|
1969
|
+
},
|
1970
|
+
value: false
|
1971
|
+
},
|
1972
|
+
enableSnippets: {
|
1973
|
+
set: function(val) {
|
1974
|
+
if (val) {
|
1975
|
+
this.commands.addCommand(expandSnippet);
|
1976
|
+
this.on("changeMode", onChangeMode);
|
1977
|
+
onChangeMode(null, this);
|
1978
|
+
} else {
|
1979
|
+
this.commands.removeCommand(expandSnippet);
|
1980
|
+
this.off("changeMode", onChangeMode);
|
1981
|
+
}
|
1982
|
+
},
|
1983
|
+
value: false
|
1984
|
+
}
|
1985
|
+
});
|
1986
|
+
}); (function() {
|
1987
|
+
window.require(["ace/ext/language_tools"], function(m) {
|
1988
|
+
if (typeof module == "object" && typeof exports == "object" && module) {
|
1989
|
+
module.exports = m;
|
1990
|
+
}
|
1991
|
+
});
|
4
1992
|
})();
|
5
1993
|
|