Show More
@@ -0,0 +1,1 b'' | |||||
|
1 | define("ace/mode/html",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/javascript","ace/mode/css","ace/tokenizer","ace/mode/html_highlight_rules","ace/mode/behaviour/xml","ace/mode/folding/html"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("./javascript").Mode,g=a("./css").Mode,h=a("../tokenizer").Tokenizer,i=a("./html_highlight_rules").HtmlHighlightRules,j=a("./behaviour/xml").XmlBehaviour,k=a("./folding/html").FoldMode,l=function(){var a=new i;this.$tokenizer=new h(a.getRules()),this.$behaviour=new j,this.$embeds=a.getEmbeds(),this.createModeDelegates({"js-":f,"css-":g}),this.foldingRules=new k};d.inherits(l,e),function(){this.toggleCommentLines=function(a,b,c,d){return 0},this.getNextLineIndent=function(a,b,c){return this.$getIndent(b)},this.checkOutdent=function(a,b,c){return!1}}.call(l.prototype),b.Mode=l}),define("ace/mode/javascript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/javascript_highlight_rules","ace/mode/matching_brace_outdent","ace/range","ace/worker/worker_client","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("../tokenizer").Tokenizer,g=a("./javascript_highlight_rules").JavaScriptHighlightRules,h=a("./matching_brace_outdent").MatchingBraceOutdent,i=a("../range").Range,j=a("../worker/worker_client").WorkerClient,k=a("./behaviour/cstyle").CstyleBehaviour,l=a("./folding/cstyle").FoldMode,m=function(){this.$tokenizer=new f((new g).getRules()),this.$outdent=new h,this.$behaviour=new k,this.foldingRules=new l};d.inherits(m,e),function(){this.toggleCommentLines=function(a,b,c,d){var e=!0,f=/^(\s*)\/\//;for(var g=c;g<=d;g++)if(!f.test(b.getLine(g))){e=!1;break}if(e){var h=new i(0,0,0,0);for(var g=c;g<=d;g++){var j=b.getLine(g),k=j.match(f);h.start.row=g,h.end.row=g,h.end.column=k[0].length,b.replace(h,k[1])}}else b.indentRows(c,d,"//")},this.getNextLineIndent=function(a,b,c){var d=this.$getIndent(b),e=this.$tokenizer.getLineTokens(b,a),f=e.tokens,g=e.state;if(f.length&&f[f.length-1].type=="comment")return d;if(a=="start"||a=="regex_allowed"){var h=b.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);h&&(d+=c)}else if(a=="doc-start"){if(g=="start"||a=="regex_allowed")return"";var h=b.match(/^\s*(\/?)\*/);h&&(h[1]&&(d+=" "),d+="* ")}return d},this.checkOutdent=function(a,b,c){return this.$outdent.checkOutdent(b,c)},this.autoOutdent=function(a,b,c){this.$outdent.autoOutdent(b,c)},this.createWorker=function(a){var b=new j(["ace"],"worker-javascript.js","ace/mode/javascript_worker","JavaScriptWorker");return b.attachToDocument(a.getDocument()),b.on("jslint",function(b){var c=[];for(var d=0;d<b.data.length;d++){var e=b.data[d];e&&c.push({row:e.line-1,column:e.character-1,text:e.reason,type:"warning",lint:e})}a.setAnnotations(c)}),b.on("narcissus",function(b){a.setAnnotations([b.data])}),b.on("terminate",function(){a.clearAnnotations()}),b}}.call(m.prototype),b.Mode=m}),define("ace/mode/javascript_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/unicode","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("../lib/lang"),f=a("../unicode"),g=a("./doc_comment_highlight_rules").DocCommentHighlightRules,h=a("./text_highlight_rules").TextHighlightRules,i=function(){var a=e.arrayToMap("Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|Namespace|QName|XML|XMLList|ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt|JSON|Math|this|arguments|prototype|window|document".split("|")),b=e.arrayToMap("break|case|catch|continue|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|const|yield|import|get|set".split("|")),c="case|do|else|finally|in|instanceof|return|throw|try|typeof|yield",d=e.arrayToMap("__parent__|__count__|escape|unescape|with|__proto__".split("|")),h=e.arrayToMap("const|let|var|function".split("|")),i=e.arrayToMap("null|Infinity|NaN|undefined".split("|")),j=e.arrayToMap("class|enum|extends|super|export|implements|private|public|interface|package|protected|static".split("|")),k="["+f.packages.L+"\\$_]["+f.packages.L+f.packages.Mn+f.packages.Mc+f.packages.Nd+f.packages.Pc+"\\$_]*\\b";this.$rules={start:[{token:"comment",regex:"\\/\\/.*$"},(new g).getStartRule("doc-start"),{token:"comment",merge:!0,regex:"\\/\\*",next:"comment"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",merge:!0,regex:'["].*\\\\$',next:"qqstring"},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"string",merge:!0,regex:"['].*\\\\$",next:"qstring"},{token:"constant.numeric",regex:"0[xX][0-9a-fA-F]+\\b"},{token:"constant.numeric",regex:"[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"},{token:["keyword.definition","text","entity.name.function"],regex:"(function)(\\s+)("+k+")"},{token:"constant.language.boolean",regex:"(?:true|false)\\b"},{token:"keyword",regex:"(?:"+c+")\\b",next:"regex_allowed"},{token:function(c){return a.hasOwnProperty(c)?"variable.language":d.hasOwnProperty(c)?"invalid.deprecated":h.hasOwnProperty(c)?"keyword.definition":b.hasOwnProperty(c)?"keyword":i.hasOwnProperty(c)?"constant.language":j.hasOwnProperty(c)?"invalid.illegal":c=="debugger"?"invalid.deprecated":"identifier"},regex:k},{token:"keyword.operator",regex:"!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)",next:"regex_allowed"},{token:"punctuation.operator",regex:"\\?|\\:|\\,|\\;|\\.",next:"regex_allowed"},{token:"paren.lparen",regex:"[[({]",next:"regex_allowed"},{token:"paren.rparen",regex:"[\\])}]"},{token:"keyword.operator",regex:"\\/=?",next:"regex_allowed"},{token:"comment",regex:"^#!.*$"},{token:"text",regex:"\\s+"}],regex_allowed:[{token:"comment",merge:!0,regex:"\\/\\*",next:"comment_regex_allowed"},{token:"comment",regex:"\\/\\/.*$"},{token:"string.regexp",regex:"\\/",next:"regex",merge:!0},{token:"text",regex:"\\s+"},{token:"empty",regex:"",next:"start"}],regex:[{token:"regexp.keyword.operator",regex:"\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",next:"regex"},{token:"string.regexp",regex:"/\\w*",next:"start",merge:!0},{token:"string.regexp",regex:"[^\\\\/\\[]+",next:"regex",merge:!0},{token:"string.regexp.charachterclass",regex:"\\[",next:"regex_character_class",merge:!0},{token:"empty",regex:"",next:"start"}],regex_character_class:[{token:"regexp.keyword.operator",regex:"\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",next:"regex_character_class"},{token:"string.regexp.charachterclass",regex:"]",next:"regex",merge:!0},{token:"string.regexp.charachterclass",regex:"[^\\\\\\]]+",next:"regex_character_class",merge:!0},{token:"empty",regex:"",next:"start"}],comment_regex_allowed:[{token:"comment",regex:".*?\\*\\/",merge:!0,next:"regex_allowed"},{token:"comment",merge:!0,regex:".+"}],comment:[{token:"comment",regex:".*?\\*\\/",merge:!0,next:"start"},{token:"comment",merge:!0,regex:".+"}],qqstring:[{token:"string",regex:'(?:(?:\\\\.)|(?:[^"\\\\]))*?"',next:"start"},{token:"string",merge:!0,regex:".+"}],qstring:[{token:"string",regex:"(?:(?:\\\\.)|(?:[^'\\\\]))*?'",next:"start"},{token:"string",merge:!0,regex:".+"}]},this.embedRules(g,"doc-",[(new g).getEndRule("start")])};d.inherits(i,h),b.JavaScriptHighlightRules=i}),define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text_highlight_rules").TextHighlightRules,f=function(){this.$rules={start:[{token:"comment.doc.tag",regex:"@[\\w\\d_]+"},{token:"comment.doc",merge:!0,regex:"\\s+"},{token:"comment.doc",merge:!0,regex:"TODO"},{token:"comment.doc",merge:!0,regex:"[^@\\*]+"},{token:"comment.doc",merge:!0,regex:"."}]}};d.inherits(f,e),function(){this.getStartRule=function(a){return{token:"comment.doc",merge:!0,regex:"\\/\\*(?=\\*)",next:a}},this.getEndRule=function(a){return{token:"comment.doc",merge:!0,regex:"\\*\\/",next:a}}}.call(f.prototype),b.DocCommentHighlightRules=f}),define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"],function(a,b,c){"use strict";var d=a("../range").Range,e=function(){};((function(){this.checkOutdent=function(a,b){return/^\s+$/.test(a)?/^\s*\}/.test(b):!1},this.autoOutdent=function(a,b){var c=a.getLine(b),e=c.match(/^(\s*\})/);if(!e)return 0;var f=e[1].length,g=a.findMatchingBracket({row:b,column:f});if(!g||g.row==b)return 0;var h=this.$getIndent(a.getLine(g.row));a.replace(new d(b,0,b,f-1),h)},this.$getIndent=function(a){var b=a.match(/^(\s+)/);return b?b[1]:""}})).call(e.prototype),b.MatchingBraceOutdent=e}),define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("../lib/event_emitter").EventEmitter,f=function(b,d,e,f){this.changeListener=this.changeListener.bind(this);if(c.packaged){var g=this.$guessBasePath();this.$worker=new Worker(g+d)}else{var h=this.$normalizePath(a.nameToUrl("ace/worker/worker",null,"_"));this.$worker=new Worker(h);var i={};for(var j=0;j<b.length;j++){var k=b[j],l=this.$normalizePath(a.nameToUrl(k,null,"_").replace(/.js$/,""));i[k]=l}}this.$worker.postMessage({init:!0,tlns:i,module:e,classname:f}),this.callbackId=1,this.callbacks={};var m=this;this.$worker.onerror=function(a){throw window.console&&console.log&&console.log(a),a},this.$worker.onmessage=function(a){var b=a.data;switch(b.type){case"log":window.console&&console.log&&console.log(b.data);break;case"event":m._emit(b.name,{data:b.data});break;case"call":var c=m.callbacks[b.id];c&&(c(b.data),delete m.callbacks[b.id])}}};((function(){d.implement(this,e),this.$normalizePath=function(a){return a=a.replace(/^[a-z]+:\/\/[^\/]+\//,""),a=location.protocol+"//"+location.host+(a.charAt(0)=="/"?"":location.pathname.replace(/\/[^\/]*$/,""))+"/"+a.replace(/^[\/]+/,""),a},this.$guessBasePath=function(){if(a.aceBaseUrl)return a.aceBaseUrl;var b=document.getElementsByTagName("script");for(var c=0;c<b.length;c++){var d=b[c],e=d.getAttribute("data-ace-base");if(e)return e.replace(/\/*$/,"/");var f=d.src||d.getAttribute("src");if(!f)continue;var g=f.match(/^(?:(.*\/)ace\.js|(.*\/)ace(-uncompressed)?(-noconflict)?\.js)(?:\?|$)/);if(g)return g[1]||g[2]}return""},this.terminate=function(){this._emit("terminate",{}),this.$worker.terminate(),this.$worker=null,this.$doc.removeEventListener("change",this.changeListener),this.$doc=null},this.send=function(a,b){this.$worker.postMessage({command:a,args:b})},this.call=function(a,b,c){if(c){var d=this.callbackId++;this.callbacks[d]=c,b.push(d)}this.send(a,b)},this.emit=function(a,b){try{this.$worker.postMessage({event:a,data:{data:b.data}})}catch(c){}},this.attachToDocument=function(a){this.$doc&&this.terminate(),this.$doc=a,this.call("setValue",[a.getValue()]),a.on("change",this.changeListener)},this.changeListener=function(a){a.range={start:a.data.range.start,end:a.data.range.end},this.emit("change",a)}})).call(f.prototype),b.WorkerClient=f}),define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../behaviour").Behaviour,f=function(){this.add("braces","insertion",function(a,b,c,d,e){if(e=="{"){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);return g!==""?{text:"{"+g+"}",selection:!1}:{text:"{}",selection:[1,1]}}if(e=="}"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j=="}"){var k=d.$findOpeningBracket("}",{column:h.column+1,row:h.row});if(k!==null)return{text:"",selection:[1,1]}}}else if(e=="\n"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j=="}"){var l=d.findMatchingBracket({row:h.row,column:h.column+1});if(!l)return null;var m=this.getNextLineIndent(a,i.substring(0,i.length-1),d.getTabString()),n=this.$getIndent(d.doc.getLine(l.row));return{text:"\n"+m+"\n"+n,selection:[1,m.length,1,m.length]}}}}),this.add("braces","deletion",function(a,b,c,d,e){var f=d.doc.getTextRange(e);if(!e.isMultiLine()&&f=="{"){var g=d.doc.getLine(e.start.row),h=g.substring(e.end.column,e.end.column+1);if(h=="}")return e.end.column++,e}}),this.add("parens","insertion",function(a,b,c,d,e){if(e=="("){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);return g!==""?{text:"("+g+")",selection:!1}:{text:"()",selection:[1,1]}}if(e==")"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j==")"){var k=d.$findOpeningBracket(")",{column:h.column+1,row:h.row});if(k!==null)return{text:"",selection:[1,1]}}}}),this.add("parens","deletion",function(a,b,c,d,e){var f=d.doc.getTextRange(e);if(!e.isMultiLine()&&f=="("){var g=d.doc.getLine(e.start.row),h=g.substring(e.start.column+1,e.start.column+2);if(h==")")return e.end.column++,e}}),this.add("string_dquotes","insertion",function(a,b,c,d,e){if(e=='"'){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);if(g!=="")return{text:'"'+g+'"',selection:!1};var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column-1,h.column);if(j=="\\")return null;var k=d.getTokens(f.start.row,f.start.row)[0].tokens,l=0,m,n=-1;for(var o=0;o<k.length;o++){m=k[o],m.type=="string"?n=-1:n<0&&(n=m.value.indexOf('"'));if(m.value.length+l>f.start.column)break;l+=k[o].value.length}if(!m||n<0&&m.type!=="comment"&&(m.type!=="string"||f.start.column!==m.value.length+l-1&&m.value.lastIndexOf('"')===m.value.length-1))return{text:'""',selection:[1,1]};if(m&&m.type==="string"){var p=i.substring(h.column,h.column+1);if(p=='"')return{text:"",selection:[1,1]}}}}),this.add("string_dquotes","deletion",function(a,b,c,d,e){var f=d.doc.getTextRange(e);if(!e.isMultiLine()&&f=='"'){var g=d.doc.getLine(e.start.row),h=g.substring(e.start.column+1,e.start.column+2);if(h=='"')return e.end.column++,e}})};d.inherits(f,e),b.CstyleBehaviour=f}),define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../../range").Range,f=a("./fold_mode").FoldMode,g=b.FoldMode=function(){};d.inherits(g,f),function(){this.foldingStartMarker=/(\{|\[)[^\}\]]*$|^\s*(\/\*)/,this.foldingStopMarker=/^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/,this.getFoldWidgetRange=function(a,b,c){var d=a.getLine(c),f=d.match(this.foldingStartMarker);if(f){var g=f.index;if(f[1])return this.openingBracketBlock(a,f[1],c,g);var h=a.getCommentFoldRange(c,g+f[0].length);return h.end.column-=2,h}if(b!=="markbeginend")return;var f=d.match(this.foldingStopMarker);if(f){var g=f.index+f[0].length;if(f[2]){var h=a.getCommentFoldRange(c,g);return h.end.column-=2,h}var i={row:c,column:g},j=a.$findOpeningBracket(f[1],i);if(!j)return;return j.column++,i.column--,e.fromPoints(j,i)}}}.call(g.prototype)}),define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"],function(a,b,c){"use strict";var d=a("../../range").Range,e=b.FoldMode=function(){};((function(){this.foldingStartMarker=null,this.foldingStopMarker=null,this.getFoldWidget=function(a,b,c){var d=a.getLine(c);return this.foldingStartMarker.test(d)?"start":b=="markbeginend"&&this.foldingStopMarker&&this.foldingStopMarker.test(d)?"end":""},this.getFoldWidgetRange=function(a,b,c){return null},this.indentationBlock=function(a,b,c){var e=/^\s*/,f=b,g=b,h=a.getLine(b),i=c||h.length,j=h.match(e)[0].length,k=a.getLength();while(++b<k){h=a.getLine(b);var l=h.match(e)[0].length;if(l==h.length)continue;if(l<=j)break;g=b}if(g>f){var m=a.getLine(g).length;return new d(f,i,g,m)}},this.openingBracketBlock=function(a,b,c,e){var f={row:c,column:e+1},g=a.$findClosingBracket(b,f);if(!g)return;var h=a.foldWidgets[g.row];return h==null&&(h=this.getFoldWidget(a,g.row)),h=="start"&&(g.row--,g.column=a.getLine(g.row).length),d.fromPoints(f,g)}})).call(e.prototype)}),define("ace/mode/css",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/css_highlight_rules","ace/mode/matching_brace_outdent","ace/worker/worker_client","ace/mode/folding/cstyle"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("../tokenizer").Tokenizer,g=a("./css_highlight_rules").CssHighlightRules,h=a("./matching_brace_outdent").MatchingBraceOutdent,i=a("../worker/worker_client").WorkerClient,j=a("./folding/cstyle").FoldMode,k=function(){this.$tokenizer=new f((new g).getRules(),"i"),this.$outdent=new h,this.foldingRules=new j};d.inherits(k,e),function(){this.foldingRules="cStyle",this.getNextLineIndent=function(a,b,c){var d=this.$getIndent(b),e=this.$tokenizer.getLineTokens(b,a).tokens;if(e.length&&e[e.length-1].type=="comment")return d;var f=b.match(/^.*\{\s*$/);return f&&(d+=c),d},this.checkOutdent=function(a,b,c){return this.$outdent.checkOutdent(b,c)},this.autoOutdent=function(a,b,c){this.$outdent.autoOutdent(b,c)},this.createWorker=function(a){var b=new i(["ace"],"worker-css.js","ace/mode/css_worker","Worker");return b.attachToDocument(a.getDocument()),b.on("csslint",function(b){var c=[];b.data.forEach(function(a){c.push({row:a.line-1,column:a.col-1,text:a.message,type:a.type,lint:a})}),a.setAnnotations(c)}),b}}.call(k.prototype),b.Mode=k}),define("ace/mode/css_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("../lib/lang"),f=a("./text_highlight_rules").TextHighlightRules,g=function(){var a=e.arrayToMap("-moz-appearance|-moz-box-sizing|-webkit-box-sizing|-moz-outline-radius|-moz-transform|-webkit-transform|appearance|azimuth|background-attachment|background-color|background-image|background-origin|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-bottom|border-collapse|border-color|border-left-color|border-left-style|border-left-width|border-left|border-right-color|border-right-style|border-right-width|border-right|border-spacing|border-style|border-top-color|border-top-style|border-top-width|border-top|border-width|border|bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size-adjust|font-size|font-stretch|font-style|font-variant|font-weight|font|height|left|letter-spacing|line-height|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|marker-offset|margin|marks|max-height|max-width|min-height|min-width|-moz-border-radius|opacity|orphans|outline-color|outline-offset|outline-radius|outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page|pause-after|pause-before|pause|pitch-range|pitch|play-during|pointer-events|position|quotes|resize|richness|right|size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|transform|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|z-index".split("|")),b=e.arrayToMap("rgb|rgba|url|attr|counter|counters".split("|")),c=e.arrayToMap("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|decimal-leading-zero|decimal|default|disabled|disc|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|inactive|inherit|inline-block|inline|inset|inside|inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|keep-all|left|lighter|line-edge|line-through|line|list-item|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|solid|square|static|strict|super|sw-resize|table-footer-group|table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|zero".split("|")),d=e.arrayToMap("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow".split("|")),f="\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))",g=[{token:"comment",merge:!0,regex:"\\/\\*",next:"ruleset_comment"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"constant.numeric",regex:f+"(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"},{token:"constant.numeric",regex:"#[a-f0-9]{6}"},{token:"constant.numeric",regex:"#[a-f0-9]{3}"},{token:function(e){return a.hasOwnProperty(e.toLowerCase())?"support.type":b.hasOwnProperty(e.toLowerCase())?"support.function":c.hasOwnProperty(e.toLowerCase())?"support.constant":d.hasOwnProperty(e.toLowerCase())?"support.constant.color":"text"},regex:"\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"}],h=e.copyArray(g);h.unshift({token:"paren.rparen",regex:"\\}",next:"start"});var i=e.copyArray(g);i.unshift({token:"paren.rparen",regex:"\\}",next:"media"});var j=[{token:"comment",merge:!0,regex:".+"}],k=e.copyArray(j);k.unshift({token:"comment",regex:".*?\\*\\/",next:"start"});var l=e.copyArray(j);l.unshift({token:"comment",regex:".*?\\*\\/",next:"media"});var m=e.copyArray(j);m.unshift({token:"comment",regex:".*?\\*\\/",next:"ruleset"}),this.$rules={start:[{token:"comment",merge:!0,regex:"\\/\\*",next:"comment"},{token:"paren.lparen",regex:"\\{",next:"ruleset"},{token:"string",regex:"@.*?{",next:"media"},{token:"keyword",regex:"#[a-z0-9-_]+"},{token:"variable",regex:"\\.[a-z0-9-_]+"},{token:"string",regex:":[a-z0-9-_]+"},{token:"constant",regex:"[a-z0-9-_]+"}],media:[{token:"comment",merge:!0,regex:"\\/\\*",next:"media_comment"},{token:"paren.lparen",regex:"\\{",next:"media_ruleset"},{token:"string",regex:"\\}",next:"start"},{token:"keyword",regex:"#[a-z0-9-_]+"},{token:"variable",regex:"\\.[a-z0-9-_]+"},{token:"string",regex:":[a-z0-9-_]+"},{token:"constant",regex:"[a-z0-9-_]+"}],comment:k,ruleset:h,ruleset_comment:m,media_ruleset:i,media_comment:l}};d.inherits(g,f),b.CssHighlightRules=g}),define("ace/mode/html_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/css_highlight_rules","ace/mode/javascript_highlight_rules","ace/mode/xml_util","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./css_highlight_rules").CssHighlightRules,f=a("./javascript_highlight_rules").JavaScriptHighlightRules,g=a("./xml_util"),h=a("./text_highlight_rules").TextHighlightRules,i=function(){this.$rules={start:[{token:"text",merge:!0,regex:"<\\!\\[CDATA\\[",next:"cdata"},{token:"xml_pe",regex:"<\\?.*?\\?>"},{token:"comment",merge:!0,regex:"<\\!--",next:"comment"},{token:"meta.tag",regex:"<(?=s*script\\b)",next:"script"},{token:"meta.tag",regex:"<(?=s*style\\b)",next:"css"},{token:"meta.tag",regex:"<\\/?",next:"tag"},{token:"text",regex:"\\s+"},{token:"text",regex:"[^<]+"}],cdata:[{token:"text",regex:"\\]\\]>",next:"start"},{token:"text",merge:!0,regex:"\\s+"},{token:"text",merge:!0,regex:".+"}],comment:[{token:"comment",regex:".*?-->",next:"start"},{token:"comment",merge:!0,regex:".+"}]},g.tag(this.$rules,"tag","start"),g.tag(this.$rules,"css","css-start"),g.tag(this.$rules,"script","js-start"),this.embedRules(f,"js-",[{token:"comment",regex:"\\/\\/.*(?=<\\/script>)",next:"tag"},{token:"meta.tag",regex:"<\\/(?=script)",next:"tag"}]),this.embedRules(e,"css-",[{token:"meta.tag",regex:"<\\/(?=style)",next:"tag"}])};d.inherits(i,h),b.HtmlHighlightRules=i}),define("ace/mode/xml_util",["require","exports","module","ace/lib/lang"],function(a,b,c){function g(a){return[{token:"string",regex:'".*?"'},{token:"string",merge:!0,regex:'["].*',next:a+"-qqstring"},{token:"string",regex:"'.*?'"},{token:"string",merge:!0,regex:"['].*",next:a+"-qstring"}]}function h(a,b){return[{token:"string",merge:!0,regex:".*?"+a,next:b},{token:"string",merge:!0,regex:".+"}]}"use strict";var d=a("../lib/lang"),e=d.arrayToMap("button|form|input|label|select|textarea".split("|")),f=d.arrayToMap("table|tbody|td|tfoot|th|tr".split("|"));b.tag=function(a,b,c){a[b]=[{token:"text",regex:"\\s+"},{token:function(a){return a==="a"?"meta.tag.anchor":a==="img"?"meta.tag.image":a==="script"?"meta.tag.script":a==="style"?"meta.tag.style":e.hasOwnProperty(a.toLowerCase())?"meta.tag.form":f.hasOwnProperty(a.toLowerCase())?"meta.tag.table":"meta.tag"},merge:!0,regex:"[-_a-zA-Z0-9:!]+",next:b+"embed-attribute-list"},{token:"empty",regex:"",next:b+"embed-attribute-list"}],a[b+"-qstring"]=h("'",b+"embed-attribute-list"),a[b+"-qqstring"]=h('"',b+"embed-attribute-list"),a[b+"embed-attribute-list"]=[{token:"meta.tag",merge:!0,regex:"/?>",next:c},{token:"keyword.operator",regex:"="},{token:"entity.other.attribute-name",regex:"[-_a-zA-Z0-9:]+"},{token:"constant.numeric",regex:"[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"},{token:"text",regex:"\\s+"}].concat(g(b))}}),define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/mode/behaviour/cstyle"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../behaviour").Behaviour,f=a("./cstyle").CstyleBehaviour,g=function(){this.inherit(f,["string_dquotes"]),this.add("brackets","insertion",function(a,b,c,d,e){if(e=="<"){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);return g!==""?!1:{text:"<>",selection:[1,1]}}if(e==">"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j==">")return{text:"",selection:[1,1]}}else if(e=="\n"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),k=i.substring(h.column,h.column+2);if(k=="</"){var l=this.$getIndent(d.doc.getLine(h.row))+d.getTabString(),m=this.$getIndent(d.doc.getLine(h.row));return{text:"\n"+l+"\n"+m,selection:[1,l.length,1,l.length]}}}})};d.inherits(g,e),b.XmlBehaviour=g}),define("ace/mode/folding/html",["require","exports","module","ace/lib/oop","ace/mode/folding/mixed","ace/mode/folding/xml","ace/mode/folding/cstyle"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("./mixed").FoldMode,f=a("./xml").FoldMode,g=a("./cstyle").FoldMode,h=b.FoldMode=function(){e.call(this,new f({area:1,base:1,br:1,col:1,command:1,embed:1,hr:1,img:1,input:1,keygen:1,link:1,meta:1,param:1,source:1,track:1,wbr:1,li:1,dt:1,dd:1,p:1,rt:1,rp:1,optgroup:1,option:1,colgroup:1,td:1,th:1}),{"js-":new g,"css-":new g})};d.inherits(h,e)}),define("ace/mode/folding/mixed",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("./fold_mode").FoldMode,f=b.FoldMode=function(a,b){this.defaultMode=a,this.subModes=b};d.inherits(f,e),function(){this.$getMode=function(a){for(var b in this.subModes)if(a.indexOf(b)===0)return this.subModes[b];return null},this.$tryMode=function(a,b,c,d){var e=this.$getMode(a);return e?e.getFoldWidget(b,c,d):""},this.getFoldWidget=function(a,b,c){return this.$tryMode(a.getState(c-1),a,b,c)||this.$tryMode(a.getState(c),a,b,c)||this.defaultMode.getFoldWidget(a,b,c)},this.getFoldWidgetRange=function(a,b,c){var d=this.$getMode(a.getState(c-1));if(!d||!d.getFoldWidget(a,b,c))d=this.$getMode(a.getState(c));if(!d||!d.getFoldWidget(a,b,c))d=this.defaultMode;return d.getFoldWidgetRange(a,b,c)}}.call(f.prototype)}),define("ace/mode/folding/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/range","ace/mode/folding/fold_mode","ace/token_iterator"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../../lib/lang"),f=a("../../range").Range,g=a("./fold_mode").FoldMode,h=a("../../token_iterator").TokenIterator,i=b.FoldMode=function(a){g.call(this),this.voidElements=a||{}};d.inherits(i,g),function(){this.getFoldWidget=function(a,b,c){var d=this._getFirstTagInLine(a,c);return d.closing?b=="markbeginend"?"end":"":!d.tagName||this.voidElements[d.tagName.toLowerCase()]?"":d.selfClosing?"":d.value.indexOf("/"+d.tagName)!==-1?"":"start"},this._getFirstTagInLine=function(a,b){var c=a.getTokens(b,b)[0].tokens,d="";for(var f=0;f<c.length;f++){var g=c[f];g.type.indexOf("meta.tag")===0?d+=g.value:d+=e.stringRepeat(" ",g.value.length)}return this._parseTag(d)},this.tagRe=/^(\s*)(<?(\/?)([-_a-zA-Z0-9:!]*)\s*(\/?)>?)/,this._parseTag=function(a){var b=this.tagRe.exec(a),c=this.tagRe.lastIndex||0;return this.tagRe.lastIndex=0,{value:a,match:b?b[2]:"",closing:b?!!b[3]:!1,selfClosing:b?!!b[5]||b[2]=="/>":!1,tagName:b?b[4]:"",column:b[1]?c+b[1].length:c}},this._readTagForward=function(a){var b=a.getCurrentToken();if(!b)return null;var c="",d;do if(b.type.indexOf("meta.tag")===0){if(!d)var d={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()};c+=b.value;if(c.indexOf(">")!==-1){var e=this._parseTag(c);return e.start=d,e.end={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()+b.value.length},a.stepForward(),e}}while(b=a.stepForward());return null},this._readTagBackward=function(a){var b=a.getCurrentToken();if(!b)return null;var c="",d;do if(b.type.indexOf("meta.tag")===0){d||(d={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()+b.value.length}),c=b.value+c;if(c.indexOf("<")!==-1){var e=this._parseTag(c);return e.end=d,e.start={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()},a.stepBackward(),e}}while(b=a.stepBackward());return null},this._pop=function(a,b){while(a.length){var c=a[a.length-1];if(!b||c.tagName==b.tagName)return a.pop();if(this.voidElements[b.tagName])return;if(this.voidElements[c.tagName]){a.pop();continue}return null}},this.getFoldWidgetRange=function(a,b,c){var d=this._getFirstTagInLine(a,c);if(!d.match)return null;var e=d.closing||d.selfClosing,g=[],i;if(!e){var j=new h(a,c,d.column),k={row:c,column:d.column+d.tagName.length+2};while(i=this._readTagForward(j)){if(i.selfClosing){if(!g.length)return i.start.column+=i.tagName.length+2,i.end.column-=2,f.fromPoints(i.start,i.end);continue}if(i.closing){this._pop(g,i);if(g.length==0)return f.fromPoints(k,i.start)}else g.push(i)}}else{var j=new h(a,c,d.column+d.match.length),l={row:c,column:d.column};while(i=this._readTagBackward(j)){if(i.selfClosing){if(!g.length)return i.start.column+=i.tagName.length+2,i.end.column-=2,f.fromPoints(i.start,i.end);continue}if(!i.closing){this._pop(g,i);if(g.length==0)return i.start.column+=i.tagName.length+2,f.fromPoints(i.start,l)}else g.push(i)}}}}.call(i.prototype)}),function(){window.require(["ace/ace"],function(a){window.ace||(window.ace={});for(var b in a)a.hasOwnProperty(b)&&(ace[b]=a[b])})}() No newline at end of file |
@@ -0,0 +1,1 b'' | |||||
|
1 | define("ace/mode/markdown",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/javascript","ace/mode/xml","ace/mode/html","ace/tokenizer","ace/mode/markdown_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("./javascript").Mode,g=a("./xml").Mode,h=a("./html").Mode,i=a("../tokenizer").Tokenizer,j=a("./markdown_highlight_rules").MarkdownHighlightRules,k=function(){var a=new j;this.$tokenizer=new i(a.getRules()),this.$embeds=a.getEmbeds(),this.createModeDelegates({"js-":f,"xml-":g,"html-":h})};d.inherits(k,e),function(){this.getNextLineIndent=function(a,b,c){if(a=="listblock"){var d=/^((?:.+)?)([-+*][ ]+)/.exec(b);return d?(new Array(d[1].length+1)).join(" ")+d[2]:""}return this.$getIndent(b)}}.call(k.prototype),b.Mode=k}),define("ace/mode/javascript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/javascript_highlight_rules","ace/mode/matching_brace_outdent","ace/range","ace/worker/worker_client","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("../tokenizer").Tokenizer,g=a("./javascript_highlight_rules").JavaScriptHighlightRules,h=a("./matching_brace_outdent").MatchingBraceOutdent,i=a("../range").Range,j=a("../worker/worker_client").WorkerClient,k=a("./behaviour/cstyle").CstyleBehaviour,l=a("./folding/cstyle").FoldMode,m=function(){this.$tokenizer=new f((new g).getRules()),this.$outdent=new h,this.$behaviour=new k,this.foldingRules=new l};d.inherits(m,e),function(){this.toggleCommentLines=function(a,b,c,d){var e=!0,f=/^(\s*)\/\//;for(var g=c;g<=d;g++)if(!f.test(b.getLine(g))){e=!1;break}if(e){var h=new i(0,0,0,0);for(var g=c;g<=d;g++){var j=b.getLine(g),k=j.match(f);h.start.row=g,h.end.row=g,h.end.column=k[0].length,b.replace(h,k[1])}}else b.indentRows(c,d,"//")},this.getNextLineIndent=function(a,b,c){var d=this.$getIndent(b),e=this.$tokenizer.getLineTokens(b,a),f=e.tokens,g=e.state;if(f.length&&f[f.length-1].type=="comment")return d;if(a=="start"||a=="regex_allowed"){var h=b.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);h&&(d+=c)}else if(a=="doc-start"){if(g=="start"||a=="regex_allowed")return"";var h=b.match(/^\s*(\/?)\*/);h&&(h[1]&&(d+=" "),d+="* ")}return d},this.checkOutdent=function(a,b,c){return this.$outdent.checkOutdent(b,c)},this.autoOutdent=function(a,b,c){this.$outdent.autoOutdent(b,c)},this.createWorker=function(a){var b=new j(["ace"],"worker-javascript.js","ace/mode/javascript_worker","JavaScriptWorker");return b.attachToDocument(a.getDocument()),b.on("jslint",function(b){var c=[];for(var d=0;d<b.data.length;d++){var e=b.data[d];e&&c.push({row:e.line-1,column:e.character-1,text:e.reason,type:"warning",lint:e})}a.setAnnotations(c)}),b.on("narcissus",function(b){a.setAnnotations([b.data])}),b.on("terminate",function(){a.clearAnnotations()}),b}}.call(m.prototype),b.Mode=m}),define("ace/mode/javascript_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/unicode","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("../lib/lang"),f=a("../unicode"),g=a("./doc_comment_highlight_rules").DocCommentHighlightRules,h=a("./text_highlight_rules").TextHighlightRules,i=function(){var a=e.arrayToMap("Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|Namespace|QName|XML|XMLList|ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt|JSON|Math|this|arguments|prototype|window|document".split("|")),b=e.arrayToMap("break|case|catch|continue|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|const|yield|import|get|set".split("|")),c="case|do|else|finally|in|instanceof|return|throw|try|typeof|yield",d=e.arrayToMap("__parent__|__count__|escape|unescape|with|__proto__".split("|")),h=e.arrayToMap("const|let|var|function".split("|")),i=e.arrayToMap("null|Infinity|NaN|undefined".split("|")),j=e.arrayToMap("class|enum|extends|super|export|implements|private|public|interface|package|protected|static".split("|")),k="["+f.packages.L+"\\$_]["+f.packages.L+f.packages.Mn+f.packages.Mc+f.packages.Nd+f.packages.Pc+"\\$_]*\\b";this.$rules={start:[{token:"comment",regex:"\\/\\/.*$"},(new g).getStartRule("doc-start"),{token:"comment",merge:!0,regex:"\\/\\*",next:"comment"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",merge:!0,regex:'["].*\\\\$',next:"qqstring"},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"string",merge:!0,regex:"['].*\\\\$",next:"qstring"},{token:"constant.numeric",regex:"0[xX][0-9a-fA-F]+\\b"},{token:"constant.numeric",regex:"[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"},{token:["keyword.definition","text","entity.name.function"],regex:"(function)(\\s+)("+k+")"},{token:"constant.language.boolean",regex:"(?:true|false)\\b"},{token:"keyword",regex:"(?:"+c+")\\b",next:"regex_allowed"},{token:function(c){return a.hasOwnProperty(c)?"variable.language":d.hasOwnProperty(c)?"invalid.deprecated":h.hasOwnProperty(c)?"keyword.definition":b.hasOwnProperty(c)?"keyword":i.hasOwnProperty(c)?"constant.language":j.hasOwnProperty(c)?"invalid.illegal":c=="debugger"?"invalid.deprecated":"identifier"},regex:k},{token:"keyword.operator",regex:"!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)",next:"regex_allowed"},{token:"punctuation.operator",regex:"\\?|\\:|\\,|\\;|\\.",next:"regex_allowed"},{token:"paren.lparen",regex:"[[({]",next:"regex_allowed"},{token:"paren.rparen",regex:"[\\])}]"},{token:"keyword.operator",regex:"\\/=?",next:"regex_allowed"},{token:"comment",regex:"^#!.*$"},{token:"text",regex:"\\s+"}],regex_allowed:[{token:"comment",merge:!0,regex:"\\/\\*",next:"comment_regex_allowed"},{token:"comment",regex:"\\/\\/.*$"},{token:"string.regexp",regex:"\\/",next:"regex",merge:!0},{token:"text",regex:"\\s+"},{token:"empty",regex:"",next:"start"}],regex:[{token:"regexp.keyword.operator",regex:"\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",next:"regex"},{token:"string.regexp",regex:"/\\w*",next:"start",merge:!0},{token:"string.regexp",regex:"[^\\\\/\\[]+",next:"regex",merge:!0},{token:"string.regexp.charachterclass",regex:"\\[",next:"regex_character_class",merge:!0},{token:"empty",regex:"",next:"start"}],regex_character_class:[{token:"regexp.keyword.operator",regex:"\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",next:"regex_character_class"},{token:"string.regexp.charachterclass",regex:"]",next:"regex",merge:!0},{token:"string.regexp.charachterclass",regex:"[^\\\\\\]]+",next:"regex_character_class",merge:!0},{token:"empty",regex:"",next:"start"}],comment_regex_allowed:[{token:"comment",regex:".*?\\*\\/",merge:!0,next:"regex_allowed"},{token:"comment",merge:!0,regex:".+"}],comment:[{token:"comment",regex:".*?\\*\\/",merge:!0,next:"start"},{token:"comment",merge:!0,regex:".+"}],qqstring:[{token:"string",regex:'(?:(?:\\\\.)|(?:[^"\\\\]))*?"',next:"start"},{token:"string",merge:!0,regex:".+"}],qstring:[{token:"string",regex:"(?:(?:\\\\.)|(?:[^'\\\\]))*?'",next:"start"},{token:"string",merge:!0,regex:".+"}]},this.embedRules(g,"doc-",[(new g).getEndRule("start")])};d.inherits(i,h),b.JavaScriptHighlightRules=i}),define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text_highlight_rules").TextHighlightRules,f=function(){this.$rules={start:[{token:"comment.doc.tag",regex:"@[\\w\\d_]+"},{token:"comment.doc",merge:!0,regex:"\\s+"},{token:"comment.doc",merge:!0,regex:"TODO"},{token:"comment.doc",merge:!0,regex:"[^@\\*]+"},{token:"comment.doc",merge:!0,regex:"."}]}};d.inherits(f,e),function(){this.getStartRule=function(a){return{token:"comment.doc",merge:!0,regex:"\\/\\*(?=\\*)",next:a}},this.getEndRule=function(a){return{token:"comment.doc",merge:!0,regex:"\\*\\/",next:a}}}.call(f.prototype),b.DocCommentHighlightRules=f}),define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"],function(a,b,c){"use strict";var d=a("../range").Range,e=function(){};((function(){this.checkOutdent=function(a,b){return/^\s+$/.test(a)?/^\s*\}/.test(b):!1},this.autoOutdent=function(a,b){var c=a.getLine(b),e=c.match(/^(\s*\})/);if(!e)return 0;var f=e[1].length,g=a.findMatchingBracket({row:b,column:f});if(!g||g.row==b)return 0;var h=this.$getIndent(a.getLine(g.row));a.replace(new d(b,0,b,f-1),h)},this.$getIndent=function(a){var b=a.match(/^(\s+)/);return b?b[1]:""}})).call(e.prototype),b.MatchingBraceOutdent=e}),define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("../lib/event_emitter").EventEmitter,f=function(b,d,e,f){this.changeListener=this.changeListener.bind(this);if(c.packaged){var g=this.$guessBasePath();this.$worker=new Worker(g+d)}else{var h=this.$normalizePath(a.nameToUrl("ace/worker/worker",null,"_"));this.$worker=new Worker(h);var i={};for(var j=0;j<b.length;j++){var k=b[j],l=this.$normalizePath(a.nameToUrl(k,null,"_").replace(/.js$/,""));i[k]=l}}this.$worker.postMessage({init:!0,tlns:i,module:e,classname:f}),this.callbackId=1,this.callbacks={};var m=this;this.$worker.onerror=function(a){throw window.console&&console.log&&console.log(a),a},this.$worker.onmessage=function(a){var b=a.data;switch(b.type){case"log":window.console&&console.log&&console.log(b.data);break;case"event":m._emit(b.name,{data:b.data});break;case"call":var c=m.callbacks[b.id];c&&(c(b.data),delete m.callbacks[b.id])}}};((function(){d.implement(this,e),this.$normalizePath=function(a){return a=a.replace(/^[a-z]+:\/\/[^\/]+\//,""),a=location.protocol+"//"+location.host+(a.charAt(0)=="/"?"":location.pathname.replace(/\/[^\/]*$/,""))+"/"+a.replace(/^[\/]+/,""),a},this.$guessBasePath=function(){if(a.aceBaseUrl)return a.aceBaseUrl;var b=document.getElementsByTagName("script");for(var c=0;c<b.length;c++){var d=b[c],e=d.getAttribute("data-ace-base");if(e)return e.replace(/\/*$/,"/");var f=d.src||d.getAttribute("src");if(!f)continue;var g=f.match(/^(?:(.*\/)ace\.js|(.*\/)ace(-uncompressed)?(-noconflict)?\.js)(?:\?|$)/);if(g)return g[1]||g[2]}return""},this.terminate=function(){this._emit("terminate",{}),this.$worker.terminate(),this.$worker=null,this.$doc.removeEventListener("change",this.changeListener),this.$doc=null},this.send=function(a,b){this.$worker.postMessage({command:a,args:b})},this.call=function(a,b,c){if(c){var d=this.callbackId++;this.callbacks[d]=c,b.push(d)}this.send(a,b)},this.emit=function(a,b){try{this.$worker.postMessage({event:a,data:{data:b.data}})}catch(c){}},this.attachToDocument=function(a){this.$doc&&this.terminate(),this.$doc=a,this.call("setValue",[a.getValue()]),a.on("change",this.changeListener)},this.changeListener=function(a){a.range={start:a.data.range.start,end:a.data.range.end},this.emit("change",a)}})).call(f.prototype),b.WorkerClient=f}),define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../behaviour").Behaviour,f=function(){this.add("braces","insertion",function(a,b,c,d,e){if(e=="{"){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);return g!==""?{text:"{"+g+"}",selection:!1}:{text:"{}",selection:[1,1]}}if(e=="}"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j=="}"){var k=d.$findOpeningBracket("}",{column:h.column+1,row:h.row});if(k!==null)return{text:"",selection:[1,1]}}}else if(e=="\n"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j=="}"){var l=d.findMatchingBracket({row:h.row,column:h.column+1});if(!l)return null;var m=this.getNextLineIndent(a,i.substring(0,i.length-1),d.getTabString()),n=this.$getIndent(d.doc.getLine(l.row));return{text:"\n"+m+"\n"+n,selection:[1,m.length,1,m.length]}}}}),this.add("braces","deletion",function(a,b,c,d,e){var f=d.doc.getTextRange(e);if(!e.isMultiLine()&&f=="{"){var g=d.doc.getLine(e.start.row),h=g.substring(e.end.column,e.end.column+1);if(h=="}")return e.end.column++,e}}),this.add("parens","insertion",function(a,b,c,d,e){if(e=="("){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);return g!==""?{text:"("+g+")",selection:!1}:{text:"()",selection:[1,1]}}if(e==")"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j==")"){var k=d.$findOpeningBracket(")",{column:h.column+1,row:h.row});if(k!==null)return{text:"",selection:[1,1]}}}}),this.add("parens","deletion",function(a,b,c,d,e){var f=d.doc.getTextRange(e);if(!e.isMultiLine()&&f=="("){var g=d.doc.getLine(e.start.row),h=g.substring(e.start.column+1,e.start.column+2);if(h==")")return e.end.column++,e}}),this.add("string_dquotes","insertion",function(a,b,c,d,e){if(e=='"'){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);if(g!=="")return{text:'"'+g+'"',selection:!1};var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column-1,h.column);if(j=="\\")return null;var k=d.getTokens(f.start.row,f.start.row)[0].tokens,l=0,m,n=-1;for(var o=0;o<k.length;o++){m=k[o],m.type=="string"?n=-1:n<0&&(n=m.value.indexOf('"'));if(m.value.length+l>f.start.column)break;l+=k[o].value.length}if(!m||n<0&&m.type!=="comment"&&(m.type!=="string"||f.start.column!==m.value.length+l-1&&m.value.lastIndexOf('"')===m.value.length-1))return{text:'""',selection:[1,1]};if(m&&m.type==="string"){var p=i.substring(h.column,h.column+1);if(p=='"')return{text:"",selection:[1,1]}}}}),this.add("string_dquotes","deletion",function(a,b,c,d,e){var f=d.doc.getTextRange(e);if(!e.isMultiLine()&&f=='"'){var g=d.doc.getLine(e.start.row),h=g.substring(e.start.column+1,e.start.column+2);if(h=='"')return e.end.column++,e}})};d.inherits(f,e),b.CstyleBehaviour=f}),define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../../range").Range,f=a("./fold_mode").FoldMode,g=b.FoldMode=function(){};d.inherits(g,f),function(){this.foldingStartMarker=/(\{|\[)[^\}\]]*$|^\s*(\/\*)/,this.foldingStopMarker=/^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/,this.getFoldWidgetRange=function(a,b,c){var d=a.getLine(c),f=d.match(this.foldingStartMarker);if(f){var g=f.index;if(f[1])return this.openingBracketBlock(a,f[1],c,g);var h=a.getCommentFoldRange(c,g+f[0].length);return h.end.column-=2,h}if(b!=="markbeginend")return;var f=d.match(this.foldingStopMarker);if(f){var g=f.index+f[0].length;if(f[2]){var h=a.getCommentFoldRange(c,g);return h.end.column-=2,h}var i={row:c,column:g},j=a.$findOpeningBracket(f[1],i);if(!j)return;return j.column++,i.column--,e.fromPoints(j,i)}}}.call(g.prototype)}),define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"],function(a,b,c){"use strict";var d=a("../../range").Range,e=b.FoldMode=function(){};((function(){this.foldingStartMarker=null,this.foldingStopMarker=null,this.getFoldWidget=function(a,b,c){var d=a.getLine(c);return this.foldingStartMarker.test(d)?"start":b=="markbeginend"&&this.foldingStopMarker&&this.foldingStopMarker.test(d)?"end":""},this.getFoldWidgetRange=function(a,b,c){return null},this.indentationBlock=function(a,b,c){var e=/^\s*/,f=b,g=b,h=a.getLine(b),i=c||h.length,j=h.match(e)[0].length,k=a.getLength();while(++b<k){h=a.getLine(b);var l=h.match(e)[0].length;if(l==h.length)continue;if(l<=j)break;g=b}if(g>f){var m=a.getLine(g).length;return new d(f,i,g,m)}},this.openingBracketBlock=function(a,b,c,e){var f={row:c,column:e+1},g=a.$findClosingBracket(b,f);if(!g)return;var h=a.foldWidgets[g.row];return h==null&&(h=this.getFoldWidget(a,g.row)),h=="start"&&(g.row--,g.column=a.getLine(g.row).length),d.fromPoints(f,g)}})).call(e.prototype)}),define("ace/mode/xml",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/xml_highlight_rules","ace/mode/behaviour/xml","ace/mode/folding/xml"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("../tokenizer").Tokenizer,g=a("./xml_highlight_rules").XmlHighlightRules,h=a("./behaviour/xml").XmlBehaviour,i=a("./folding/xml").FoldMode,j=function(){this.$tokenizer=new f((new g).getRules()),this.$behaviour=new h,this.foldingRules=new i};d.inherits(j,e),function(){this.getNextLineIndent=function(a,b,c){return this.$getIndent(b)}}.call(j.prototype),b.Mode=j}),define("ace/mode/xml_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/xml_util","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./xml_util"),f=a("./text_highlight_rules").TextHighlightRules,g=function(){this.$rules={start:[{token:"text",regex:"<\\!\\[CDATA\\[",next:"cdata"},{token:"xml_pe",regex:"<\\?.*?\\?>"},{token:"comment",merge:!0,regex:"<\\!--",next:"comment"},{token:"meta.tag",regex:"<\\/?",next:"tag"},{token:"text",regex:"\\s+"},{token:"text",regex:"[^<]+"}],cdata:[{token:"text",regex:"\\]\\]>",next:"start"},{token:"text",regex:"\\s+"},{token:"text",regex:"(?:[^\\]]|\\](?!\\]>))+"}],comment:[{token:"comment",regex:".*?-->",next:"start"},{token:"comment",merge:!0,regex:".+"}]},e.tag(this.$rules,"tag","start")};d.inherits(g,f),b.XmlHighlightRules=g}),define("ace/mode/xml_util",["require","exports","module","ace/lib/lang"],function(a,b,c){function g(a){return[{token:"string",regex:'".*?"'},{token:"string",merge:!0,regex:'["].*',next:a+"-qqstring"},{token:"string",regex:"'.*?'"},{token:"string",merge:!0,regex:"['].*",next:a+"-qstring"}]}function h(a,b){return[{token:"string",merge:!0,regex:".*?"+a,next:b},{token:"string",merge:!0,regex:".+"}]}"use strict";var d=a("../lib/lang"),e=d.arrayToMap("button|form|input|label|select|textarea".split("|")),f=d.arrayToMap("table|tbody|td|tfoot|th|tr".split("|"));b.tag=function(a,b,c){a[b]=[{token:"text",regex:"\\s+"},{token:function(a){return a==="a"?"meta.tag.anchor":a==="img"?"meta.tag.image":a==="script"?"meta.tag.script":a==="style"?"meta.tag.style":e.hasOwnProperty(a.toLowerCase())?"meta.tag.form":f.hasOwnProperty(a.toLowerCase())?"meta.tag.table":"meta.tag"},merge:!0,regex:"[-_a-zA-Z0-9:!]+",next:b+"embed-attribute-list"},{token:"empty",regex:"",next:b+"embed-attribute-list"}],a[b+"-qstring"]=h("'",b+"embed-attribute-list"),a[b+"-qqstring"]=h('"',b+"embed-attribute-list"),a[b+"embed-attribute-list"]=[{token:"meta.tag",merge:!0,regex:"/?>",next:c},{token:"keyword.operator",regex:"="},{token:"entity.other.attribute-name",regex:"[-_a-zA-Z0-9:]+"},{token:"constant.numeric",regex:"[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"},{token:"text",regex:"\\s+"}].concat(g(b))}}),define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/mode/behaviour/cstyle"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../behaviour").Behaviour,f=a("./cstyle").CstyleBehaviour,g=function(){this.inherit(f,["string_dquotes"]),this.add("brackets","insertion",function(a,b,c,d,e){if(e=="<"){var f=c.getSelectionRange(),g=d.doc.getTextRange(f);return g!==""?!1:{text:"<>",selection:[1,1]}}if(e==">"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),j=i.substring(h.column,h.column+1);if(j==">")return{text:"",selection:[1,1]}}else if(e=="\n"){var h=c.getCursorPosition(),i=d.doc.getLine(h.row),k=i.substring(h.column,h.column+2);if(k=="</"){var l=this.$getIndent(d.doc.getLine(h.row))+d.getTabString(),m=this.$getIndent(d.doc.getLine(h.row));return{text:"\n"+l+"\n"+m,selection:[1,l.length,1,l.length]}}}})};d.inherits(g,e),b.XmlBehaviour=g}),define("ace/mode/folding/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/range","ace/mode/folding/fold_mode","ace/token_iterator"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("../../lib/lang"),f=a("../../range").Range,g=a("./fold_mode").FoldMode,h=a("../../token_iterator").TokenIterator,i=b.FoldMode=function(a){g.call(this),this.voidElements=a||{}};d.inherits(i,g),function(){this.getFoldWidget=function(a,b,c){var d=this._getFirstTagInLine(a,c);return d.closing?b=="markbeginend"?"end":"":!d.tagName||this.voidElements[d.tagName.toLowerCase()]?"":d.selfClosing?"":d.value.indexOf("/"+d.tagName)!==-1?"":"start"},this._getFirstTagInLine=function(a,b){var c=a.getTokens(b,b)[0].tokens,d="";for(var f=0;f<c.length;f++){var g=c[f];g.type.indexOf("meta.tag")===0?d+=g.value:d+=e.stringRepeat(" ",g.value.length)}return this._parseTag(d)},this.tagRe=/^(\s*)(<?(\/?)([-_a-zA-Z0-9:!]*)\s*(\/?)>?)/,this._parseTag=function(a){var b=this.tagRe.exec(a),c=this.tagRe.lastIndex||0;return this.tagRe.lastIndex=0,{value:a,match:b?b[2]:"",closing:b?!!b[3]:!1,selfClosing:b?!!b[5]||b[2]=="/>":!1,tagName:b?b[4]:"",column:b[1]?c+b[1].length:c}},this._readTagForward=function(a){var b=a.getCurrentToken();if(!b)return null;var c="",d;do if(b.type.indexOf("meta.tag")===0){if(!d)var d={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()};c+=b.value;if(c.indexOf(">")!==-1){var e=this._parseTag(c);return e.start=d,e.end={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()+b.value.length},a.stepForward(),e}}while(b=a.stepForward());return null},this._readTagBackward=function(a){var b=a.getCurrentToken();if(!b)return null;var c="",d;do if(b.type.indexOf("meta.tag")===0){d||(d={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()+b.value.length}),c=b.value+c;if(c.indexOf("<")!==-1){var e=this._parseTag(c);return e.end=d,e.start={row:a.getCurrentTokenRow(),column:a.getCurrentTokenColumn()},a.stepBackward(),e}}while(b=a.stepBackward());return null},this._pop=function(a,b){while(a.length){var c=a[a.length-1];if(!b||c.tagName==b.tagName)return a.pop();if(this.voidElements[b.tagName])return;if(this.voidElements[c.tagName]){a.pop();continue}return null}},this.getFoldWidgetRange=function(a,b,c){var d=this._getFirstTagInLine(a,c);if(!d.match)return null;var e=d.closing||d.selfClosing,g=[],i;if(!e){var j=new h(a,c,d.column),k={row:c,column:d.column+d.tagName.length+2};while(i=this._readTagForward(j)){if(i.selfClosing){if(!g.length)return i.start.column+=i.tagName.length+2,i.end.column-=2,f.fromPoints(i.start,i.end);continue}if(i.closing){this._pop(g,i);if(g.length==0)return f.fromPoints(k,i.start)}else g.push(i)}}else{var j=new h(a,c,d.column+d.match.length),l={row:c,column:d.column};while(i=this._readTagBackward(j)){if(i.selfClosing){if(!g.length)return i.start.column+=i.tagName.length+2,i.end.column-=2,f.fromPoints(i.start,i.end);continue}if(!i.closing){this._pop(g,i);if(g.length==0)return i.start.column+=i.tagName.length+2,f.fromPoints(i.start,l)}else g.push(i)}}}}.call(i.prototype)}),define("ace/mode/html",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/javascript","ace/mode/css","ace/tokenizer","ace/mode/html_highlight_rules","ace/mode/behaviour/xml","ace/mode/folding/html"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("./javascript").Mode,g=a("./css").Mode,h=a("../tokenizer").Tokenizer,i=a("./html_highlight_rules").HtmlHighlightRules,j=a("./behaviour/xml").XmlBehaviour,k=a("./folding/html").FoldMode,l=function(){var a=new i;this.$tokenizer=new h(a.getRules()),this.$behaviour=new j,this.$embeds=a.getEmbeds(),this.createModeDelegates({"js-":f,"css-":g}),this.foldingRules=new k};d.inherits(l,e),function(){this.toggleCommentLines=function(a,b,c,d){return 0},this.getNextLineIndent=function(a,b,c){return this.$getIndent(b)},this.checkOutdent=function(a,b,c){return!1}}.call(l.prototype),b.Mode=l}),define("ace/mode/css",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/css_highlight_rules","ace/mode/matching_brace_outdent","ace/worker/worker_client","ace/mode/folding/cstyle"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./text").Mode,f=a("../tokenizer").Tokenizer,g=a("./css_highlight_rules").CssHighlightRules,h=a("./matching_brace_outdent").MatchingBraceOutdent,i=a("../worker/worker_client").WorkerClient,j=a("./folding/cstyle").FoldMode,k=function(){this.$tokenizer=new f((new g).getRules(),"i"),this.$outdent=new h,this.foldingRules=new j};d.inherits(k,e),function(){this.foldingRules="cStyle",this.getNextLineIndent=function(a,b,c){var d=this.$getIndent(b),e=this.$tokenizer.getLineTokens(b,a).tokens;if(e.length&&e[e.length-1].type=="comment")return d;var f=b.match(/^.*\{\s*$/);return f&&(d+=c),d},this.checkOutdent=function(a,b,c){return this.$outdent.checkOutdent(b,c)},this.autoOutdent=function(a,b,c){this.$outdent.autoOutdent(b,c)},this.createWorker=function(a){var b=new i(["ace"],"worker-css.js","ace/mode/css_worker","Worker");return b.attachToDocument(a.getDocument()),b.on("csslint",function(b){var c=[];b.data.forEach(function(a){c.push({row:a.line-1,column:a.col-1,text:a.message,type:a.type,lint:a})}),a.setAnnotations(c)}),b}}.call(k.prototype),b.Mode=k}),define("ace/mode/css_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("../lib/lang"),f=a("./text_highlight_rules").TextHighlightRules,g=function(){var a=e.arrayToMap("-moz-appearance|-moz-box-sizing|-webkit-box-sizing|-moz-outline-radius|-moz-transform|-webkit-transform|appearance|azimuth|background-attachment|background-color|background-image|background-origin|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-bottom|border-collapse|border-color|border-left-color|border-left-style|border-left-width|border-left|border-right-color|border-right-style|border-right-width|border-right|border-spacing|border-style|border-top-color|border-top-style|border-top-width|border-top|border-width|border|bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size-adjust|font-size|font-stretch|font-style|font-variant|font-weight|font|height|left|letter-spacing|line-height|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|marker-offset|margin|marks|max-height|max-width|min-height|min-width|-moz-border-radius|opacity|orphans|outline-color|outline-offset|outline-radius|outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page|pause-after|pause-before|pause|pitch-range|pitch|play-during|pointer-events|position|quotes|resize|richness|right|size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|transform|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|z-index".split("|")),b=e.arrayToMap("rgb|rgba|url|attr|counter|counters".split("|")),c=e.arrayToMap("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|decimal-leading-zero|decimal|default|disabled|disc|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|inactive|inherit|inline-block|inline|inset|inside|inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|keep-all|left|lighter|line-edge|line-through|line|list-item|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|solid|square|static|strict|super|sw-resize|table-footer-group|table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|zero".split("|")),d=e.arrayToMap("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow".split("|")),f="\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))",g=[{token:"comment",merge:!0,regex:"\\/\\*",next:"ruleset_comment"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"constant.numeric",regex:f+"(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"},{token:"constant.numeric",regex:"#[a-f0-9]{6}"},{token:"constant.numeric",regex:"#[a-f0-9]{3}"},{token:function(e){return a.hasOwnProperty(e.toLowerCase())?"support.type":b.hasOwnProperty(e.toLowerCase())?"support.function":c.hasOwnProperty(e.toLowerCase())?"support.constant":d.hasOwnProperty(e.toLowerCase())?"support.constant.color":"text"},regex:"\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"}],h=e.copyArray(g);h.unshift({token:"paren.rparen",regex:"\\}",next:"start"});var i=e.copyArray(g);i.unshift({token:"paren.rparen",regex:"\\}",next:"media"});var j=[{token:"comment",merge:!0,regex:".+"}],k=e.copyArray(j);k.unshift({token:"comment",regex:".*?\\*\\/",next:"start"});var l=e.copyArray(j);l.unshift({token:"comment",regex:".*?\\*\\/",next:"media"});var m=e.copyArray(j);m.unshift({token:"comment",regex:".*?\\*\\/",next:"ruleset"}),this.$rules={start:[{token:"comment",merge:!0,regex:"\\/\\*",next:"comment"},{token:"paren.lparen",regex:"\\{",next:"ruleset"},{token:"string",regex:"@.*?{",next:"media"},{token:"keyword",regex:"#[a-z0-9-_]+"},{token:"variable",regex:"\\.[a-z0-9-_]+"},{token:"string",regex:":[a-z0-9-_]+"},{token:"constant",regex:"[a-z0-9-_]+"}],media:[{token:"comment",merge:!0,regex:"\\/\\*",next:"media_comment"},{token:"paren.lparen",regex:"\\{",next:"media_ruleset"},{token:"string",regex:"\\}",next:"start"},{token:"keyword",regex:"#[a-z0-9-_]+"},{token:"variable",regex:"\\.[a-z0-9-_]+"},{token:"string",regex:":[a-z0-9-_]+"},{token:"constant",regex:"[a-z0-9-_]+"}],comment:k,ruleset:h,ruleset_comment:m,media_ruleset:i,media_comment:l}};d.inherits(g,f),b.CssHighlightRules=g}),define("ace/mode/html_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/css_highlight_rules","ace/mode/javascript_highlight_rules","ace/mode/xml_util","ace/mode/text_highlight_rules"],function(a,b,c){"use strict";var d=a("../lib/oop"),e=a("./css_highlight_rules").CssHighlightRules,f=a("./javascript_highlight_rules").JavaScriptHighlightRules,g=a("./xml_util"),h=a("./text_highlight_rules").TextHighlightRules,i=function(){this.$rules={start:[{token:"text",merge:!0,regex:"<\\!\\[CDATA\\[",next:"cdata"},{token:"xml_pe",regex:"<\\?.*?\\?>"},{token:"comment",merge:!0,regex:"<\\!--",next:"comment"},{token:"meta.tag",regex:"<(?=s*script\\b)",next:"script"},{token:"meta.tag",regex:"<(?=s*style\\b)",next:"css"},{token:"meta.tag",regex:"<\\/?",next:"tag"},{token:"text",regex:"\\s+"},{token:"text",regex:"[^<]+"}],cdata:[{token:"text",regex:"\\]\\]>",next:"start"},{token:"text",merge:!0,regex:"\\s+"},{token:"text",merge:!0,regex:".+"}],comment:[{token:"comment",regex:".*?-->",next:"start"},{token:"comment",merge:!0,regex:".+"}]},g.tag(this.$rules,"tag","start"),g.tag(this.$rules,"css","css-start"),g.tag(this.$rules,"script","js-start"),this.embedRules(f,"js-",[{token:"comment",regex:"\\/\\/.*(?=<\\/script>)",next:"tag"},{token:"meta.tag",regex:"<\\/(?=script)",next:"tag"}]),this.embedRules(e,"css-",[{token:"meta.tag",regex:"<\\/(?=style)",next:"tag"}])};d.inherits(i,h),b.HtmlHighlightRules=i}),define("ace/mode/folding/html",["require","exports","module","ace/lib/oop","ace/mode/folding/mixed","ace/mode/folding/xml","ace/mode/folding/cstyle"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("./mixed").FoldMode,f=a("./xml").FoldMode,g=a("./cstyle").FoldMode,h=b.FoldMode=function(){e.call(this,new f({area:1,base:1,br:1,col:1,command:1,embed:1,hr:1,img:1,input:1,keygen:1,link:1,meta:1,param:1,source:1,track:1,wbr:1,li:1,dt:1,dd:1,p:1,rt:1,rp:1,optgroup:1,option:1,colgroup:1,td:1,th:1}),{"js-":new g,"css-":new g})};d.inherits(h,e)}),define("ace/mode/folding/mixed",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode"],function(a,b,c){"use strict";var d=a("../../lib/oop"),e=a("./fold_mode").FoldMode,f=b.FoldMode=function(a,b){this.defaultMode=a,this.subModes=b};d.inherits(f,e),function(){this.$getMode=function(a){for(var b in this.subModes)if(a.indexOf(b)===0)return this.subModes[b];return null},this.$tryMode=function(a,b,c,d){var e=this.$getMode(a);return e?e.getFoldWidget(b,c,d):""},this.getFoldWidget=function(a,b,c){return this.$tryMode(a.getState(c-1),a,b,c)||this.$tryMode(a.getState(c),a,b,c)||this.defaultMode.getFoldWidget(a,b,c)},this.getFoldWidgetRange=function(a,b,c){var d=this.$getMode(a.getState(c-1));if(!d||!d.getFoldWidget(a,b,c))d=this.$getMode(a.getState(c));if(!d||!d.getFoldWidget(a,b,c))d=this.defaultMode;return d.getFoldWidgetRange(a,b,c)}}.call(f.prototype)}),define("ace/mode/markdown_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules","ace/mode/javascript_highlight_rules","ace/mode/xml_highlight_rules","ace/mode/html_highlight_rules","ace/mode/css_highlight_rules"],function(a,b,c){function j(a,b){return{token:"support.function",regex:"^```"+a+"\\s*$",next:b+"start"}}"use strict";var d=a("../lib/oop"),e=a("./text_highlight_rules").TextHighlightRules,f=a("./javascript_highlight_rules").JavaScriptHighlightRules,g=a("./xml_highlight_rules").XmlHighlightRules,h=a("./html_highlight_rules").HtmlHighlightRules,i=a("./css_highlight_rules").CssHighlightRules,k=function(){this.$rules={start:[{token:"empty_line",regex:"^$"},{token:"support.function",regex:"(`+)([^\\r]*?[^`])(\\1)"},{token:"support.function",regex:"^[ ]{4}.+"},{token:"markup.heading.1",regex:"^=+(?=\\s*$)"},{token:"markup.heading.1",regex:"^\\-+(?=\\s*$)"},{token:function(a){return"markup.heading."+a.length},regex:"^#{1,6}"},j("javascript","js-"),j("xml","xml-"),j("html","html-"),j("css","css-"),{token:"support.function",regex:"^```[a-zA-Z]+\\s*$",next:"githubblock"},{token:"string",regex:"^>[ ].+$",next:"blockquote"},{token:["text","constant","text","url","string","text"],regex:'^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:["][^"]+["])?\\s*)$'},{token:["text","string","text","constant","text"],regex:"(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])"},{token:["text","string","text","markup.underline","string","text"],regex:'(\\[)(\\[[^\\]]*\\]|[^\\[\\]]*)(\\]\\([ \\t]*)(<?(?:(?:[^\\(]*?\\([^\\)]*?\\)\\S*?)|(?:.*?))>?)((?:[ \t]*"(?:.*?)"[ \\t]*)?)(\\))'},{token:"constant",regex:"^[ ]{0,2}(?:[ ]?\\*[ ]?){3,}\\s*$"},{token:"constant",regex:"^[ ]{0,2}(?:[ ]?\\-[ ]?){3,}\\s*$"},{token:"constant",regex:"^[ ]{0,2}(?:[ ]?\\_[ ]?){3,}\\s*$"},{token:"markup.list",regex:"^\\s{0,3}(?:[*+-]|\\d+\\.)\\s+",next:"listblock"},{token:"string",regex:"([*]{2}|[_]{2}(?=\\S))([^\\r]*?\\S[*_]*)(\\1)"},{token:"string",regex:"([*]|[_](?=\\S))([^\\r]*?\\S[*_]*)(\\1)"},{token:["text","url","text"],regex:"(<)((?:https?|ftp|dict):[^'\">\\s]+|(?:mailto:)?[-.\\w]+\\@[-a-z0-9]+(?:\\.[-a-z0-9]+)*\\.[a-z]+)(>)"},{token:"text",regex:"[^\\*_%$`\\[#<>]+"}],listblock:[{token:"empty_line",regex:"^$",next:"start"},{token:"markup.list",regex:".+"}],blockquote:[{token:"empty_line",regex:"^\\s*$",next:"start"},{token:"string",regex:".+"}],githubblock:[{token:"support.function",regex:"^```",next:"start"},{token:"support.function",regex:".+"}]},this.embedRules(f,"js-",[{token:"support.function",regex:"^```",next:"start"}]),this.embedRules(h,"html-",[{token:"support.function",regex:"^```",next:"start"}]),this.embedRules(i,"css-",[{token:"support.function",regex:"^```",next:"start"}]),this.embedRules(g,"xml-",[{token:"support.function",regex:"^```",next:"start"}])};d.inherits(k,e),b.MarkdownHighlightRules=k}),function(){window.require(["ace/ace"],function(a){window.ace||(window.ace={});for(var b in a)a.hasOwnProperty(b)&&(ace[b]=a[b])})}() No newline at end of file |
@@ -0,0 +1,23 b'' | |||||
|
1 | .CodeMirror-dialog { | |||
|
2 | position: relative; | |||
|
3 | } | |||
|
4 | ||||
|
5 | .CodeMirror-dialog > div { | |||
|
6 | position: absolute; | |||
|
7 | top: 0; left: 0; right: 0; | |||
|
8 | background: white; | |||
|
9 | border-bottom: 1px solid #eee; | |||
|
10 | z-index: 15; | |||
|
11 | padding: .1em .8em; | |||
|
12 | overflow: hidden; | |||
|
13 | color: #333; | |||
|
14 | } | |||
|
15 | ||||
|
16 | .CodeMirror-dialog input { | |||
|
17 | border: none; | |||
|
18 | outline: none; | |||
|
19 | background: transparent; | |||
|
20 | width: 20em; | |||
|
21 | color: inherit; | |||
|
22 | font-family: monospace; | |||
|
23 | } |
@@ -0,0 +1,63 b'' | |||||
|
1 | // Open simple dialogs on top of an editor. Relies on dialog.css. | |||
|
2 | ||||
|
3 | (function() { | |||
|
4 | function dialogDiv(cm, template) { | |||
|
5 | var wrap = cm.getWrapperElement(); | |||
|
6 | var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild); | |||
|
7 | dialog.className = "CodeMirror-dialog"; | |||
|
8 | dialog.innerHTML = '<div>' + template + '</div>'; | |||
|
9 | return dialog; | |||
|
10 | } | |||
|
11 | ||||
|
12 | CodeMirror.defineExtension("openDialog", function(template, callback) { | |||
|
13 | var dialog = dialogDiv(this, template); | |||
|
14 | var closed = false, me = this; | |||
|
15 | function close() { | |||
|
16 | if (closed) return; | |||
|
17 | closed = true; | |||
|
18 | dialog.parentNode.removeChild(dialog); | |||
|
19 | } | |||
|
20 | var inp = dialog.getElementsByTagName("input")[0]; | |||
|
21 | if (inp) { | |||
|
22 | CodeMirror.connect(inp, "keydown", function(e) { | |||
|
23 | if (e.keyCode == 13 || e.keyCode == 27) { | |||
|
24 | CodeMirror.e_stop(e); | |||
|
25 | close(); | |||
|
26 | me.focus(); | |||
|
27 | if (e.keyCode == 13) callback(inp.value); | |||
|
28 | } | |||
|
29 | }); | |||
|
30 | inp.focus(); | |||
|
31 | CodeMirror.connect(inp, "blur", close); | |||
|
32 | } | |||
|
33 | return close; | |||
|
34 | }); | |||
|
35 | ||||
|
36 | CodeMirror.defineExtension("openConfirm", function(template, callbacks) { | |||
|
37 | var dialog = dialogDiv(this, template); | |||
|
38 | var buttons = dialog.getElementsByTagName("button"); | |||
|
39 | var closed = false, me = this, blurring = 1; | |||
|
40 | function close() { | |||
|
41 | if (closed) return; | |||
|
42 | closed = true; | |||
|
43 | dialog.parentNode.removeChild(dialog); | |||
|
44 | me.focus(); | |||
|
45 | } | |||
|
46 | buttons[0].focus(); | |||
|
47 | for (var i = 0; i < buttons.length; ++i) { | |||
|
48 | var b = buttons[i]; | |||
|
49 | (function(callback) { | |||
|
50 | CodeMirror.connect(b, "click", function(e) { | |||
|
51 | CodeMirror.e_preventDefault(e); | |||
|
52 | close(); | |||
|
53 | if (callback) callback(me); | |||
|
54 | }); | |||
|
55 | })(callbacks[i]); | |||
|
56 | CodeMirror.connect(b, "blur", function() { | |||
|
57 | --blurring; | |||
|
58 | setTimeout(function() { if (blurring <= 0) close(); }, 200); | |||
|
59 | }); | |||
|
60 | CodeMirror.connect(b, "focus", function() { ++blurring; }); | |||
|
61 | } | |||
|
62 | }); | |||
|
63 | })(); No newline at end of file |
@@ -0,0 +1,66 b'' | |||||
|
1 | CodeMirror.braceRangeFinder = function(cm, line) { | |||
|
2 | var lineText = cm.getLine(line); | |||
|
3 | var startChar = lineText.lastIndexOf("{"); | |||
|
4 | if (startChar < 0 || lineText.lastIndexOf("}") > startChar) return; | |||
|
5 | var tokenType = cm.getTokenAt({line: line, ch: startChar}).className; | |||
|
6 | var count = 1, lastLine = cm.lineCount(), end; | |||
|
7 | outer: for (var i = line + 1; i < lastLine; ++i) { | |||
|
8 | var text = cm.getLine(i), pos = 0; | |||
|
9 | for (;;) { | |||
|
10 | var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos); | |||
|
11 | if (nextOpen < 0) nextOpen = text.length; | |||
|
12 | if (nextClose < 0) nextClose = text.length; | |||
|
13 | pos = Math.min(nextOpen, nextClose); | |||
|
14 | if (pos == text.length) break; | |||
|
15 | if (cm.getTokenAt({line: i, ch: pos + 1}).className == tokenType) { | |||
|
16 | if (pos == nextOpen) ++count; | |||
|
17 | else if (!--count) { end = i; break outer; } | |||
|
18 | } | |||
|
19 | ++pos; | |||
|
20 | } | |||
|
21 | } | |||
|
22 | if (end == null || end == line + 1) return; | |||
|
23 | return end; | |||
|
24 | }; | |||
|
25 | ||||
|
26 | ||||
|
27 | CodeMirror.newFoldFunction = function(rangeFinder, markText) { | |||
|
28 | var folded = []; | |||
|
29 | if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">▼</div>%N%'; | |||
|
30 | ||||
|
31 | function isFolded(cm, n) { | |||
|
32 | for (var i = 0; i < folded.length; ++i) { | |||
|
33 | var start = cm.lineInfo(folded[i].start); | |||
|
34 | if (!start) folded.splice(i--, 1); | |||
|
35 | else if (start.line == n) return {pos: i, region: folded[i]}; | |||
|
36 | } | |||
|
37 | } | |||
|
38 | ||||
|
39 | function expand(cm, region) { | |||
|
40 | cm.clearMarker(region.start); | |||
|
41 | for (var i = 0; i < region.hidden.length; ++i) | |||
|
42 | cm.showLine(region.hidden[i]); | |||
|
43 | } | |||
|
44 | ||||
|
45 | return function(cm, line) { | |||
|
46 | cm.operation(function() { | |||
|
47 | var known = isFolded(cm, line); | |||
|
48 | if (known) { | |||
|
49 | folded.splice(known.pos, 1); | |||
|
50 | expand(cm, known.region); | |||
|
51 | } else { | |||
|
52 | var end = rangeFinder(cm, line); | |||
|
53 | if (end == null) return; | |||
|
54 | var hidden = []; | |||
|
55 | for (var i = line + 1; i < end; ++i) { | |||
|
56 | var handle = cm.hideLine(i); | |||
|
57 | if (handle) hidden.push(handle); | |||
|
58 | } | |||
|
59 | var first = cm.setMarker(line, markText); | |||
|
60 | var region = {start: first, hidden: hidden}; | |||
|
61 | cm.onDeleteLine(first, function() { expand(cm, region); }); | |||
|
62 | folded.push(region); | |||
|
63 | } | |||
|
64 | }); | |||
|
65 | }; | |||
|
66 | }; |
@@ -0,0 +1,291 b'' | |||||
|
1 | // ============== Formatting extensions ============================ | |||
|
2 | // A common storage for all mode-specific formatting features | |||
|
3 | if (!CodeMirror.modeExtensions) CodeMirror.modeExtensions = {}; | |||
|
4 | ||||
|
5 | // Returns the extension of the editor's current mode | |||
|
6 | CodeMirror.defineExtension("getModeExt", function () { | |||
|
7 | return CodeMirror.modeExtensions[this.getOption("mode")]; | |||
|
8 | }); | |||
|
9 | ||||
|
10 | // If the current mode is 'htmlmixed', returns the extension of a mode located at | |||
|
11 | // the specified position (can be htmlmixed, css or javascript). Otherwise, simply | |||
|
12 | // returns the extension of the editor's current mode. | |||
|
13 | CodeMirror.defineExtension("getModeExtAtPos", function (pos) { | |||
|
14 | var token = this.getTokenAt(pos); | |||
|
15 | if (token && token.state && token.state.mode) | |||
|
16 | return CodeMirror.modeExtensions[token.state.mode == "html" ? "htmlmixed" : token.state.mode]; | |||
|
17 | else | |||
|
18 | return this.getModeExt(); | |||
|
19 | }); | |||
|
20 | ||||
|
21 | // Comment/uncomment the specified range | |||
|
22 | CodeMirror.defineExtension("commentRange", function (isComment, from, to) { | |||
|
23 | var curMode = this.getModeExtAtPos(this.getCursor()); | |||
|
24 | if (isComment) { // Comment range | |||
|
25 | var commentedText = this.getRange(from, to); | |||
|
26 | this.replaceRange(curMode.commentStart + this.getRange(from, to) + curMode.commentEnd | |||
|
27 | , from, to); | |||
|
28 | if (from.line == to.line && from.ch == to.ch) { // An empty comment inserted - put cursor inside | |||
|
29 | this.setCursor(from.line, from.ch + curMode.commentStart.length); | |||
|
30 | } | |||
|
31 | } | |||
|
32 | else { // Uncomment range | |||
|
33 | var selText = this.getRange(from, to); | |||
|
34 | var startIndex = selText.indexOf(curMode.commentStart); | |||
|
35 | var endIndex = selText.lastIndexOf(curMode.commentEnd); | |||
|
36 | if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) { | |||
|
37 | // Take string till comment start | |||
|
38 | selText = selText.substr(0, startIndex) | |||
|
39 | // From comment start till comment end | |||
|
40 | + selText.substring(startIndex + curMode.commentStart.length, endIndex) | |||
|
41 | // From comment end till string end | |||
|
42 | + selText.substr(endIndex + curMode.commentEnd.length); | |||
|
43 | } | |||
|
44 | this.replaceRange(selText, from, to); | |||
|
45 | } | |||
|
46 | }); | |||
|
47 | ||||
|
48 | // Applies automatic mode-aware indentation to the specified range | |||
|
49 | CodeMirror.defineExtension("autoIndentRange", function (from, to) { | |||
|
50 | var cmInstance = this; | |||
|
51 | this.operation(function () { | |||
|
52 | for (var i = from.line; i <= to.line; i++) { | |||
|
53 | cmInstance.indentLine(i); | |||
|
54 | } | |||
|
55 | }); | |||
|
56 | }); | |||
|
57 | ||||
|
58 | // Applies automatic formatting to the specified range | |||
|
59 | CodeMirror.defineExtension("autoFormatRange", function (from, to) { | |||
|
60 | var absStart = this.indexFromPos(from); | |||
|
61 | var absEnd = this.indexFromPos(to); | |||
|
62 | // Insert additional line breaks where necessary according to the | |||
|
63 | // mode's syntax | |||
|
64 | var res = this.getModeExt().autoFormatLineBreaks(this.getValue(), absStart, absEnd); | |||
|
65 | var cmInstance = this; | |||
|
66 | ||||
|
67 | // Replace and auto-indent the range | |||
|
68 | this.operation(function () { | |||
|
69 | cmInstance.replaceRange(res, from, to); | |||
|
70 | var startLine = cmInstance.posFromIndex(absStart).line; | |||
|
71 | var endLine = cmInstance.posFromIndex(absStart + res.length).line; | |||
|
72 | for (var i = startLine; i <= endLine; i++) { | |||
|
73 | cmInstance.indentLine(i); | |||
|
74 | } | |||
|
75 | }); | |||
|
76 | }); | |||
|
77 | ||||
|
78 | // Define extensions for a few modes | |||
|
79 | ||||
|
80 | CodeMirror.modeExtensions["css"] = { | |||
|
81 | commentStart: "/*", | |||
|
82 | commentEnd: "*/", | |||
|
83 | wordWrapChars: [";", "\\{", "\\}"], | |||
|
84 | autoFormatLineBreaks: function (text) { | |||
|
85 | return text.replace(new RegExp("(;|\\{|\\})([^\r\n])", "g"), "$1\n$2"); | |||
|
86 | } | |||
|
87 | }; | |||
|
88 | ||||
|
89 | CodeMirror.modeExtensions["javascript"] = { | |||
|
90 | commentStart: "/*", | |||
|
91 | commentEnd: "*/", | |||
|
92 | wordWrapChars: [";", "\\{", "\\}"], | |||
|
93 | ||||
|
94 | getNonBreakableBlocks: function (text) { | |||
|
95 | var nonBreakableRegexes = [ | |||
|
96 | new RegExp("for\\s*?\\(([\\s\\S]*?)\\)"), | |||
|
97 | new RegExp("'([\\s\\S]*?)('|$)"), | |||
|
98 | new RegExp("\"([\\s\\S]*?)(\"|$)"), | |||
|
99 | new RegExp("//.*([\r\n]|$)") | |||
|
100 | ]; | |||
|
101 | var nonBreakableBlocks = new Array(); | |||
|
102 | for (var i = 0; i < nonBreakableRegexes.length; i++) { | |||
|
103 | var curPos = 0; | |||
|
104 | while (curPos < text.length) { | |||
|
105 | var m = text.substr(curPos).match(nonBreakableRegexes[i]); | |||
|
106 | if (m != null) { | |||
|
107 | nonBreakableBlocks.push({ | |||
|
108 | start: curPos + m.index, | |||
|
109 | end: curPos + m.index + m[0].length | |||
|
110 | }); | |||
|
111 | curPos += m.index + Math.max(1, m[0].length); | |||
|
112 | } | |||
|
113 | else { // No more matches | |||
|
114 | break; | |||
|
115 | } | |||
|
116 | } | |||
|
117 | } | |||
|
118 | nonBreakableBlocks.sort(function (a, b) { | |||
|
119 | return a.start - b.start; | |||
|
120 | }); | |||
|
121 | ||||
|
122 | return nonBreakableBlocks; | |||
|
123 | }, | |||
|
124 | ||||
|
125 | autoFormatLineBreaks: function (text) { | |||
|
126 | var curPos = 0; | |||
|
127 | var reLinesSplitter = new RegExp("(;|\\{|\\})([^\r\n])", "g"); | |||
|
128 | var nonBreakableBlocks = this.getNonBreakableBlocks(text); | |||
|
129 | if (nonBreakableBlocks != null) { | |||
|
130 | var res = ""; | |||
|
131 | for (var i = 0; i < nonBreakableBlocks.length; i++) { | |||
|
132 | if (nonBreakableBlocks[i].start > curPos) { // Break lines till the block | |||
|
133 | res += text.substring(curPos, nonBreakableBlocks[i].start).replace(reLinesSplitter, "$1\n$2"); | |||
|
134 | curPos = nonBreakableBlocks[i].start; | |||
|
135 | } | |||
|
136 | if (nonBreakableBlocks[i].start <= curPos | |||
|
137 | && nonBreakableBlocks[i].end >= curPos) { // Skip non-breakable block | |||
|
138 | res += text.substring(curPos, nonBreakableBlocks[i].end); | |||
|
139 | curPos = nonBreakableBlocks[i].end; | |||
|
140 | } | |||
|
141 | } | |||
|
142 | if (curPos < text.length - 1) { | |||
|
143 | res += text.substr(curPos).replace(reLinesSplitter, "$1\n$2"); | |||
|
144 | } | |||
|
145 | return res; | |||
|
146 | } | |||
|
147 | else { | |||
|
148 | return text.replace(reLinesSplitter, "$1\n$2"); | |||
|
149 | } | |||
|
150 | } | |||
|
151 | }; | |||
|
152 | ||||
|
153 | CodeMirror.modeExtensions["xml"] = { | |||
|
154 | commentStart: "<!--", | |||
|
155 | commentEnd: "-->", | |||
|
156 | wordWrapChars: [">"], | |||
|
157 | ||||
|
158 | autoFormatLineBreaks: function (text) { | |||
|
159 | var lines = text.split("\n"); | |||
|
160 | var reProcessedPortion = new RegExp("(^\\s*?<|^[^<]*?)(.+)(>\\s*?$|[^>]*?$)"); | |||
|
161 | var reOpenBrackets = new RegExp("<", "g"); | |||
|
162 | var reCloseBrackets = new RegExp("(>)([^\r\n])", "g"); | |||
|
163 | for (var i = 0; i < lines.length; i++) { | |||
|
164 | var mToProcess = lines[i].match(reProcessedPortion); | |||
|
165 | if (mToProcess != null && mToProcess.length > 3) { // The line starts with whitespaces and ends with whitespaces | |||
|
166 | lines[i] = mToProcess[1] | |||
|
167 | + mToProcess[2].replace(reOpenBrackets, "\n$&").replace(reCloseBrackets, "$1\n$2") | |||
|
168 | + mToProcess[3]; | |||
|
169 | continue; | |||
|
170 | } | |||
|
171 | } | |||
|
172 | ||||
|
173 | return lines.join("\n"); | |||
|
174 | } | |||
|
175 | }; | |||
|
176 | ||||
|
177 | CodeMirror.modeExtensions["htmlmixed"] = { | |||
|
178 | commentStart: "<!--", | |||
|
179 | commentEnd: "-->", | |||
|
180 | wordWrapChars: [">", ";", "\\{", "\\}"], | |||
|
181 | ||||
|
182 | getModeInfos: function (text, absPos) { | |||
|
183 | var modeInfos = new Array(); | |||
|
184 | modeInfos[0] = | |||
|
185 | { | |||
|
186 | pos: 0, | |||
|
187 | modeExt: CodeMirror.modeExtensions["xml"], | |||
|
188 | modeName: "xml" | |||
|
189 | }; | |||
|
190 | ||||
|
191 | var modeMatchers = new Array(); | |||
|
192 | modeMatchers[0] = | |||
|
193 | { | |||
|
194 | regex: new RegExp("<style[^>]*>([\\s\\S]*?)(</style[^>]*>|$)", "i"), | |||
|
195 | modeExt: CodeMirror.modeExtensions["css"], | |||
|
196 | modeName: "css" | |||
|
197 | }; | |||
|
198 | modeMatchers[1] = | |||
|
199 | { | |||
|
200 | regex: new RegExp("<script[^>]*>([\\s\\S]*?)(</script[^>]*>|$)", "i"), | |||
|
201 | modeExt: CodeMirror.modeExtensions["javascript"], | |||
|
202 | modeName: "javascript" | |||
|
203 | }; | |||
|
204 | ||||
|
205 | var lastCharPos = (typeof (absPos) !== "undefined" ? absPos : text.length - 1); | |||
|
206 | // Detect modes for the entire text | |||
|
207 | for (var i = 0; i < modeMatchers.length; i++) { | |||
|
208 | var curPos = 0; | |||
|
209 | while (curPos <= lastCharPos) { | |||
|
210 | var m = text.substr(curPos).match(modeMatchers[i].regex); | |||
|
211 | if (m != null) { | |||
|
212 | if (m.length > 1 && m[1].length > 0) { | |||
|
213 | // Push block begin pos | |||
|
214 | var blockBegin = curPos + m.index + m[0].indexOf(m[1]); | |||
|
215 | modeInfos.push( | |||
|
216 | { | |||
|
217 | pos: blockBegin, | |||
|
218 | modeExt: modeMatchers[i].modeExt, | |||
|
219 | modeName: modeMatchers[i].modeName | |||
|
220 | }); | |||
|
221 | // Push block end pos | |||
|
222 | modeInfos.push( | |||
|
223 | { | |||
|
224 | pos: blockBegin + m[1].length, | |||
|
225 | modeExt: modeInfos[0].modeExt, | |||
|
226 | modeName: modeInfos[0].modeName | |||
|
227 | }); | |||
|
228 | curPos += m.index + m[0].length; | |||
|
229 | continue; | |||
|
230 | } | |||
|
231 | else { | |||
|
232 | curPos += m.index + Math.max(m[0].length, 1); | |||
|
233 | } | |||
|
234 | } | |||
|
235 | else { // No more matches | |||
|
236 | break; | |||
|
237 | } | |||
|
238 | } | |||
|
239 | } | |||
|
240 | // Sort mode infos | |||
|
241 | modeInfos.sort(function sortModeInfo(a, b) { | |||
|
242 | return a.pos - b.pos; | |||
|
243 | }); | |||
|
244 | ||||
|
245 | return modeInfos; | |||
|
246 | }, | |||
|
247 | ||||
|
248 | autoFormatLineBreaks: function (text, startPos, endPos) { | |||
|
249 | var modeInfos = this.getModeInfos(text); | |||
|
250 | var reBlockStartsWithNewline = new RegExp("^\\s*?\n"); | |||
|
251 | var reBlockEndsWithNewline = new RegExp("\n\\s*?$"); | |||
|
252 | var res = ""; | |||
|
253 | // Use modes info to break lines correspondingly | |||
|
254 | if (modeInfos.length > 1) { // Deal with multi-mode text | |||
|
255 | for (var i = 1; i <= modeInfos.length; i++) { | |||
|
256 | var selStart = modeInfos[i - 1].pos; | |||
|
257 | var selEnd = (i < modeInfos.length ? modeInfos[i].pos : endPos); | |||
|
258 | ||||
|
259 | if (selStart >= endPos) { // The block starts later than the needed fragment | |||
|
260 | break; | |||
|
261 | } | |||
|
262 | if (selStart < startPos) { | |||
|
263 | if (selEnd <= startPos) { // The block starts earlier than the needed fragment | |||
|
264 | continue; | |||
|
265 | } | |||
|
266 | selStart = startPos; | |||
|
267 | } | |||
|
268 | if (selEnd > endPos) { | |||
|
269 | selEnd = endPos; | |||
|
270 | } | |||
|
271 | var textPortion = text.substring(selStart, selEnd); | |||
|
272 | if (modeInfos[i - 1].modeName != "xml") { // Starting a CSS or JavaScript block | |||
|
273 | if (!reBlockStartsWithNewline.test(textPortion) | |||
|
274 | && selStart > 0) { // The block does not start with a line break | |||
|
275 | textPortion = "\n" + textPortion; | |||
|
276 | } | |||
|
277 | if (!reBlockEndsWithNewline.test(textPortion) | |||
|
278 | && selEnd < text.length - 1) { // The block does not end with a line break | |||
|
279 | textPortion += "\n"; | |||
|
280 | } | |||
|
281 | } | |||
|
282 | res += modeInfos[i - 1].modeExt.autoFormatLineBreaks(textPortion); | |||
|
283 | } | |||
|
284 | } | |||
|
285 | else { // Single-mode text | |||
|
286 | res = modeInfos[0].modeExt.autoFormatLineBreaks(text.substring(startPos, endPos)); | |||
|
287 | } | |||
|
288 | ||||
|
289 | return res; | |||
|
290 | } | |||
|
291 | }; |
@@ -0,0 +1,83 b'' | |||||
|
1 | (function () { | |||
|
2 | function forEach(arr, f) { | |||
|
3 | for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]); | |||
|
4 | } | |||
|
5 | ||||
|
6 | function arrayContains(arr, item) { | |||
|
7 | if (!Array.prototype.indexOf) { | |||
|
8 | var i = arr.length; | |||
|
9 | while (i--) { | |||
|
10 | if (arr[i] === item) { | |||
|
11 | return true; | |||
|
12 | } | |||
|
13 | } | |||
|
14 | return false; | |||
|
15 | } | |||
|
16 | return arr.indexOf(item) != -1; | |||
|
17 | } | |||
|
18 | ||||
|
19 | CodeMirror.javascriptHint = function(editor) { | |||
|
20 | // Find the token at the cursor | |||
|
21 | var cur = editor.getCursor(), token = editor.getTokenAt(cur), tprop = token; | |||
|
22 | // If it's not a 'word-style' token, ignore the token. | |||
|
23 | if (!/^[\w$_]*$/.test(token.string)) { | |||
|
24 | token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state, | |||
|
25 | className: token.string == "." ? "property" : null}; | |||
|
26 | } | |||
|
27 | // If it is a property, find out what it is a property of. | |||
|
28 | while (tprop.className == "property") { | |||
|
29 | tprop = editor.getTokenAt({line: cur.line, ch: tprop.start}); | |||
|
30 | if (tprop.string != ".") return; | |||
|
31 | tprop = editor.getTokenAt({line: cur.line, ch: tprop.start}); | |||
|
32 | if (!context) var context = []; | |||
|
33 | context.push(tprop); | |||
|
34 | } | |||
|
35 | return {list: getCompletions(token, context), | |||
|
36 | from: {line: cur.line, ch: token.start}, | |||
|
37 | to: {line: cur.line, ch: token.end}}; | |||
|
38 | } | |||
|
39 | ||||
|
40 | var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " + | |||
|
41 | "toUpperCase toLowerCase split concat match replace search").split(" "); | |||
|
42 | var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " + | |||
|
43 | "lastIndexOf every some filter forEach map reduce reduceRight ").split(" "); | |||
|
44 | var funcProps = "prototype apply call bind".split(" "); | |||
|
45 | var keywords = ("break case catch continue debugger default delete do else false finally for function " + | |||
|
46 | "if in instanceof new null return switch throw true try typeof var void while with").split(" "); | |||
|
47 | ||||
|
48 | function getCompletions(token, context) { | |||
|
49 | var found = [], start = token.string; | |||
|
50 | function maybeAdd(str) { | |||
|
51 | if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str); | |||
|
52 | } | |||
|
53 | function gatherCompletions(obj) { | |||
|
54 | if (typeof obj == "string") forEach(stringProps, maybeAdd); | |||
|
55 | else if (obj instanceof Array) forEach(arrayProps, maybeAdd); | |||
|
56 | else if (obj instanceof Function) forEach(funcProps, maybeAdd); | |||
|
57 | for (var name in obj) maybeAdd(name); | |||
|
58 | } | |||
|
59 | ||||
|
60 | if (context) { | |||
|
61 | // If this is a property, see if it belongs to some object we can | |||
|
62 | // find in the current environment. | |||
|
63 | var obj = context.pop(), base; | |||
|
64 | if (obj.className == "variable") | |||
|
65 | base = window[obj.string]; | |||
|
66 | else if (obj.className == "string") | |||
|
67 | base = ""; | |||
|
68 | else if (obj.className == "atom") | |||
|
69 | base = 1; | |||
|
70 | while (base != null && context.length) | |||
|
71 | base = base[context.pop().string]; | |||
|
72 | if (base != null) gatherCompletions(base); | |||
|
73 | } | |||
|
74 | else { | |||
|
75 | // If not, just look in the window object and any local scope | |||
|
76 | // (reading into JS mode internals to get at the local variables) | |||
|
77 | for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name); | |||
|
78 | gatherCompletions(window); | |||
|
79 | forEach(keywords, maybeAdd); | |||
|
80 | } | |||
|
81 | return found; | |||
|
82 | } | |||
|
83 | })(); |
@@ -0,0 +1,114 b'' | |||||
|
1 | // Define search commands. Depends on dialog.js or another | |||
|
2 | // implementation of the openDialog method. | |||
|
3 | ||||
|
4 | // Replace works a little oddly -- it will do the replace on the next | |||
|
5 | // Ctrl-G (or whatever is bound to findNext) press. You prevent a | |||
|
6 | // replace by making sure the match is no longer selected when hitting | |||
|
7 | // Ctrl-G. | |||
|
8 | ||||
|
9 | (function() { | |||
|
10 | function SearchState() { | |||
|
11 | this.posFrom = this.posTo = this.query = null; | |||
|
12 | this.marked = []; | |||
|
13 | } | |||
|
14 | function getSearchState(cm) { | |||
|
15 | return cm._searchState || (cm._searchState = new SearchState()); | |||
|
16 | } | |||
|
17 | function dialog(cm, text, shortText, f) { | |||
|
18 | if (cm.openDialog) cm.openDialog(text, f); | |||
|
19 | else f(prompt(shortText, "")); | |||
|
20 | } | |||
|
21 | function confirmDialog(cm, text, shortText, fs) { | |||
|
22 | if (cm.openConfirm) cm.openConfirm(text, fs); | |||
|
23 | else if (confirm(shortText)) fs[0](); | |||
|
24 | } | |||
|
25 | function parseQuery(query) { | |||
|
26 | var isRE = query.match(/^\/(.*)\/$/); | |||
|
27 | return isRE ? new RegExp(isRE[1]) : query; | |||
|
28 | } | |||
|
29 | var queryDialog = | |||
|
30 | 'Search: <input type="text" style="width: 10em"> <span style="color: #888">(Use /re/ syntax for regexp search)</span>'; | |||
|
31 | function doSearch(cm, rev) { | |||
|
32 | var state = getSearchState(cm); | |||
|
33 | if (state.query) return findNext(cm, rev); | |||
|
34 | dialog(cm, queryDialog, "Search for:", function(query) { | |||
|
35 | cm.operation(function() { | |||
|
36 | if (!query || state.query) return; | |||
|
37 | state.query = parseQuery(query); | |||
|
38 | if (cm.lineCount() < 2000) { // This is too expensive on big documents. | |||
|
39 | for (var cursor = cm.getSearchCursor(query); cursor.findNext();) | |||
|
40 | state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching")); | |||
|
41 | } | |||
|
42 | state.posFrom = state.posTo = cm.getCursor(); | |||
|
43 | findNext(cm, rev); | |||
|
44 | }); | |||
|
45 | }); | |||
|
46 | } | |||
|
47 | function findNext(cm, rev) {cm.operation(function() { | |||
|
48 | var state = getSearchState(cm); | |||
|
49 | var cursor = cm.getSearchCursor(state.query, rev ? state.posFrom : state.posTo); | |||
|
50 | if (!cursor.find(rev)) { | |||
|
51 | cursor = cm.getSearchCursor(state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0}); | |||
|
52 | if (!cursor.find(rev)) return; | |||
|
53 | } | |||
|
54 | cm.setSelection(cursor.from(), cursor.to()); | |||
|
55 | state.posFrom = cursor.from(); state.posTo = cursor.to(); | |||
|
56 | })} | |||
|
57 | function clearSearch(cm) {cm.operation(function() { | |||
|
58 | var state = getSearchState(cm); | |||
|
59 | if (!state.query) return; | |||
|
60 | state.query = null; | |||
|
61 | for (var i = 0; i < state.marked.length; ++i) state.marked[i].clear(); | |||
|
62 | state.marked.length = 0; | |||
|
63 | })} | |||
|
64 | ||||
|
65 | var replaceQueryDialog = | |||
|
66 | 'Replace: <input type="text" style="width: 10em"> <span style="color: #888">(Use /re/ syntax for regexp search)</span>'; | |||
|
67 | var replacementQueryDialog = 'With: <input type="text" style="width: 10em">'; | |||
|
68 | var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>"; | |||
|
69 | function replace(cm, all) { | |||
|
70 | dialog(cm, replaceQueryDialog, "Replace:", function(query) { | |||
|
71 | if (!query) return; | |||
|
72 | query = parseQuery(query); | |||
|
73 | dialog(cm, replacementQueryDialog, "Replace with:", function(text) { | |||
|
74 | if (all) { | |||
|
75 | cm.operation(function() { | |||
|
76 | for (var cursor = cm.getSearchCursor(query); cursor.findNext();) { | |||
|
77 | if (typeof query != "string") { | |||
|
78 | var match = cm.getRange(cursor.from(), cursor.to()).match(query); | |||
|
79 | cursor.replace(text.replace(/\$(\d)/, function(w, i) {return match[i];})); | |||
|
80 | } else cursor.replace(text); | |||
|
81 | } | |||
|
82 | }); | |||
|
83 | } else { | |||
|
84 | clearSearch(cm); | |||
|
85 | var cursor = cm.getSearchCursor(query, cm.getCursor()); | |||
|
86 | function advance() { | |||
|
87 | var start = cursor.from(), match; | |||
|
88 | if (!(match = cursor.findNext())) { | |||
|
89 | cursor = cm.getSearchCursor(query); | |||
|
90 | if (!(match = cursor.findNext()) || | |||
|
91 | (cursor.from().line == start.line && cursor.from().ch == start.ch)) return; | |||
|
92 | } | |||
|
93 | cm.setSelection(cursor.from(), cursor.to()); | |||
|
94 | confirmDialog(cm, doReplaceConfirm, "Replace?", | |||
|
95 | [function() {doReplace(match);}, advance]); | |||
|
96 | } | |||
|
97 | function doReplace(match) { | |||
|
98 | cursor.replace(typeof query == "string" ? text : | |||
|
99 | text.replace(/\$(\d)/, function(w, i) {return match[i];})); | |||
|
100 | advance(); | |||
|
101 | } | |||
|
102 | advance(); | |||
|
103 | } | |||
|
104 | }); | |||
|
105 | }); | |||
|
106 | } | |||
|
107 | ||||
|
108 | CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);}; | |||
|
109 | CodeMirror.commands.findNext = doSearch; | |||
|
110 | CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);}; | |||
|
111 | CodeMirror.commands.clearSearch = clearSearch; | |||
|
112 | CodeMirror.commands.replace = replace; | |||
|
113 | CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);}; | |||
|
114 | })(); |
@@ -0,0 +1,117 b'' | |||||
|
1 | (function(){ | |||
|
2 | function SearchCursor(cm, query, pos, caseFold) { | |||
|
3 | this.atOccurrence = false; this.cm = cm; | |||
|
4 | if (caseFold == null) caseFold = typeof query == "string" && query == query.toLowerCase(); | |||
|
5 | ||||
|
6 | pos = pos ? cm.clipPos(pos) : {line: 0, ch: 0}; | |||
|
7 | this.pos = {from: pos, to: pos}; | |||
|
8 | ||||
|
9 | // The matches method is filled in based on the type of query. | |||
|
10 | // It takes a position and a direction, and returns an object | |||
|
11 | // describing the next occurrence of the query, or null if no | |||
|
12 | // more matches were found. | |||
|
13 | if (typeof query != "string") // Regexp match | |||
|
14 | this.matches = function(reverse, pos) { | |||
|
15 | if (reverse) { | |||
|
16 | var line = cm.getLine(pos.line).slice(0, pos.ch), match = line.match(query), start = 0; | |||
|
17 | while (match) { | |||
|
18 | var ind = line.indexOf(match[0]); | |||
|
19 | start += ind; | |||
|
20 | line = line.slice(ind + 1); | |||
|
21 | var newmatch = line.match(query); | |||
|
22 | if (newmatch) match = newmatch; | |||
|
23 | else break; | |||
|
24 | start++; | |||
|
25 | } | |||
|
26 | } | |||
|
27 | else { | |||
|
28 | var line = cm.getLine(pos.line).slice(pos.ch), match = line.match(query), | |||
|
29 | start = match && pos.ch + line.indexOf(match[0]); | |||
|
30 | } | |||
|
31 | if (match) | |||
|
32 | return {from: {line: pos.line, ch: start}, | |||
|
33 | to: {line: pos.line, ch: start + match[0].length}, | |||
|
34 | match: match}; | |||
|
35 | }; | |||
|
36 | else { // String query | |||
|
37 | if (caseFold) query = query.toLowerCase(); | |||
|
38 | var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;}; | |||
|
39 | var target = query.split("\n"); | |||
|
40 | // Different methods for single-line and multi-line queries | |||
|
41 | if (target.length == 1) | |||
|
42 | this.matches = function(reverse, pos) { | |||
|
43 | var line = fold(cm.getLine(pos.line)), len = query.length, match; | |||
|
44 | if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1) | |||
|
45 | : (match = line.indexOf(query, pos.ch)) != -1) | |||
|
46 | return {from: {line: pos.line, ch: match}, | |||
|
47 | to: {line: pos.line, ch: match + len}}; | |||
|
48 | }; | |||
|
49 | else | |||
|
50 | this.matches = function(reverse, pos) { | |||
|
51 | var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(cm.getLine(ln)); | |||
|
52 | var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match)); | |||
|
53 | if (reverse ? offsetA >= pos.ch || offsetA != match.length | |||
|
54 | : offsetA <= pos.ch || offsetA != line.length - match.length) | |||
|
55 | return; | |||
|
56 | for (;;) { | |||
|
57 | if (reverse ? !ln : ln == cm.lineCount() - 1) return; | |||
|
58 | line = fold(cm.getLine(ln += reverse ? -1 : 1)); | |||
|
59 | match = target[reverse ? --idx : ++idx]; | |||
|
60 | if (idx > 0 && idx < target.length - 1) { | |||
|
61 | if (line != match) return; | |||
|
62 | else continue; | |||
|
63 | } | |||
|
64 | var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length); | |||
|
65 | if (reverse ? offsetB != line.length - match.length : offsetB != match.length) | |||
|
66 | return; | |||
|
67 | var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB}; | |||
|
68 | return {from: reverse ? end : start, to: reverse ? start : end}; | |||
|
69 | } | |||
|
70 | }; | |||
|
71 | } | |||
|
72 | } | |||
|
73 | ||||
|
74 | SearchCursor.prototype = { | |||
|
75 | findNext: function() {return this.find(false);}, | |||
|
76 | findPrevious: function() {return this.find(true);}, | |||
|
77 | ||||
|
78 | find: function(reverse) { | |||
|
79 | var self = this, pos = this.cm.clipPos(reverse ? this.pos.from : this.pos.to); | |||
|
80 | function savePosAndFail(line) { | |||
|
81 | var pos = {line: line, ch: 0}; | |||
|
82 | self.pos = {from: pos, to: pos}; | |||
|
83 | self.atOccurrence = false; | |||
|
84 | return false; | |||
|
85 | } | |||
|
86 | ||||
|
87 | for (;;) { | |||
|
88 | if (this.pos = this.matches(reverse, pos)) { | |||
|
89 | this.atOccurrence = true; | |||
|
90 | return this.pos.match || true; | |||
|
91 | } | |||
|
92 | if (reverse) { | |||
|
93 | if (!pos.line) return savePosAndFail(0); | |||
|
94 | pos = {line: pos.line-1, ch: this.cm.getLine(pos.line-1).length}; | |||
|
95 | } | |||
|
96 | else { | |||
|
97 | var maxLine = this.cm.lineCount(); | |||
|
98 | if (pos.line == maxLine - 1) return savePosAndFail(maxLine); | |||
|
99 | pos = {line: pos.line+1, ch: 0}; | |||
|
100 | } | |||
|
101 | } | |||
|
102 | }, | |||
|
103 | ||||
|
104 | from: function() {if (this.atOccurrence) return this.pos.from;}, | |||
|
105 | to: function() {if (this.atOccurrence) return this.pos.to;}, | |||
|
106 | ||||
|
107 | replace: function(newText) { | |||
|
108 | var self = this; | |||
|
109 | if (this.atOccurrence) | |||
|
110 | self.pos.to = this.cm.replaceRange(newText, self.pos.from, self.pos.to); | |||
|
111 | } | |||
|
112 | }; | |||
|
113 | ||||
|
114 | CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) { | |||
|
115 | return new SearchCursor(this, query, pos, caseFold); | |||
|
116 | }); | |||
|
117 | })(); |
@@ -0,0 +1,16 b'' | |||||
|
1 | .CodeMirror-completions { | |||
|
2 | position: absolute; | |||
|
3 | z-index: 10; | |||
|
4 | overflow: hidden; | |||
|
5 | -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); | |||
|
6 | -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); | |||
|
7 | box-shadow: 2px 3px 5px rgba(0,0,0,.2); | |||
|
8 | } | |||
|
9 | .CodeMirror-completions select { | |||
|
10 | background: #fafafa; | |||
|
11 | outline: none; | |||
|
12 | border: none; | |||
|
13 | padding: 0; | |||
|
14 | margin: 0; | |||
|
15 | font-family: monospace; | |||
|
16 | } |
@@ -0,0 +1,66 b'' | |||||
|
1 | (function() { | |||
|
2 | CodeMirror.simpleHint = function(editor, getHints) { | |||
|
3 | // We want a single cursor position. | |||
|
4 | if (editor.somethingSelected()) return; | |||
|
5 | var result = getHints(editor); | |||
|
6 | if (!result || !result.list.length) return; | |||
|
7 | var completions = result.list; | |||
|
8 | function insert(str) { | |||
|
9 | editor.replaceRange(str, result.from, result.to); | |||
|
10 | } | |||
|
11 | // When there is only one completion, use it directly. | |||
|
12 | if (completions.length == 1) {insert(completions[0]); return true;} | |||
|
13 | ||||
|
14 | // Build the select widget | |||
|
15 | var complete = document.createElement("div"); | |||
|
16 | complete.className = "CodeMirror-completions"; | |||
|
17 | var sel = complete.appendChild(document.createElement("select")); | |||
|
18 | // Opera doesn't move the selection when pressing up/down in a | |||
|
19 | // multi-select, but it does properly support the size property on | |||
|
20 | // single-selects, so no multi-select is necessary. | |||
|
21 | if (!window.opera) sel.multiple = true; | |||
|
22 | for (var i = 0; i < completions.length; ++i) { | |||
|
23 | var opt = sel.appendChild(document.createElement("option")); | |||
|
24 | opt.appendChild(document.createTextNode(completions[i])); | |||
|
25 | } | |||
|
26 | sel.firstChild.selected = true; | |||
|
27 | sel.size = Math.min(10, completions.length); | |||
|
28 | var pos = editor.cursorCoords(); | |||
|
29 | complete.style.left = pos.x + "px"; | |||
|
30 | complete.style.top = pos.yBot + "px"; | |||
|
31 | document.body.appendChild(complete); | |||
|
32 | // Hack to hide the scrollbar. | |||
|
33 | if (completions.length <= 10) | |||
|
34 | complete.style.width = (sel.clientWidth - 1) + "px"; | |||
|
35 | ||||
|
36 | var done = false; | |||
|
37 | function close() { | |||
|
38 | if (done) return; | |||
|
39 | done = true; | |||
|
40 | complete.parentNode.removeChild(complete); | |||
|
41 | } | |||
|
42 | function pick() { | |||
|
43 | insert(completions[sel.selectedIndex]); | |||
|
44 | close(); | |||
|
45 | setTimeout(function(){editor.focus();}, 50); | |||
|
46 | } | |||
|
47 | CodeMirror.connect(sel, "blur", close); | |||
|
48 | CodeMirror.connect(sel, "keydown", function(event) { | |||
|
49 | var code = event.keyCode; | |||
|
50 | // Enter | |||
|
51 | if (code == 13) {CodeMirror.e_stop(event); pick();} | |||
|
52 | // Escape | |||
|
53 | else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();} | |||
|
54 | else if (code != 38 && code != 40) { | |||
|
55 | close(); editor.focus(); | |||
|
56 | setTimeout(function(){CodeMirror.simpleHint(editor, getHints);}, 50); | |||
|
57 | } | |||
|
58 | }); | |||
|
59 | CodeMirror.connect(sel, "dblclick", pick); | |||
|
60 | ||||
|
61 | sel.focus(); | |||
|
62 | // Opera sometimes ignores focusing a freshly created node | |||
|
63 | if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100); | |||
|
64 | return true; | |||
|
65 | }; | |||
|
66 | })(); |
@@ -0,0 +1,18 b'' | |||||
|
1 | .cm-s-cobalt { background: #002240; color: white; } | |||
|
2 | .cm-s-cobalt span.CodeMirror-selected { background: #b36539 !important; } | |||
|
3 | .cm-s-cobalt .CodeMirror-gutter { background: #002240; border-right: 1px solid #aaa; } | |||
|
4 | .cm-s-cobalt .CodeMirror-gutter-text { color: #d0d0d0; } | |||
|
5 | .cm-s-cobalt .CodeMirror-cursor { border-left: 1px solid white !important; } | |||
|
6 | ||||
|
7 | .cm-s-cobalt span.cm-comment { color: #08f; } | |||
|
8 | .cm-s-cobalt span.cm-atom { color: #845dc4; } | |||
|
9 | .cm-s-cobalt span.cm-number, .cm-s-cobalt span.cm-attribute { color: #ff80e1; } | |||
|
10 | .cm-s-cobalt span.cm-keyword { color: #ffee80; } | |||
|
11 | .cm-s-cobalt span.cm-string { color: #3ad900; } | |||
|
12 | .cm-s-cobalt span.cm-meta { color: #ff9d00; } | |||
|
13 | .cm-s-cobalt span.cm-variable-2, .cm-s-cobalt span.cm-tag { color: #9effff; } | |||
|
14 | .cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def { color: white; } | |||
|
15 | .cm-s-cobalt span.cm-error { color: #9d1e15; } | |||
|
16 | .cm-s-cobalt span.cm-bracket { color: #d8d8d8; } | |||
|
17 | .cm-s-cobalt span.cm-builtin, .cm-s-cobalt span.cm-special { color: #ff9e59; } | |||
|
18 | .cm-s-cobalt span.cm-link { color: #845dc4; } |
@@ -0,0 +1,25 b'' | |||||
|
1 | .cm-s-eclipse span.cm-meta {color: #FF1717;} | |||
|
2 | .cm-s-eclipse span.cm-keyword { font-weight: bold; color: #7F0055; } | |||
|
3 | .cm-s-eclipse span.cm-atom {color: #219;} | |||
|
4 | .cm-s-eclipse span.cm-number {color: #164;} | |||
|
5 | .cm-s-eclipse span.cm-def {color: #00f;} | |||
|
6 | .cm-s-eclipse span.cm-variable {color: black;} | |||
|
7 | .cm-s-eclipse span.cm-variable-2 {color: #0000C0;} | |||
|
8 | .cm-s-eclipse span.cm-variable-3 {color: #0000C0;} | |||
|
9 | .cm-s-eclipse span.cm-property {color: black;} | |||
|
10 | .cm-s-eclipse span.cm-operator {color: black;} | |||
|
11 | .cm-s-eclipse span.cm-comment {color: #3F7F5F;} | |||
|
12 | .cm-s-eclipse span.cm-string {color: #2A00FF;} | |||
|
13 | .cm-s-eclipse span.cm-string-2 {color: #f50;} | |||
|
14 | .cm-s-eclipse span.cm-error {color: #f00;} | |||
|
15 | .cm-s-eclipse span.cm-qualifier {color: #555;} | |||
|
16 | .cm-s-eclipse span.cm-builtin {color: #30a;} | |||
|
17 | .cm-s-eclipse span.cm-bracket {color: #cc7;} | |||
|
18 | .cm-s-eclipse span.cm-tag {color: #170;} | |||
|
19 | .cm-s-eclipse span.cm-attribute {color: #00c;} | |||
|
20 | .cm-s-eclipse span.cm-link {color: #219;} | |||
|
21 | ||||
|
22 | .cm-s-eclipse .CodeMirror-matchingbracket { | |||
|
23 | border:1px solid grey; | |||
|
24 | color:black !important;; | |||
|
25 | } |
@@ -0,0 +1,28 b'' | |||||
|
1 | /* Based on Sublime Text's Monokai theme */ | |||
|
2 | ||||
|
3 | .cm-s-monokai {background: #272822; color: #f8f8f2;} | |||
|
4 | .cm-s-monokai span.CodeMirror-selected {background: #ffe792 !important;} | |||
|
5 | .cm-s-monokai .CodeMirror-gutter {background: #272822; border-right: 0px;} | |||
|
6 | .cm-s-monokai .CodeMirror-gutter-text {color: #d0d0d0;} | |||
|
7 | .cm-s-monokai .CodeMirror-cursor {border-left: 1px solid #f8f8f0 !important;} | |||
|
8 | ||||
|
9 | .cm-s-monokai span.cm-comment {color: #75715e;} | |||
|
10 | .cm-s-monokai span.cm-atom {color: #ae81ff;} | |||
|
11 | .cm-s-monokai span.cm-number {color: #ae81ff;} | |||
|
12 | ||||
|
13 | .cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute {color: #a6e22e;} | |||
|
14 | .cm-s-monokai span.cm-keyword {color: #f92672;} | |||
|
15 | .cm-s-monokai span.cm-string {color: #e6db74;} | |||
|
16 | ||||
|
17 | .cm-s-monokai span.cm-variable {color: #a6e22e;} | |||
|
18 | .cm-s-monokai span.cm-variable-2 {color: #9effff;} | |||
|
19 | .cm-s-monokai span.cm-def {color: #fd971f;} | |||
|
20 | .cm-s-monokai span.cm-error {background: #f92672; color: #f8f8f0;} | |||
|
21 | .cm-s-monokai span.cm-bracket {color: #f8f8f2;} | |||
|
22 | .cm-s-monokai span.cm-tag {color: #f92672;} | |||
|
23 | .cm-s-monokai span.cm-link {color: #ae81ff;} | |||
|
24 | ||||
|
25 | .cm-s-monokai .CodeMirror-matchingbracket { | |||
|
26 | text-decoration: underline; | |||
|
27 | color: white !important; | |||
|
28 | } |
@@ -0,0 +1,21 b'' | |||||
|
1 | .cm-s-rubyblue { font:13px/1.4em Trebuchet, Verdana, sans-serif; } /* - customized editor font - */ | |||
|
2 | ||||
|
3 | .cm-s-rubyblue { background: #112435; color: white; } | |||
|
4 | .cm-s-rubyblue span.CodeMirror-selected { background: #0000FF !important; } | |||
|
5 | .cm-s-rubyblue .CodeMirror-gutter { background: #1F4661; border-right: 7px solid #3E7087; min-width:2.5em; } | |||
|
6 | .cm-s-rubyblue .CodeMirror-gutter-text { color: white; } | |||
|
7 | .cm-s-rubyblue .CodeMirror-cursor { border-left: 1px solid white !important; } | |||
|
8 | ||||
|
9 | .cm-s-rubyblue span.cm-comment { color: #999; font-style:italic; } | |||
|
10 | .cm-s-rubyblue span.cm-atom { color: #F4C20B; } | |||
|
11 | .cm-s-rubyblue span.cm-number, .cm-s-rubyblue span.cm-attribute { color: #82C6E0; } | |||
|
12 | .cm-s-rubyblue span.cm-keyword { color: #F0F; } | |||
|
13 | .cm-s-rubyblue span.cm-string { color: #F08047; } | |||
|
14 | .cm-s-rubyblue span.cm-meta { color: #F0F; } | |||
|
15 | .cm-s-rubyblue span.cm-variable-2, .cm-s-rubyblue span.cm-tag { color: #7BD827; } | |||
|
16 | .cm-s-rubyblue span.cm-variable-3, .cm-s-rubyblue span.cm-def { color: white; } | |||
|
17 | .cm-s-rubyblue span.cm-error { color: #AF2018; } | |||
|
18 | .cm-s-rubyblue span.cm-bracket { color: #F0F; } | |||
|
19 | .cm-s-rubyblue span.cm-link { color: #F4C20B; } | |||
|
20 | .cm-s-rubyblue span.CodeMirror-matchingbracket { color:#F0F !important; } | |||
|
21 | .cm-s-rubyblue span.cm-builtin, .cm-s-rubyblue span.cm-special { color: #FF9D00; } |
@@ -5,7 +5,7 b'' | |||||
5 | We carry a mostly unmodified copy of CodeMirror. The current version we use |
|
5 | We carry a mostly unmodified copy of CodeMirror. The current version we use | |
6 | is (*please update this information when updating versions*):: |
|
6 | is (*please update this information when updating versions*):: | |
7 |
|
7 | |||
8 |
CodeMirror 2. |
|
8 | CodeMirror 2.2 | |
9 |
|
9 | |||
10 | The only changes we've applied so far are these:: |
|
10 | The only changes we've applied so far are these:: | |
11 |
|
11 |
@@ -2,5 +2,5 b'' | |||||
2 |
|
2 | |||
3 | CodeMirror 2 is a rewrite of [CodeMirror |
|
3 | CodeMirror 2 is a rewrite of [CodeMirror | |
4 | 1](http://github.com/marijnh/CodeMirror). The docs live |
|
4 | 1](http://github.com/marijnh/CodeMirror). The docs live | |
5 | [here](http://codemirror.net/manual.html), and the project page is |
|
5 | [here](http://codemirror.net/doc/manual.html), and the project page is | |
6 | [http://codemirror.net/](http://codemirror.net/). |
|
6 | [http://codemirror.net/](http://codemirror.net/). |
@@ -23,6 +23,7 b'' | |||||
23 | color: #aaa; |
|
23 | color: #aaa; | |
24 | text-align: right; |
|
24 | text-align: right; | |
25 | padding: .4em .2em .4em .4em; |
|
25 | padding: .4em .2em .4em .4em; | |
|
26 | white-space: pre !important; | |||
26 | } |
|
27 | } | |
27 | .CodeMirror-lines { |
|
28 | .CodeMirror-lines { | |
28 | padding: .4em; |
|
29 | padding: .4em; | |
@@ -41,28 +42,63 b'' | |||||
41 | word-wrap: normal; |
|
42 | word-wrap: normal; | |
42 | } |
|
43 | } | |
43 |
|
44 | |||
|
45 | .CodeMirror-wrap pre { | |||
|
46 | word-wrap: break-word; | |||
|
47 | white-space: pre-wrap; | |||
|
48 | } | |||
|
49 | .CodeMirror-wrap .CodeMirror-scroll { | |||
|
50 | overflow-x: hidden; | |||
|
51 | } | |||
|
52 | ||||
44 | .CodeMirror textarea { |
|
53 | .CodeMirror textarea { | |
45 | font-family: inherit !important; |
|
54 | outline: none !important; | |
46 | font-size: inherit !important; |
|
|||
47 | } |
|
55 | } | |
48 |
|
56 | |||
49 | .CodeMirror-cursor { |
|
57 | .CodeMirror pre.CodeMirror-cursor { | |
50 | z-index: 10; |
|
58 | z-index: 10; | |
51 | position: absolute; |
|
59 | position: absolute; | |
52 | visibility: hidden; |
|
60 | visibility: hidden; | |
53 |
border-left: 1px solid black |
|
61 | border-left: 1px solid black; | |
54 | } |
|
62 | } | |
55 | .CodeMirror-focused .CodeMirror-cursor { |
|
63 | .CodeMirror-focused pre.CodeMirror-cursor { | |
56 | visibility: visible; |
|
64 | visibility: visible; | |
57 | } |
|
65 | } | |
58 |
|
66 | |||
59 | span.CodeMirror-selected { |
|
67 | span.CodeMirror-selected { background: #d9d9d9; } | |
60 | background: #ccc !important; |
|
68 | .CodeMirror-focused span.CodeMirror-selected { background: #d2dcf8; } | |
61 | color: HighlightText !important; |
|
69 | ||
62 | } |
|
70 | .CodeMirror-searching {background: #ffa;} | |
63 | .CodeMirror-focused span.CodeMirror-selected { |
|
71 | ||
64 | background: Highlight !important; |
|
72 | /* Default theme */ | |
65 | } |
|
73 | ||
|
74 | .cm-s-default span.cm-keyword {color: #708;} | |||
|
75 | .cm-s-default span.cm-atom {color: #219;} | |||
|
76 | .cm-s-default span.cm-number {color: #164;} | |||
|
77 | .cm-s-default span.cm-def {color: #00f;} | |||
|
78 | .cm-s-default span.cm-variable {color: black;} | |||
|
79 | .cm-s-default span.cm-variable-2 {color: #05a;} | |||
|
80 | .cm-s-default span.cm-variable-3 {color: #085;} | |||
|
81 | .cm-s-default span.cm-property {color: black;} | |||
|
82 | .cm-s-default span.cm-operator {color: black;} | |||
|
83 | .cm-s-default span.cm-comment {color: #a50;} | |||
|
84 | .cm-s-default span.cm-string {color: #a11;} | |||
|
85 | .cm-s-default span.cm-string-2 {color: #f50;} | |||
|
86 | .cm-s-default span.cm-meta {color: #555;} | |||
|
87 | .cm-s-default span.cm-error {color: #f00;} | |||
|
88 | .cm-s-default span.cm-qualifier {color: #555;} | |||
|
89 | .cm-s-default span.cm-builtin {color: #30a;} | |||
|
90 | .cm-s-default span.cm-bracket {color: #cc7;} | |||
|
91 | .cm-s-default span.cm-tag {color: #170;} | |||
|
92 | .cm-s-default span.cm-attribute {color: #00c;} | |||
|
93 | .cm-s-default span.cm-header {color: #a0a;} | |||
|
94 | .cm-s-default span.cm-quote {color: #090;} | |||
|
95 | .cm-s-default span.cm-hr {color: #999;} | |||
|
96 | .cm-s-default span.cm-link {color: #00c;} | |||
|
97 | ||||
|
98 | span.cm-header, span.cm-strong {font-weight: bold;} | |||
|
99 | span.cm-em {font-style: italic;} | |||
|
100 | span.cm-emstrong {font-style: italic; font-weight: bold;} | |||
|
101 | span.cm-link {text-decoration: underline;} | |||
66 |
|
102 | |||
67 |
.CodeMirror-matchingbracket {color: #0f0 |
|
103 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} | |
68 |
.CodeMirror-nonmatchingbracket {color: #f22 |
|
104 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} |
This diff has been collapsed as it changes many lines, (2190 lines changed) Show them Hide them | |||||
@@ -1,3 +1,5 b'' | |||||
|
1 | // CodeMirror version 2.2 | |||
|
2 | // | |||
1 | // All functions that need access to the editor's state live inside |
|
3 | // All functions that need access to the editor's state live inside | |
2 | // the CodeMirror function. Below that, at the bottom of the file, |
|
4 | // the CodeMirror function. Below that, at the bottom of the file, | |
3 | // some utilities are defined. |
|
5 | // some utilities are defined. | |
@@ -16,19 +18,19 b' var CodeMirror = (function() {' | |||||
16 | var targetDocument = options["document"]; |
|
18 | var targetDocument = options["document"]; | |
17 | // The element in which the editor lives. |
|
19 | // The element in which the editor lives. | |
18 | var wrapper = targetDocument.createElement("div"); |
|
20 | var wrapper = targetDocument.createElement("div"); | |
19 | wrapper.className = "CodeMirror"; |
|
21 | wrapper.className = "CodeMirror" + (options.lineWrapping ? " CodeMirror-wrap" : ""); | |
20 | // This mess creates the base DOM structure for the editor. |
|
22 | // This mess creates the base DOM structure for the editor. | |
21 | wrapper.innerHTML = |
|
23 | wrapper.innerHTML = | |
22 |
'<div style="overflow: hidden; position: relative; width: |
|
24 | '<div style="overflow: hidden; position: relative; width: 3px; height: 0px;">' + // Wraps and hides input textarea | |
23 |
'<textarea style="position: absolute; width: |
|
25 | '<textarea style="position: absolute; padding: 0; width: 1px;" wrap="off" ' + | |
24 | 'autocorrect="off" autocapitalize="off"></textarea></div>' + |
|
26 | 'autocorrect="off" autocapitalize="off"></textarea></div>' + | |
25 |
'<div class="CodeMirror-scroll |
|
27 | '<div class="CodeMirror-scroll" tabindex="-1">' + | |
26 | '<div style="position: relative">' + // Set to the height of the text, causes scrolling |
|
28 | '<div style="position: relative">' + // Set to the height of the text, causes scrolling | |
27 | '<div style="position: absolute; height: 0; width: 0; overflow: hidden;"></div>' + |
|
|||
28 | '<div style="position: relative">' + // Moved around its parent to cover visible view |
|
29 | '<div style="position: relative">' + // Moved around its parent to cover visible view | |
29 | '<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' + |
|
30 | '<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' + | |
30 | // Provides positioning relative to (visible) text origin |
|
31 | // Provides positioning relative to (visible) text origin | |
31 |
'<div class="CodeMirror-lines"><div style="position: relative" |
|
32 | '<div class="CodeMirror-lines"><div style="position: relative">' + | |
|
33 | '<div style="position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden"></div>' + | |||
32 | '<pre class="CodeMirror-cursor"> </pre>' + // Absolutely positioned blinky cursor |
|
34 | '<pre class="CodeMirror-cursor"> </pre>' + // Absolutely positioned blinky cursor | |
33 | '<div></div>' + // This DIV contains the actual code |
|
35 | '<div></div>' + // This DIV contains the actual code | |
34 | '</div></div></div></div></div>'; |
|
36 | '</div></div></div></div></div>'; | |
@@ -36,51 +38,62 b' var CodeMirror = (function() {' | |||||
36 | // I've never seen more elegant code in my life. |
|
38 | // I've never seen more elegant code in my life. | |
37 | var inputDiv = wrapper.firstChild, input = inputDiv.firstChild, |
|
39 | var inputDiv = wrapper.firstChild, input = inputDiv.firstChild, | |
38 | scroller = wrapper.lastChild, code = scroller.firstChild, |
|
40 | scroller = wrapper.lastChild, code = scroller.firstChild, | |
39 |
me |
|
41 | mover = code.firstChild, gutter = mover.firstChild, gutterText = gutter.firstChild, | |
40 |
|
|
42 | lineSpace = gutter.nextSibling.firstChild, measure = lineSpace.firstChild, | |
41 | lineSpace = gutter.nextSibling.firstChild, |
|
43 | cursor = measure.nextSibling, lineDiv = cursor.nextSibling; | |
42 | cursor = lineSpace.firstChild, lineDiv = cursor.nextSibling; |
|
44 | themeChanged(); | |
43 | if (options.tabindex != null) input.tabindex = options.tabindex; |
|
45 | // Needed to hide big blue blinking cursor on Mobile Safari | |
|
46 | if (/AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent)) input.style.width = "0px"; | |||
|
47 | if (!webkit) lineSpace.draggable = true; | |||
|
48 | if (options.tabindex != null) input.tabIndex = options.tabindex; | |||
44 | if (!options.gutter && !options.lineNumbers) gutter.style.display = "none"; |
|
49 | if (!options.gutter && !options.lineNumbers) gutter.style.display = "none"; | |
45 |
|
50 | |||
|
51 | // Check for problem with IE innerHTML not working when we have a | |||
|
52 | // P (or similar) parent node. | |||
|
53 | try { stringWidth("x"); } | |||
|
54 | catch (e) { | |||
|
55 | if (e.message.match(/runtime/i)) | |||
|
56 | e = new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)"); | |||
|
57 | throw e; | |||
|
58 | } | |||
|
59 | ||||
46 | // Delayed object wrap timeouts, making sure only one is active. blinker holds an interval. |
|
60 | // Delayed object wrap timeouts, making sure only one is active. blinker holds an interval. | |
47 | var poll = new Delayed(), highlight = new Delayed(), blinker; |
|
61 | var poll = new Delayed(), highlight = new Delayed(), blinker; | |
48 |
|
62 | |||
49 |
// mode holds a mode API object. |
|
63 | // mode holds a mode API object. doc is the tree of Line objects, | |
50 |
// |
|
64 | // work an array of lines that should be parsed, and history the | |
51 |
// |
|
65 | // undo history (instance of History constructor). | |
52 | // constructor). |
|
66 | var mode, doc = new BranchChunk([new LeafChunk([new Line("")])]), work, focused; | |
53 | var mode, lines = [new Line("")], work, history = new History(), focused; |
|
|||
54 | loadMode(); |
|
67 | loadMode(); | |
55 | // The selection. These are always maintained to point at valid |
|
68 | // The selection. These are always maintained to point at valid | |
56 | // positions. Inverted is used to remember that the user is |
|
69 | // positions. Inverted is used to remember that the user is | |
57 | // selecting bottom-to-top. |
|
70 | // selecting bottom-to-top. | |
58 | var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false}; |
|
71 | var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false}; | |
59 | // Selection-related flags. shiftSelecting obviously tracks |
|
72 | // Selection-related flags. shiftSelecting obviously tracks | |
60 |
// whether the user is holding shift. |
|
73 | // whether the user is holding shift. | |
61 | // to get around the fact that we can't create inverted |
|
74 | var shiftSelecting, lastClick, lastDoubleClick, draggingText, overwrite = false; | |
62 | // selections. See below. |
|
|||
63 | var shiftSelecting, reducedSelection, lastClick, lastDoubleClick; |
|
|||
64 | // Variables used by startOperation/endOperation to track what |
|
75 | // Variables used by startOperation/endOperation to track what | |
65 | // happened during the operation. |
|
76 | // happened during the operation. | |
66 |
var updateInput, changes, textChanged, selectionChanged, leaveInputAlone, |
|
77 | var updateInput, userSelChange, changes, textChanged, selectionChanged, leaveInputAlone, | |
|
78 | gutterDirty, callbacks; | |||
67 | // Current visible range (may be bigger than the view window). |
|
79 | // Current visible range (may be bigger than the view window). | |
68 |
var showingFrom = 0, showingTo = 0, last |
|
80 | var displayOffset = 0, showingFrom = 0, showingTo = 0, lastSizeC = 0; | |
69 | // editing will hold an object describing the things we put in the |
|
|||
70 | // textarea, to help figure out whether something changed. |
|
|||
71 | // bracketHighlighted is used to remember that a backet has been |
|
81 | // bracketHighlighted is used to remember that a backet has been | |
72 | // marked. |
|
82 | // marked. | |
73 |
var |
|
83 | var bracketHighlighted; | |
74 | // Tracks the maximum line length so that the horizontal scrollbar |
|
84 | // Tracks the maximum line length so that the horizontal scrollbar | |
75 | // can be kept static when scrolling. |
|
85 | // can be kept static when scrolling. | |
76 | var maxLine = "", maxWidth; |
|
86 | var maxLine = "", maxWidth, tabText = computeTabText(); | |
77 |
|
87 | |||
78 | // Initialize the content. |
|
88 | // Initialize the content. | |
79 | operation(function(){setValue(options.value || ""); updateInput = false;})(); |
|
89 | operation(function(){setValue(options.value || ""); updateInput = false;})(); | |
|
90 | var history = new History(); | |||
80 |
|
91 | |||
81 | // Register our event handlers. |
|
92 | // Register our event handlers. | |
82 | connect(scroller, "mousedown", operation(onMouseDown)); |
|
93 | connect(scroller, "mousedown", operation(onMouseDown)); | |
|
94 | connect(scroller, "dblclick", operation(onDoubleClick)); | |||
83 | connect(lineSpace, "dragstart", onDragStart); |
|
95 | connect(lineSpace, "dragstart", onDragStart); | |
|
96 | connect(lineSpace, "selectstart", e_preventDefault); | |||
84 | // Gecko browsers fire contextmenu *after* opening the menu, at |
|
97 | // Gecko browsers fire contextmenu *after* opening the menu, at | |
85 | // which point we can't mess with it anymore. Context menu is |
|
98 | // which point we can't mess with it anymore. Context menu is | |
86 | // handled in onMouseDown for Gecko. |
|
99 | // handled in onMouseDown for Gecko. | |
@@ -92,6 +105,7 b' var CodeMirror = (function() {' | |||||
92 | }); |
|
105 | }); | |
93 | connect(window, "resize", function() {updateDisplay(true);}); |
|
106 | connect(window, "resize", function() {updateDisplay(true);}); | |
94 | connect(input, "keyup", operation(onKeyUp)); |
|
107 | connect(input, "keyup", operation(onKeyUp)); | |
|
108 | connect(input, "input", fastPoll); | |||
95 | connect(input, "keydown", operation(onKeyDown)); |
|
109 | connect(input, "keydown", operation(onKeyDown)); | |
96 | connect(input, "keypress", operation(onKeyPress)); |
|
110 | connect(input, "keypress", operation(onKeyPress)); | |
97 | connect(input, "focus", onFocus); |
|
111 | connect(input, "focus", onFocus); | |
@@ -101,8 +115,8 b' var CodeMirror = (function() {' | |||||
101 | connect(scroller, "dragover", e_stop); |
|
115 | connect(scroller, "dragover", e_stop); | |
102 | connect(scroller, "drop", operation(onDrop)); |
|
116 | connect(scroller, "drop", operation(onDrop)); | |
103 | connect(scroller, "paste", function(){focusInput(); fastPoll();}); |
|
117 | connect(scroller, "paste", function(){focusInput(); fastPoll();}); | |
104 |
connect(input, "paste", |
|
118 | connect(input, "paste", fastPoll); | |
105 |
connect(input, "cut", function(){ |
|
119 | connect(input, "cut", operation(function(){replaceSelection("");})); | |
106 |
|
120 | |||
107 | // IE throws unspecified error in certain cases, when |
|
121 | // IE throws unspecified error in certain cases, when | |
108 | // trying to access activeElement before onload |
|
122 | // trying to access activeElement before onload | |
@@ -110,7 +124,7 b' var CodeMirror = (function() {' | |||||
110 | if (hasFocus) setTimeout(onFocus, 20); |
|
124 | if (hasFocus) setTimeout(onFocus, 20); | |
111 | else onBlur(); |
|
125 | else onBlur(); | |
112 |
|
126 | |||
113 |
function isLine(l) {return l >= 0 && l < |
|
127 | function isLine(l) {return l >= 0 && l < doc.size;} | |
114 | // The instance object that we'll return. Mostly calls out to |
|
128 | // The instance object that we'll return. Mostly calls out to | |
115 | // local functions in the CodeMirror function. Some do some extra |
|
129 | // local functions in the CodeMirror function. Some do some extra | |
116 | // range checking and/or clipping. operation is used to wrap the |
|
130 | // range checking and/or clipping. operation is used to wrap the | |
@@ -123,12 +137,15 b' var CodeMirror = (function() {' | |||||
123 | replaceSelection: operation(replaceSelection), |
|
137 | replaceSelection: operation(replaceSelection), | |
124 | focus: function(){focusInput(); onFocus(); fastPoll();}, |
|
138 | focus: function(){focusInput(); onFocus(); fastPoll();}, | |
125 | setOption: function(option, value) { |
|
139 | setOption: function(option, value) { | |
|
140 | var oldVal = options[option]; | |||
126 | options[option] = value; |
|
141 | options[option] = value; | |
127 | if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber") |
|
142 | if (option == "mode" || option == "indentUnit") loadMode(); | |
|
143 | else if (option == "readOnly" && value) {onBlur(); input.blur();} | |||
|
144 | else if (option == "theme") themeChanged(); | |||
|
145 | else if (option == "lineWrapping" && oldVal != value) operation(wrappingChanged)(); | |||
|
146 | else if (option == "tabSize") operation(tabsChanged)(); | |||
|
147 | if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber" || option == "theme") | |||
128 | operation(gutterChanged)(); |
|
148 | operation(gutterChanged)(); | |
129 | else if (option == "mode" || option == "indentUnit") loadMode(); |
|
|||
130 | else if (option == "readOnly" && value == "nocursor") input.blur(); |
|
|||
131 | else if (option == "theme") scroller.className = scroller.className.replace(/cm-s-\w+/, "cm-s-" + value); |
|
|||
132 | }, |
|
149 | }, | |
133 | getOption: function(option) {return options[option];}, |
|
150 | getOption: function(option) {return options[option];}, | |
134 | undo: operation(undo), |
|
151 | undo: operation(undo), | |
@@ -136,14 +153,16 b' var CodeMirror = (function() {' | |||||
136 | indentLine: operation(function(n, dir) { |
|
153 | indentLine: operation(function(n, dir) { | |
137 | if (isLine(n)) indentLine(n, dir == null ? "smart" : dir ? "add" : "subtract"); |
|
154 | if (isLine(n)) indentLine(n, dir == null ? "smart" : dir ? "add" : "subtract"); | |
138 | }), |
|
155 | }), | |
|
156 | indentSelection: operation(indentSelected), | |||
139 | historySize: function() {return {undo: history.done.length, redo: history.undone.length};}, |
|
157 | historySize: function() {return {undo: history.done.length, redo: history.undone.length};}, | |
|
158 | clearHistory: function() {history = new History();}, | |||
140 | matchBrackets: operation(function(){matchBrackets(true);}), |
|
159 | matchBrackets: operation(function(){matchBrackets(true);}), | |
141 | getTokenAt: function(pos) { |
|
160 | getTokenAt: operation(function(pos) { | |
142 | pos = clipPos(pos); |
|
161 | pos = clipPos(pos); | |
143 |
return |
|
162 | return getLine(pos.line).getTokenAt(mode, getStateBefore(pos.line), pos.ch); | |
144 | }, |
|
163 | }), | |
145 | getStateAfter: function(line) { |
|
164 | getStateAfter: function(line) { | |
146 |
line = clipLine(line == null ? |
|
165 | line = clipLine(line == null ? doc.size - 1: line); | |
147 | return getStateBefore(line + 1); |
|
166 | return getStateBefore(line + 1); | |
148 | }, |
|
167 | }, | |
149 | cursorCoords: function(start){ |
|
168 | cursorCoords: function(start){ | |
@@ -153,14 +172,23 b' var CodeMirror = (function() {' | |||||
153 | charCoords: function(pos){return pageCoords(clipPos(pos));}, |
|
172 | charCoords: function(pos){return pageCoords(clipPos(pos));}, | |
154 | coordsChar: function(coords) { |
|
173 | coordsChar: function(coords) { | |
155 | var off = eltOffset(lineSpace); |
|
174 | var off = eltOffset(lineSpace); | |
156 | var line = clipLine(Math.min(lines.length - 1, showingFrom + Math.floor((coords.y - off.top) / lineHeight()))); |
|
175 | return coordsChar(coords.x - off.left, coords.y - off.top); | |
157 | return clipPos({line: line, ch: charFromX(clipLine(line), coords.x - off.left)}); |
|
|||
158 | }, |
|
176 | }, | |
159 | getSearchCursor: function(query, pos, caseFold) {return new SearchCursor(query, pos, caseFold);}, |
|
177 | markText: operation(markText), | |
160 | markText: operation(function(a, b, c){return operation(markText(a, b, c));}), |
|
178 | setBookmark: setBookmark, | |
161 | setMarker: operation(addGutterMarker), |
|
179 | setMarker: operation(addGutterMarker), | |
162 | clearMarker: operation(removeGutterMarker), |
|
180 | clearMarker: operation(removeGutterMarker), | |
163 | setLineClass: operation(setLineClass), |
|
181 | setLineClass: operation(setLineClass), | |
|
182 | hideLine: operation(function(h) {return setLineHidden(h, true);}), | |||
|
183 | showLine: operation(function(h) {return setLineHidden(h, false);}), | |||
|
184 | onDeleteLine: function(line, f) { | |||
|
185 | if (typeof line == "number") { | |||
|
186 | if (!isLine(line)) return null; | |||
|
187 | line = getLine(line); | |||
|
188 | } | |||
|
189 | (line.handlers || (line.handlers = [])).push(f); | |||
|
190 | return line; | |||
|
191 | }, | |||
164 | lineInfo: lineInfo, |
|
192 | lineInfo: lineInfo, | |
165 | addWidget: function(pos, node, scroll, vert, horiz) { |
|
193 | addWidget: function(pos, node, scroll, vert, horiz) { | |
166 | pos = localCoords(clipPos(pos)); |
|
194 | pos = localCoords(clipPos(pos)); | |
@@ -169,7 +197,7 b' var CodeMirror = (function() {' | |||||
169 | code.appendChild(node); |
|
197 | code.appendChild(node); | |
170 | if (vert == "over") top = pos.y; |
|
198 | if (vert == "over") top = pos.y; | |
171 | else if (vert == "near") { |
|
199 | else if (vert == "near") { | |
172 |
var vspace = Math.max(scroller.offsetHeight, |
|
200 | var vspace = Math.max(scroller.offsetHeight, doc.height * textHeight()), | |
173 | hspace = Math.max(code.clientWidth, lineSpace.clientWidth) - paddingLeft(); |
|
201 | hspace = Math.max(code.clientWidth, lineSpace.clientWidth) - paddingLeft(); | |
174 | if (pos.yBot + node.offsetHeight > vspace && pos.y > node.offsetHeight) |
|
202 | if (pos.yBot + node.offsetHeight > vspace && pos.y > node.offsetHeight) | |
175 | top = pos.y - node.offsetHeight; |
|
203 | top = pos.y - node.offsetHeight; | |
@@ -190,20 +218,24 b' var CodeMirror = (function() {' | |||||
190 | scrollIntoView(left, top, left + node.offsetWidth, top + node.offsetHeight); |
|
218 | scrollIntoView(left, top, left + node.offsetWidth, top + node.offsetHeight); | |
191 | }, |
|
219 | }, | |
192 |
|
220 | |||
193 |
lineCount: function() {return |
|
221 | lineCount: function() {return doc.size;}, | |
|
222 | clipPos: clipPos, | |||
194 | getCursor: function(start) { |
|
223 | getCursor: function(start) { | |
195 | if (start == null) start = sel.inverted; |
|
224 | if (start == null) start = sel.inverted; | |
196 | return copyPos(start ? sel.from : sel.to); |
|
225 | return copyPos(start ? sel.from : sel.to); | |
197 | }, |
|
226 | }, | |
198 | somethingSelected: function() {return !posEq(sel.from, sel.to);}, |
|
227 | somethingSelected: function() {return !posEq(sel.from, sel.to);}, | |
199 | setCursor: operation(function(line, ch) { |
|
228 | setCursor: operation(function(line, ch, user) { | |
200 | if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch); |
|
229 | if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch, user); | |
201 | else setCursor(line, ch); |
|
230 | else setCursor(line, ch, user); | |
202 | }), |
|
231 | }), | |
203 |
setSelection: operation(function(from, to) { |
|
232 | setSelection: operation(function(from, to, user) { | |
204 | getLine: function(line) {if (isLine(line)) return lines[line].text;}, |
|
233 | (user ? setSelectionUser : setSelection)(clipPos(from), clipPos(to || from)); | |
|
234 | }), | |||
|
235 | getLine: function(line) {if (isLine(line)) return getLine(line).text;}, | |||
|
236 | getLineHandle: function(line) {if (isLine(line)) return getLine(line);}, | |||
205 | setLine: operation(function(line, text) { |
|
237 | setLine: operation(function(line, text) { | |
206 |
if (isLine(line)) replaceRange(text, {line: line, ch: 0}, {line: line, ch: |
|
238 | if (isLine(line)) replaceRange(text, {line: line, ch: 0}, {line: line, ch: getLine(line).text.length}); | |
207 | }), |
|
239 | }), | |
208 | removeLine: operation(function(line) { |
|
240 | removeLine: operation(function(line) { | |
209 | if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0})); |
|
241 | if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0})); | |
@@ -211,6 +243,32 b' var CodeMirror = (function() {' | |||||
211 | replaceRange: operation(replaceRange), |
|
243 | replaceRange: operation(replaceRange), | |
212 | getRange: function(from, to) {return getRange(clipPos(from), clipPos(to));}, |
|
244 | getRange: function(from, to) {return getRange(clipPos(from), clipPos(to));}, | |
213 |
|
245 | |||
|
246 | execCommand: function(cmd) {return commands[cmd](instance);}, | |||
|
247 | // Stuff used by commands, probably not much use to outside code. | |||
|
248 | moveH: operation(moveH), | |||
|
249 | deleteH: operation(deleteH), | |||
|
250 | moveV: operation(moveV), | |||
|
251 | toggleOverwrite: function() {overwrite = !overwrite;}, | |||
|
252 | ||||
|
253 | posFromIndex: function(off) { | |||
|
254 | var lineNo = 0, ch; | |||
|
255 | doc.iter(0, doc.size, function(line) { | |||
|
256 | var sz = line.text.length + 1; | |||
|
257 | if (sz > off) { ch = off; return true; } | |||
|
258 | off -= sz; | |||
|
259 | ++lineNo; | |||
|
260 | }); | |||
|
261 | return clipPos({line: lineNo, ch: ch}); | |||
|
262 | }, | |||
|
263 | indexFromPos: function (coords) { | |||
|
264 | if (coords.line < 0 || coords.ch < 0) return 0; | |||
|
265 | var index = coords.ch; | |||
|
266 | doc.iter(0, coords.line, function (line) { | |||
|
267 | index += line.text.length + 1; | |||
|
268 | }); | |||
|
269 | return index; | |||
|
270 | }, | |||
|
271 | ||||
214 | operation: function(f){return operation(f)();}, |
|
272 | operation: function(f){return operation(f)();}, | |
215 | refresh: function(){updateDisplay(true);}, |
|
273 | refresh: function(){updateDisplay(true);}, | |
216 | getInputField: function(){return input;}, |
|
274 | getInputField: function(){return input;}, | |
@@ -219,27 +277,32 b' var CodeMirror = (function() {' | |||||
219 | getGutterElement: function(){return gutter;} |
|
277 | getGutterElement: function(){return gutter;} | |
220 | }; |
|
278 | }; | |
221 |
|
279 | |||
|
280 | function getLine(n) { return getLineAt(doc, n); } | |||
|
281 | function updateLineHeight(line, height) { | |||
|
282 | gutterDirty = true; | |||
|
283 | var diff = height - line.height; | |||
|
284 | for (var n = line; n; n = n.parent) n.height += diff; | |||
|
285 | } | |||
|
286 | ||||
222 | function setValue(code) { |
|
287 | function setValue(code) { | |
223 | history = null; |
|
|||
224 | var top = {line: 0, ch: 0}; |
|
288 | var top = {line: 0, ch: 0}; | |
225 |
updateLines(top, {line: |
|
289 | updateLines(top, {line: doc.size - 1, ch: getLine(doc.size-1).text.length}, | |
226 | splitLines(code), top, top); |
|
290 | splitLines(code), top, top); | |
227 | history = new History(); |
|
|||
228 | updateInput = true; |
|
291 | updateInput = true; | |
229 | } |
|
292 | } | |
230 | function getValue(code) { |
|
293 | function getValue(code) { | |
231 | var text = []; |
|
294 | var text = []; | |
232 | for (var i = 0, l = lines.length; i < l; ++i) |
|
295 | doc.iter(0, doc.size, function(line) { text.push(line.text); }); | |
233 | text.push(lines[i].text); |
|
|||
234 | return text.join("\n"); |
|
296 | return text.join("\n"); | |
235 | } |
|
297 | } | |
236 |
|
298 | |||
237 | function onMouseDown(e) { |
|
299 | function onMouseDown(e) { | |
|
300 | setShift(e.shiftKey); | |||
238 | // Check whether this is a click in a widget |
|
301 | // Check whether this is a click in a widget | |
239 | for (var n = e_target(e); n != wrapper; n = n.parentNode) |
|
302 | for (var n = e_target(e); n != wrapper; n = n.parentNode) | |
240 | if (n.parentNode == code && n != mover) return; |
|
303 | if (n.parentNode == code && n != mover) return; | |
241 |
|
304 | |||
242 |
// |
|
305 | // See if this is a click in the gutter | |
243 | for (var n = e_target(e); n != wrapper; n = n.parentNode) |
|
306 | for (var n = e_target(e); n != wrapper; n = n.parentNode) | |
244 | if (n.parentNode == gutterText) { |
|
307 | if (n.parentNode == gutterText) { | |
245 | if (options.onGutterClick) |
|
308 | if (options.onGutterClick) | |
@@ -265,19 +328,32 b' var CodeMirror = (function() {' | |||||
265 | if (!focused) onFocus(); |
|
328 | if (!focused) onFocus(); | |
266 |
|
329 | |||
267 | var now = +new Date; |
|
330 | var now = +new Date; | |
268 | if (lastDoubleClick > now - 400) { |
|
331 | if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) { | |
269 | e_preventDefault(e); |
|
332 | e_preventDefault(e); | |
|
333 | setTimeout(focusInput, 20); | |||
270 | return selectLine(start.line); |
|
334 | return selectLine(start.line); | |
271 | } else if (lastClick > now - 400) { |
|
335 | } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) { | |
272 | lastDoubleClick = now; |
|
336 | lastDoubleClick = {time: now, pos: start}; | |
273 | e_preventDefault(e); |
|
337 | e_preventDefault(e); | |
274 | return selectWordAt(start); |
|
338 | return selectWordAt(start); | |
275 | } else { lastClick = now; } |
|
339 | } else { lastClick = {time: now, pos: start}; } | |
276 |
|
340 | |||
277 | var last = start, going; |
|
341 | var last = start, going; | |
278 | if (dragAndDrop && !posEq(sel.from, sel.to) && |
|
342 | if (dragAndDrop && !posEq(sel.from, sel.to) && | |
279 | !posLess(start, sel.from) && !posLess(sel.to, start)) { |
|
343 | !posLess(start, sel.from) && !posLess(sel.to, start)) { | |
280 | // Let the drag handler handle this. |
|
344 | // Let the drag handler handle this. | |
|
345 | if (webkit) lineSpace.draggable = true; | |||
|
346 | var up = connect(targetDocument, "mouseup", operation(function(e2) { | |||
|
347 | if (webkit) lineSpace.draggable = false; | |||
|
348 | draggingText = false; | |||
|
349 | up(); | |||
|
350 | if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) { | |||
|
351 | e_preventDefault(e2); | |||
|
352 | setCursor(start.line, start.ch, true); | |||
|
353 | focusInput(); | |||
|
354 | } | |||
|
355 | }), true); | |||
|
356 | draggingText = true; | |||
281 | return; |
|
357 | return; | |
282 | } |
|
358 | } | |
283 | e_preventDefault(e); |
|
359 | e_preventDefault(e); | |
@@ -311,6 +387,15 b' var CodeMirror = (function() {' | |||||
311 | move(); up(); |
|
387 | move(); up(); | |
312 | }), true); |
|
388 | }), true); | |
313 | } |
|
389 | } | |
|
390 | function onDoubleClick(e) { | |||
|
391 | for (var n = e_target(e); n != wrapper; n = n.parentNode) | |||
|
392 | if (n.parentNode == gutterText) return e_preventDefault(e); | |||
|
393 | var start = posFromMouse(e); | |||
|
394 | if (!start) return; | |||
|
395 | lastDoubleClick = {time: +new Date, pos: start}; | |||
|
396 | e_preventDefault(e); | |||
|
397 | selectWordAt(start); | |||
|
398 | } | |||
314 | function onDrop(e) { |
|
399 | function onDrop(e) { | |
315 | e.preventDefault(); |
|
400 | e.preventDefault(); | |
316 | var pos = posFromMouse(e, true), files = e.dataTransfer.files; |
|
401 | var pos = posFromMouse(e, true), files = e.dataTransfer.files; | |
@@ -320,7 +405,13 b' var CodeMirror = (function() {' | |||||
320 | var reader = new FileReader; |
|
405 | var reader = new FileReader; | |
321 | reader.onload = function() { |
|
406 | reader.onload = function() { | |
322 | text[i] = reader.result; |
|
407 | text[i] = reader.result; | |
323 | if (++read == n) replaceRange(text.join(""), clipPos(pos), clipPos(pos)); |
|
408 | if (++read == n) { | |
|
409 | pos = clipPos(pos); | |||
|
410 | operation(function() { | |||
|
411 | var end = replaceRange(text.join(""), pos, pos); | |||
|
412 | setSelectionUser(pos, end); | |||
|
413 | })(); | |||
|
414 | } | |||
324 | }; |
|
415 | }; | |
325 | reader.readAsText(file); |
|
416 | reader.readAsText(file); | |
326 | } |
|
417 | } | |
@@ -330,7 +421,13 b' var CodeMirror = (function() {' | |||||
330 | else { |
|
421 | else { | |
331 | try { |
|
422 | try { | |
332 | var text = e.dataTransfer.getData("Text"); |
|
423 | var text = e.dataTransfer.getData("Text"); | |
333 | if (text) replaceRange(text, pos, pos); |
|
424 | if (text) { | |
|
425 | var end = replaceRange(text, pos, pos); | |||
|
426 | var curFrom = sel.from, curTo = sel.to; | |||
|
427 | setSelectionUser(pos, end); | |||
|
428 | if (draggingText) replaceRange("", curFrom, curTo); | |||
|
429 | focusInput(); | |||
|
430 | } | |||
334 | } |
|
431 | } | |
335 | catch(e){} |
|
432 | catch(e){} | |
336 | } |
|
433 | } | |
@@ -342,81 +439,76 b' var CodeMirror = (function() {' | |||||
342 | e.dataTransfer.setDragImage(escapeElement, 0, 0); |
|
439 | e.dataTransfer.setDragImage(escapeElement, 0, 0); | |
343 | e.dataTransfer.setData("Text", txt); |
|
440 | e.dataTransfer.setData("Text", txt); | |
344 | } |
|
441 | } | |
|
442 | function handleKeyBinding(e) { | |||
|
443 | var name = keyNames[e.keyCode], next = keyMap[options.keyMap].auto, bound, dropShift; | |||
|
444 | if (name == null || e.altGraphKey) { | |||
|
445 | if (next) options.keyMap = next; | |||
|
446 | return null; | |||
|
447 | } | |||
|
448 | if (e.altKey) name = "Alt-" + name; | |||
|
449 | if (e.ctrlKey) name = "Ctrl-" + name; | |||
|
450 | if (e.metaKey) name = "Cmd-" + name; | |||
|
451 | if (e.shiftKey && (bound = lookupKey("Shift-" + name, options.extraKeys, options.keyMap))) { | |||
|
452 | dropShift = true; | |||
|
453 | } else { | |||
|
454 | bound = lookupKey(name, options.extraKeys, options.keyMap); | |||
|
455 | } | |||
|
456 | if (typeof bound == "string") { | |||
|
457 | if (commands.propertyIsEnumerable(bound)) bound = commands[bound]; | |||
|
458 | else bound = null; | |||
|
459 | } | |||
|
460 | if (next && (bound || !isModifierKey(e))) options.keyMap = next; | |||
|
461 | if (!bound) return false; | |||
|
462 | if (dropShift) { | |||
|
463 | var prevShift = shiftSelecting; | |||
|
464 | shiftSelecting = null; | |||
|
465 | bound(instance); | |||
|
466 | shiftSelecting = prevShift; | |||
|
467 | } else bound(instance); | |||
|
468 | e_preventDefault(e); | |||
|
469 | return true; | |||
|
470 | } | |||
|
471 | var lastStoppedKey = null; | |||
345 | function onKeyDown(e) { |
|
472 | function onKeyDown(e) { | |
346 | if (!focused) onFocus(); |
|
473 | if (!focused) onFocus(); | |
347 |
|
||||
348 | var code = e.keyCode; |
|
474 | var code = e.keyCode; | |
349 | // IE does strange things with escape. |
|
475 | // IE does strange things with escape. | |
350 | if (ie && code == 27) { e.returnValue = false; } |
|
476 | if (ie && code == 27) { e.returnValue = false; } | |
351 | // Tries to detect ctrl on non-mac, cmd on mac. |
|
477 | setShift(code == 16 || e.shiftKey); | |
352 | var mod = (mac ? e.metaKey : e.ctrlKey) && !e.altKey, anyMod = e.ctrlKey || e.altKey || e.metaKey; |
|
|||
353 | if (code == 16 || e.shiftKey) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from); |
|
|||
354 | else shiftSelecting = null; |
|
|||
355 | // First give onKeyEvent option a chance to handle this. |
|
478 | // First give onKeyEvent option a chance to handle this. | |
356 | if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; |
|
479 | if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; | |
357 |
|
480 | var handled = handleKeyBinding(e); | ||
358 | if (code == 33 || code == 34) {scrollPage(code == 34); return e_preventDefault(e);} // page up/down |
|
481 | if (window.opera) { | |
359 | if (mod && ((code == 36 || code == 35) || // ctrl-home/end |
|
482 | lastStoppedKey = handled ? e.keyCode : null; | |
360 | mac && (code == 38 || code == 40))) { // cmd-up/down |
|
483 | // Opera has no cut event... we try to at least catch the key combo | |
361 | scrollEnd(code == 36 || code == 38); return e_preventDefault(e); |
|
484 | if (!handled && (mac ? e.metaKey : e.ctrlKey) && e.keyCode == 88) | |
362 | } |
|
485 | replaceSelection(""); | |
363 | if (mod && code == 65) {selectAll(); return e_preventDefault(e);} // ctrl-a |
|
|||
364 | if (!options.readOnly) { |
|
|||
365 | if (!anyMod && code == 13) {return;} // enter |
|
|||
366 | if (!anyMod && code == 9 && handleTab(e.shiftKey)) return e_preventDefault(e); // tab |
|
|||
367 | if (mod && code == 90) {undo(); return e_preventDefault(e);} // ctrl-z |
|
|||
368 | if (mod && ((e.shiftKey && code == 90) || code == 89)) {redo(); return e_preventDefault(e);} // ctrl-shift-z, ctrl-y |
|
|||
369 | } |
|
|||
370 | if (code == 36) { if (options.smartHome) { smartHome(); return e_preventDefault(e); } } |
|
|||
371 |
|
||||
372 | // Key id to use in the movementKeys map. We also pass it to |
|
|||
373 | // fastPoll in order to 'self learn'. We need this because |
|
|||
374 | // reducedSelection, the hack where we collapse the selection to |
|
|||
375 | // its start when it is inverted and a movement key is pressed |
|
|||
376 | // (and later restore it again), shouldn't be used for |
|
|||
377 | // non-movement keys. |
|
|||
378 | curKeyId = (mod ? "c" : "") + (e.altKey ? "a" : "") + code; |
|
|||
379 | if (sel.inverted && movementKeys[curKeyId] === true) { |
|
|||
380 | var range = selRange(input); |
|
|||
381 | if (range) { |
|
|||
382 | reducedSelection = {anchor: range.start}; |
|
|||
383 | setSelRange(input, range.start, range.start); |
|
|||
384 | } |
|
|||
385 | } |
|
|||
386 | // Don't save the key as a movementkey unless it had a modifier |
|
|||
387 | if (!mod && !e.altKey) curKeyId = null; |
|
|||
388 | fastPoll(curKeyId); |
|
|||
389 | } |
|
|||
390 | function onKeyUp(e) { |
|
|||
391 | if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; |
|
|||
392 | if (reducedSelection) { |
|
|||
393 | reducedSelection = null; |
|
|||
394 | updateInput = true; |
|
|||
395 | } |
|
486 | } | |
396 | if (e.keyCode == 16) shiftSelecting = null; |
|
|||
397 | } |
|
487 | } | |
398 | function onKeyPress(e) { |
|
488 | function onKeyPress(e) { | |
|
489 | if (window.opera && e.keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;} | |||
399 | if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; |
|
490 | if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; | |
|
491 | if (window.opera && !e.which && handleKeyBinding(e)) return; | |||
400 | if (options.electricChars && mode.electricChars) { |
|
492 | if (options.electricChars && mode.electricChars) { | |
401 | var ch = String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode); |
|
493 | var ch = String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode); | |
402 | if (mode.electricChars.indexOf(ch) > -1) |
|
494 | if (mode.electricChars.indexOf(ch) > -1) | |
403 |
setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 5 |
|
495 | setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 75); | |
404 | } |
|
496 | } | |
405 | var code = e.keyCode; |
|
497 | fastPoll(); | |
406 | // Re-stop tab and enter. Necessary on some browsers. |
|
498 | } | |
407 | if (code == 13) {if (!options.readOnly) handleEnter(); e_preventDefault(e);} |
|
499 | function onKeyUp(e) { | |
408 | else if (!e.ctrlKey && !e.altKey && !e.metaKey && code == 9 && options.tabMode != "default") e_preventDefault(e); |
|
500 | if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; | |
409 | else fastPoll(curKeyId); |
|
501 | if (e.keyCode == 16) shiftSelecting = null; | |
410 | } |
|
502 | } | |
411 |
|
503 | |||
412 | function onFocus() { |
|
504 | function onFocus() { | |
413 |
if (options.readOnly |
|
505 | if (options.readOnly) return; | |
414 | if (!focused) { |
|
506 | if (!focused) { | |
415 | if (options.onFocus) options.onFocus(instance); |
|
507 | if (options.onFocus) options.onFocus(instance); | |
416 | focused = true; |
|
508 | focused = true; | |
417 | if (wrapper.className.search(/\bCodeMirror-focused\b/) == -1) |
|
509 | if (wrapper.className.search(/\bCodeMirror-focused\b/) == -1) | |
418 | wrapper.className += " CodeMirror-focused"; |
|
510 | wrapper.className += " CodeMirror-focused"; | |
419 |
if (!leaveInputAlone) |
|
511 | if (!leaveInputAlone) resetInput(true); | |
420 | } |
|
512 | } | |
421 | slowPoll(); |
|
513 | slowPoll(); | |
422 | restartBlink(); |
|
514 | restartBlink(); | |
@@ -436,7 +528,7 b' var CodeMirror = (function() {' | |||||
436 | function updateLines(from, to, newText, selFrom, selTo) { |
|
528 | function updateLines(from, to, newText, selFrom, selTo) { | |
437 | if (history) { |
|
529 | if (history) { | |
438 | var old = []; |
|
530 | var old = []; | |
439 |
|
|
531 | doc.iter(from.line, to.line + 1, function(line) { old.push(line.text); }); | |
440 | history.addChange(from.line, newText.length, old); |
|
532 | history.addChange(from.line, newText.length, old); | |
441 | while (history.done.length > options.undoDepth) history.done.shift(); |
|
533 | while (history.done.length > options.undoDepth) history.done.shift(); | |
442 | } |
|
534 | } | |
@@ -446,11 +538,11 b' var CodeMirror = (function() {' | |||||
446 | var change = from.pop(); |
|
538 | var change = from.pop(); | |
447 | if (change) { |
|
539 | if (change) { | |
448 | var replaced = [], end = change.start + change.added; |
|
540 | var replaced = [], end = change.start + change.added; | |
449 |
|
|
541 | doc.iter(change.start, end, function(line) { replaced.push(line.text); }); | |
450 | to.push({start: change.start, added: change.old.length, old: replaced}); |
|
542 | to.push({start: change.start, added: change.old.length, old: replaced}); | |
451 | var pos = clipPos({line: change.start + change.old.length - 1, |
|
543 | var pos = clipPos({line: change.start + change.old.length - 1, | |
452 | ch: editEnd(replaced[replaced.length-1], change.old[change.old.length-1])}); |
|
544 | ch: editEnd(replaced[replaced.length-1], change.old[change.old.length-1])}); | |
453 |
updateLinesNoUndo({line: change.start, ch: 0}, {line: end - 1, ch: |
|
545 | updateLinesNoUndo({line: change.start, ch: 0}, {line: end - 1, ch: getLine(end-1).text.length}, change.old, pos, pos); | |
454 | updateInput = true; |
|
546 | updateInput = true; | |
455 | } |
|
547 | } | |
456 | } |
|
548 | } | |
@@ -459,51 +551,77 b' var CodeMirror = (function() {' | |||||
459 |
|
551 | |||
460 | function updateLinesNoUndo(from, to, newText, selFrom, selTo) { |
|
552 | function updateLinesNoUndo(from, to, newText, selFrom, selTo) { | |
461 | var recomputeMaxLength = false, maxLineLength = maxLine.length; |
|
553 | var recomputeMaxLength = false, maxLineLength = maxLine.length; | |
462 | for (var i = from.line; i <= to.line; ++i) { |
|
554 | if (!options.lineWrapping) | |
463 | if (lines[i].text.length == maxLineLength) {recomputeMaxLength = true; break;} |
|
555 | doc.iter(from.line, to.line, function(line) { | |
464 | } |
|
556 | if (line.text.length == maxLineLength) {recomputeMaxLength = true; return true;} | |
|
557 | }); | |||
|
558 | if (from.line != to.line || newText.length > 1) gutterDirty = true; | |||
465 |
|
559 | |||
466 |
var nlines = to.line - from.line, firstLine = |
|
560 | var nlines = to.line - from.line, firstLine = getLine(from.line), lastLine = getLine(to.line); | |
467 | // First adjust the line structure, taking some care to leave highlighting intact. |
|
561 | // First adjust the line structure, taking some care to leave highlighting intact. | |
468 | if (firstLine == lastLine) { |
|
562 | if (from.ch == 0 && to.ch == 0 && newText[newText.length - 1] == "") { | |
|
563 | // This is a whole-line replace. Treated specially to make | |||
|
564 | // sure line objects move the way they are supposed to. | |||
|
565 | var added = [], prevLine = null; | |||
|
566 | if (from.line) { | |||
|
567 | prevLine = getLine(from.line - 1); | |||
|
568 | prevLine.fixMarkEnds(lastLine); | |||
|
569 | } else lastLine.fixMarkStarts(); | |||
|
570 | for (var i = 0, e = newText.length - 1; i < e; ++i) | |||
|
571 | added.push(Line.inheritMarks(newText[i], prevLine)); | |||
|
572 | if (nlines) doc.remove(from.line, nlines, callbacks); | |||
|
573 | if (added.length) doc.insert(from.line, added); | |||
|
574 | } else if (firstLine == lastLine) { | |||
469 | if (newText.length == 1) |
|
575 | if (newText.length == 1) | |
470 | firstLine.replace(from.ch, to.ch, newText[0]); |
|
576 | firstLine.replace(from.ch, to.ch, newText[0]); | |
471 | else { |
|
577 | else { | |
472 | lastLine = firstLine.split(to.ch, newText[newText.length-1]); |
|
578 | lastLine = firstLine.split(to.ch, newText[newText.length-1]); | |
473 | var spliceargs = [from.line + 1, nlines]; |
|
579 | firstLine.replace(from.ch, null, newText[0]); | |
474 | firstLine.replace(from.ch, firstLine.text.length, newText[0]); |
|
580 | firstLine.fixMarkEnds(lastLine); | |
475 | for (var i = 1, e = newText.length - 1; i < e; ++i) spliceargs.push(new Line(newText[i])); |
|
581 | var added = []; | |
476 | spliceargs.push(lastLine); |
|
582 | for (var i = 1, e = newText.length - 1; i < e; ++i) | |
477 | lines.splice.apply(lines, spliceargs); |
|
583 | added.push(Line.inheritMarks(newText[i], firstLine)); | |
478 | } |
|
584 | added.push(lastLine); | |
479 | } |
|
585 | doc.insert(from.line + 1, added); | |
480 | else if (newText.length == 1) { |
|
|||
481 | firstLine.replace(from.ch, firstLine.text.length, newText[0] + lastLine.text.slice(to.ch)); |
|
|||
482 | lines.splice(from.line + 1, nlines); |
|
|||
483 | } |
|
|||
484 | else { |
|
|||
485 | var spliceargs = [from.line + 1, nlines - 1]; |
|
|||
486 | firstLine.replace(from.ch, firstLine.text.length, newText[0]); |
|
|||
487 | lastLine.replace(0, to.ch, newText[newText.length-1]); |
|
|||
488 | for (var i = 1, e = newText.length - 1; i < e; ++i) spliceargs.push(new Line(newText[i])); |
|
|||
489 | lines.splice.apply(lines, spliceargs); |
|
|||
490 | } |
|
|||
491 |
|
||||
492 |
|
||||
493 | for (var i = from.line, e = i + newText.length; i < e; ++i) { |
|
|||
494 | var l = lines[i].text; |
|
|||
495 | if (l.length > maxLineLength) { |
|
|||
496 | maxLine = l; maxLineLength = l.length; maxWidth = null; |
|
|||
497 | recomputeMaxLength = false; |
|
|||
498 | } |
|
586 | } | |
499 | } |
|
587 | } else if (newText.length == 1) { | |
500 | if (recomputeMaxLength) { |
|
588 | firstLine.replace(from.ch, null, newText[0]); | |
501 | maxLineLength = 0; maxLine = ""; maxWidth = null; |
|
589 | lastLine.replace(null, to.ch, ""); | |
502 | for (var i = 0, e = lines.length; i < e; ++i) { |
|
590 | firstLine.append(lastLine); | |
503 | var l = lines[i].text; |
|
591 | doc.remove(from.line + 1, nlines, callbacks); | |
|
592 | } else { | |||
|
593 | var added = []; | |||
|
594 | firstLine.replace(from.ch, null, newText[0]); | |||
|
595 | lastLine.replace(null, to.ch, newText[newText.length-1]); | |||
|
596 | firstLine.fixMarkEnds(lastLine); | |||
|
597 | for (var i = 1, e = newText.length - 1; i < e; ++i) | |||
|
598 | added.push(Line.inheritMarks(newText[i], firstLine)); | |||
|
599 | if (nlines > 1) doc.remove(from.line + 1, nlines - 1, callbacks); | |||
|
600 | doc.insert(from.line + 1, added); | |||
|
601 | } | |||
|
602 | if (options.lineWrapping) { | |||
|
603 | var perLine = scroller.clientWidth / charWidth() - 3; | |||
|
604 | doc.iter(from.line, from.line + newText.length, function(line) { | |||
|
605 | if (line.hidden) return; | |||
|
606 | var guess = Math.ceil(line.text.length / perLine) || 1; | |||
|
607 | if (guess != line.height) updateLineHeight(line, guess); | |||
|
608 | }); | |||
|
609 | } else { | |||
|
610 | doc.iter(from.line, i + newText.length, function(line) { | |||
|
611 | var l = line.text; | |||
504 | if (l.length > maxLineLength) { |
|
612 | if (l.length > maxLineLength) { | |
505 |
maxLineLength = l.length; max |
|
613 | maxLine = l; maxLineLength = l.length; maxWidth = null; | |
|
614 | recomputeMaxLength = false; | |||
506 | } |
|
615 | } | |
|
616 | }); | |||
|
617 | if (recomputeMaxLength) { | |||
|
618 | maxLineLength = 0; maxLine = ""; maxWidth = null; | |||
|
619 | doc.iter(0, doc.size, function(line) { | |||
|
620 | var l = line.text; | |||
|
621 | if (l.length > maxLineLength) { | |||
|
622 | maxLineLength = l.length; maxLine = l; | |||
|
623 | } | |||
|
624 | }); | |||
507 | } |
|
625 | } | |
508 | } |
|
626 | } | |
509 |
|
627 | |||
@@ -515,24 +633,25 b' var CodeMirror = (function() {' | |||||
515 | if (task < from.line) newWork.push(task); |
|
633 | if (task < from.line) newWork.push(task); | |
516 | else if (task > to.line) newWork.push(task + lendiff); |
|
634 | else if (task > to.line) newWork.push(task + lendiff); | |
517 | } |
|
635 | } | |
518 | if (newText.length < 5) { |
|
636 | var hlEnd = from.line + Math.min(newText.length, 500); | |
519 |
|
|
637 | highlightLines(from.line, hlEnd); | |
520 |
|
|
638 | newWork.push(hlEnd); | |
521 | } else { |
|
|||
522 | newWork.push(from.line); |
|
|||
523 | } |
|
|||
524 | work = newWork; |
|
639 | work = newWork; | |
525 | startWorker(100); |
|
640 | startWorker(100); | |
526 | // Remember that these lines changed, for updating the display |
|
641 | // Remember that these lines changed, for updating the display | |
527 | changes.push({from: from.line, to: to.line + 1, diff: lendiff}); |
|
642 | changes.push({from: from.line, to: to.line + 1, diff: lendiff}); | |
528 |
|
|
643 | var changeObj = {from: from, to: to, text: newText}; | |
|
644 | if (textChanged) { | |||
|
645 | for (var cur = textChanged; cur.next; cur = cur.next) {} | |||
|
646 | cur.next = changeObj; | |||
|
647 | } else textChanged = changeObj; | |||
529 |
|
648 | |||
530 | // Update the selection |
|
649 | // Update the selection | |
531 | function updateLine(n) {return n <= Math.min(to.line, to.line + lendiff) ? n : n + lendiff;} |
|
650 | function updateLine(n) {return n <= Math.min(to.line, to.line + lendiff) ? n : n + lendiff;} | |
532 | setSelection(selFrom, selTo, updateLine(sel.from.line), updateLine(sel.to.line)); |
|
651 | setSelection(selFrom, selTo, updateLine(sel.from.line), updateLine(sel.to.line)); | |
533 |
|
652 | |||
534 | // Make sure the scroll-size div has the correct height. |
|
653 | // Make sure the scroll-size div has the correct height. | |
535 |
code.style.height = ( |
|
654 | code.style.height = (doc.height * textHeight() + 2 * paddingTop()) + "px"; | |
536 | } |
|
655 | } | |
537 |
|
656 | |||
538 | function replaceRange(code, from, to) { |
|
657 | function replaceRange(code, from, to) { | |
@@ -570,10 +689,10 b' var CodeMirror = (function() {' | |||||
570 |
|
689 | |||
571 | function getRange(from, to) { |
|
690 | function getRange(from, to) { | |
572 | var l1 = from.line, l2 = to.line; |
|
691 | var l1 = from.line, l2 = to.line; | |
573 |
if (l1 == l2) return |
|
692 | if (l1 == l2) return getLine(l1).text.slice(from.ch, to.ch); | |
574 |
var code = [ |
|
693 | var code = [getLine(l1).text.slice(from.ch)]; | |
575 |
|
|
694 | doc.iter(l1 + 1, l2, function(line) { code.push(line.text); }); | |
576 |
code.push( |
|
695 | code.push(getLine(l2).text.slice(0, to.ch)); | |
577 | return code.join("\n"); |
|
696 | return code.join("\n"); | |
578 | } |
|
697 | } | |
579 | function getSelection() { |
|
698 | function getSelection() { | |
@@ -583,131 +702,74 b' var CodeMirror = (function() {' | |||||
583 | var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll |
|
702 | var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll | |
584 | function slowPoll() { |
|
703 | function slowPoll() { | |
585 | if (pollingFast) return; |
|
704 | if (pollingFast) return; | |
586 |
poll.set( |
|
705 | poll.set(options.pollInterval, function() { | |
587 | startOperation(); |
|
706 | startOperation(); | |
588 | readInput(); |
|
707 | readInput(); | |
589 | if (focused) slowPoll(); |
|
708 | if (focused) slowPoll(); | |
590 | endOperation(); |
|
709 | endOperation(); | |
591 | }); |
|
710 | }); | |
592 | } |
|
711 | } | |
593 |
function fastPoll( |
|
712 | function fastPoll() { | |
594 | var missed = false; |
|
713 | var missed = false; | |
595 | pollingFast = true; |
|
714 | pollingFast = true; | |
596 | function p() { |
|
715 | function p() { | |
597 | startOperation(); |
|
716 | startOperation(); | |
598 | var changed = readInput(); |
|
717 | var changed = readInput(); | |
599 | if (changed && keyId) { |
|
718 | if (!changed && !missed) {missed = true; poll.set(60, p);} | |
600 | if (changed == "moved" && movementKeys[keyId] == null) movementKeys[keyId] = true; |
|
|||
601 | if (changed == "changed") movementKeys[keyId] = false; |
|
|||
602 | } |
|
|||
603 | if (!changed && !missed) {missed = true; poll.set(80, p);} |
|
|||
604 | else {pollingFast = false; slowPoll();} |
|
719 | else {pollingFast = false; slowPoll();} | |
605 | endOperation(); |
|
720 | endOperation(); | |
606 | } |
|
721 | } | |
607 | poll.set(20, p); |
|
722 | poll.set(20, p); | |
608 | } |
|
723 | } | |
609 |
|
724 | |||
610 | // Inspects the textarea, compares its state (content, selection) |
|
725 | // Previnput is a hack to work with IME. If we reset the textarea | |
611 | // to the data in the editing variable, and updates the editor |
|
726 | // on every change, that breaks IME. So we look for changes | |
612 | // content or cursor if something changed. |
|
727 | // compared to the previous content instead. (Modern browsers have | |
|
728 | // events that indicate IME taking place, but these are not widely | |||
|
729 | // supported or compatible enough yet to rely on.) | |||
|
730 | var prevInput = ""; | |||
613 | function readInput() { |
|
731 | function readInput() { | |
614 | if (leaveInputAlone || !focused) return; |
|
732 | if (leaveInputAlone || !focused || hasSelection(input)) return false; | |
615 | var changed = false, text = input.value, sr = selRange(input); |
|
733 | var text = input.value; | |
616 |
if ( |
|
734 | if (text == prevInput) return false; | |
617 | var changed = editing.text != text, rs = reducedSelection; |
|
735 | shiftSelecting = null; | |
618 | var moved = changed || sr.start != editing.start || sr.end != (rs ? editing.start : editing.end); |
|
736 | var same = 0, l = Math.min(prevInput.length, text.length); | |
619 | if (!moved && !rs) return false; |
|
737 | while (same < l && prevInput[same] == text[same]) ++same; | |
620 | if (changed) { |
|
738 | if (same < prevInput.length) | |
621 | shiftSelecting = reducedSelection = null; |
|
739 | sel.from = {line: sel.from.line, ch: sel.from.ch - (prevInput.length - same)}; | |
622 | if (options.readOnly) {updateInput = true; return "changed";} |
|
740 | else if (overwrite && posEq(sel.from, sel.to)) | |
623 | } |
|
741 | sel.to = {line: sel.to.line, ch: Math.min(getLine(sel.to.line).text.length, sel.to.ch + (text.length - same))}; | |
624 |
|
742 | replaceSelection(text.slice(same), "end"); | ||
625 | // Compute selection start and end based on start/end offsets in textarea |
|
743 | prevInput = text; | |
626 | function computeOffset(n, startLine) { |
|
744 | return true; | |
627 | var pos = 0; |
|
|||
628 | for (;;) { |
|
|||
629 | var found = text.indexOf("\n", pos); |
|
|||
630 | if (found == -1 || (text.charAt(found-1) == "\r" ? found - 1 : found) >= n) |
|
|||
631 | return {line: startLine, ch: n - pos}; |
|
|||
632 | ++startLine; |
|
|||
633 | pos = found + 1; |
|
|||
634 | } |
|
|||
635 | } |
|
|||
636 | var from = computeOffset(sr.start, editing.from), |
|
|||
637 | to = computeOffset(sr.end, editing.from); |
|
|||
638 | // Here we have to take the reducedSelection hack into account, |
|
|||
639 | // so that you can, for example, press shift-up at the start of |
|
|||
640 | // your selection and have the right thing happen. |
|
|||
641 | if (rs) { |
|
|||
642 | var head = sr.start == rs.anchor ? to : from; |
|
|||
643 | var tail = shiftSelecting ? sel.to : sr.start == rs.anchor ? from : to; |
|
|||
644 | if (sel.inverted = posLess(head, tail)) { from = head; to = tail; } |
|
|||
645 | else { reducedSelection = null; from = tail; to = head; } |
|
|||
646 | } |
|
|||
647 |
|
||||
648 | // In some cases (cursor on same line as before), we don't have |
|
|||
649 | // to update the textarea content at all. |
|
|||
650 | if (from.line == to.line && from.line == sel.from.line && from.line == sel.to.line && !shiftSelecting) |
|
|||
651 | updateInput = false; |
|
|||
652 |
|
||||
653 | // Magic mess to extract precise edited range from the changed |
|
|||
654 | // string. |
|
|||
655 | if (changed) { |
|
|||
656 | var start = 0, end = text.length, len = Math.min(end, editing.text.length); |
|
|||
657 | var c, line = editing.from, nl = -1; |
|
|||
658 | while (start < len && (c = text.charAt(start)) == editing.text.charAt(start)) { |
|
|||
659 | ++start; |
|
|||
660 | if (c == "\n") {line++; nl = start;} |
|
|||
661 | } |
|
|||
662 | var ch = nl > -1 ? start - nl : start, endline = editing.to - 1, edend = editing.text.length; |
|
|||
663 | for (;;) { |
|
|||
664 | c = editing.text.charAt(edend); |
|
|||
665 | if (text.charAt(end) != c) {++end; ++edend; break;} |
|
|||
666 | if (c == "\n") endline--; |
|
|||
667 | if (edend <= start || end <= start) break; |
|
|||
668 | --end; --edend; |
|
|||
669 | } |
|
|||
670 | var nl = editing.text.lastIndexOf("\n", edend - 1), endch = nl == -1 ? edend : edend - nl - 1; |
|
|||
671 | updateLines({line: line, ch: ch}, {line: endline, ch: endch}, splitLines(text.slice(start, end)), from, to); |
|
|||
672 | if (line != endline || from.line != line) updateInput = true; |
|
|||
673 | } |
|
|||
674 | else setSelection(from, to); |
|
|||
675 |
|
||||
676 | editing.text = text; editing.start = sr.start; editing.end = sr.end; |
|
|||
677 | return changed ? "changed" : moved ? "moved" : false; |
|
|||
678 | } |
|
745 | } | |
679 |
|
746 | function resetInput(user) { | ||
680 | // Set the textarea content and selection range to match the |
|
747 | if (!posEq(sel.from, sel.to)) { | |
681 | // editor state. |
|
748 | prevInput = ""; | |
682 | function prepareInput() { |
|
749 | input.value = getSelection(); | |
683 | var text = []; |
|
750 | input.select(); | |
684 | var from = Math.max(0, sel.from.line - 1), to = Math.min(lines.length, sel.to.line + 2); |
|
751 | } else if (user) prevInput = input.value = ""; | |
685 | for (var i = from; i < to; ++i) text.push(lines[i].text); |
|
|||
686 | text = input.value = text.join(lineSep); |
|
|||
687 | var startch = sel.from.ch, endch = sel.to.ch; |
|
|||
688 | for (var i = from; i < sel.from.line; ++i) |
|
|||
689 | startch += lineSep.length + lines[i].text.length; |
|
|||
690 | for (var i = from; i < sel.to.line; ++i) |
|
|||
691 | endch += lineSep.length + lines[i].text.length; |
|
|||
692 | editing = {text: text, from: from, to: to, start: startch, end: endch}; |
|
|||
693 | setSelRange(input, startch, reducedSelection ? startch : endch); |
|
|||
694 | } |
|
752 | } | |
|
753 | ||||
695 | function focusInput() { |
|
754 | function focusInput() { | |
696 |
if (options.readOnly |
|
755 | if (!options.readOnly) input.focus(); | |
697 | } |
|
756 | } | |
698 |
|
757 | |||
699 | function scrollEditorIntoView() { |
|
758 | function scrollEditorIntoView() { | |
700 | if (!cursor.getBoundingClientRect) return; |
|
759 | if (!cursor.getBoundingClientRect) return; | |
701 | var rect = cursor.getBoundingClientRect(); |
|
760 | var rect = cursor.getBoundingClientRect(); | |
702 | var winH = window.innerHeight || document.body.offsetHeight || document.documentElement.offsetHeight; |
|
761 | // IE returns bogus coordinates when the instance sits inside of an iframe and the cursor is hidden | |
|
762 | if (ie && rect.top == rect.bottom) return; | |||
|
763 | var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight); | |||
703 | if (rect.top < 0 || rect.bottom > winH) cursor.scrollIntoView(); |
|
764 | if (rect.top < 0 || rect.bottom > winH) cursor.scrollIntoView(); | |
704 | } |
|
765 | } | |
705 | function scrollCursorIntoView() { |
|
766 | function scrollCursorIntoView() { | |
706 | var cursor = localCoords(sel.inverted ? sel.from : sel.to); |
|
767 | var cursor = localCoords(sel.inverted ? sel.from : sel.to); | |
707 | return scrollIntoView(cursor.x, cursor.y, cursor.x, cursor.yBot); |
|
768 | var x = options.lineWrapping ? Math.min(cursor.x, lineSpace.offsetWidth) : cursor.x; | |
|
769 | return scrollIntoView(x, cursor.y, x, cursor.yBot); | |||
708 | } |
|
770 | } | |
709 | function scrollIntoView(x1, y1, x2, y2) { |
|
771 | function scrollIntoView(x1, y1, x2, y2) { | |
710 |
var pl = paddingLeft(), pt = paddingTop(), lh = |
|
772 | var pl = paddingLeft(), pt = paddingTop(), lh = textHeight(); | |
711 | y1 += pt; y2 += pt; x1 += pl; x2 += pl; |
|
773 | y1 += pt; y2 += pt; x1 += pl; x2 += pl; | |
712 | var screen = scroller.clientHeight, screentop = scroller.scrollTop, scrolled = false, result = true; |
|
774 | var screen = scroller.clientHeight, screentop = scroller.scrollTop, scrolled = false, result = true; | |
713 | if (y1 < screentop) {scroller.scrollTop = Math.max(0, y1 - 2*lh); scrolled = true;} |
|
775 | if (y1 < screentop) {scroller.scrollTop = Math.max(0, y1 - 2*lh); scrolled = true;} | |
@@ -720,7 +782,7 b' var CodeMirror = (function() {' | |||||
720 | scroller.scrollLeft = Math.max(0, x1 - 10 - gutterw); |
|
782 | scroller.scrollLeft = Math.max(0, x1 - 10 - gutterw); | |
721 | scrolled = true; |
|
783 | scrolled = true; | |
722 | } |
|
784 | } | |
723 | else if (x2 > screenw + screenleft) { |
|
785 | else if (x2 > screenw + screenleft - 3) { | |
724 | scroller.scrollLeft = x2 + 10 - screenw; |
|
786 | scroller.scrollLeft = x2 + 10 - screenw; | |
725 | scrolled = true; |
|
787 | scrolled = true; | |
726 | if (x2 > code.clientWidth) result = false; |
|
788 | if (x2 > code.clientWidth) result = false; | |
@@ -730,32 +792,107 b' var CodeMirror = (function() {' | |||||
730 | } |
|
792 | } | |
731 |
|
793 | |||
732 | function visibleLines() { |
|
794 | function visibleLines() { | |
733 |
var lh = |
|
795 | var lh = textHeight(), top = scroller.scrollTop - paddingTop(); | |
734 |
r |
|
796 | var from_height = Math.max(0, Math.floor(top / lh)); | |
735 |
|
|
797 | var to_height = Math.ceil((top + scroller.clientHeight) / lh); | |
|
798 | return {from: lineAtHeight(doc, from_height), | |||
|
799 | to: lineAtHeight(doc, to_height)}; | |||
736 | } |
|
800 | } | |
737 | // Uses a set of changes plus the current scroll position to |
|
801 | // Uses a set of changes plus the current scroll position to | |
738 | // determine which DOM updates have to be made, and makes the |
|
802 | // determine which DOM updates have to be made, and makes the | |
739 | // updates. |
|
803 | // updates. | |
740 | function updateDisplay(changes) { |
|
804 | function updateDisplay(changes, suppressCallback) { | |
741 | if (!scroller.clientWidth) { |
|
805 | if (!scroller.clientWidth) { | |
742 | showingFrom = showingTo = 0; |
|
806 | showingFrom = showingTo = displayOffset = 0; | |
743 | return; |
|
807 | return; | |
744 | } |
|
808 | } | |
745 | // First create a range of theoretically intact lines, and punch |
|
809 | // Compute the new visible window | |
746 | // holes in that using the change info. |
|
810 | var visible = visibleLines(); | |
747 | var intact = changes === true ? [] : [{from: showingFrom, to: showingTo, domStart: 0}]; |
|
811 | // Bail out if the visible area is already rendered and nothing changed. | |
|
812 | if (changes !== true && changes.length == 0 && visible.from >= showingFrom && visible.to <= showingTo) return; | |||
|
813 | var from = Math.max(visible.from - 100, 0), to = Math.min(doc.size, visible.to + 100); | |||
|
814 | if (showingFrom < from && from - showingFrom < 20) from = showingFrom; | |||
|
815 | if (showingTo > to && showingTo - to < 20) to = Math.min(doc.size, showingTo); | |||
|
816 | ||||
|
817 | // Create a range of theoretically intact lines, and punch holes | |||
|
818 | // in that using the change info. | |||
|
819 | var intact = changes === true ? [] : | |||
|
820 | computeIntact([{from: showingFrom, to: showingTo, domStart: 0}], changes); | |||
|
821 | // Clip off the parts that won't be visible | |||
|
822 | var intactLines = 0; | |||
|
823 | for (var i = 0; i < intact.length; ++i) { | |||
|
824 | var range = intact[i]; | |||
|
825 | if (range.from < from) {range.domStart += (from - range.from); range.from = from;} | |||
|
826 | if (range.to > to) range.to = to; | |||
|
827 | if (range.from >= range.to) intact.splice(i--, 1); | |||
|
828 | else intactLines += range.to - range.from; | |||
|
829 | } | |||
|
830 | if (intactLines == to - from) return; | |||
|
831 | intact.sort(function(a, b) {return a.domStart - b.domStart;}); | |||
|
832 | ||||
|
833 | var th = textHeight(), gutterDisplay = gutter.style.display; | |||
|
834 | lineDiv.style.display = gutter.style.display = "none"; | |||
|
835 | patchDisplay(from, to, intact); | |||
|
836 | lineDiv.style.display = ""; | |||
|
837 | ||||
|
838 | // Position the mover div to align with the lines it's supposed | |||
|
839 | // to be showing (which will cover the visible display) | |||
|
840 | var different = from != showingFrom || to != showingTo || lastSizeC != scroller.clientHeight + th; | |||
|
841 | // This is just a bogus formula that detects when the editor is | |||
|
842 | // resized or the font size changes. | |||
|
843 | if (different) lastSizeC = scroller.clientHeight + th; | |||
|
844 | showingFrom = from; showingTo = to; | |||
|
845 | displayOffset = heightAtLine(doc, from); | |||
|
846 | mover.style.top = (displayOffset * th) + "px"; | |||
|
847 | code.style.height = (doc.height * th + 2 * paddingTop()) + "px"; | |||
|
848 | ||||
|
849 | // Since this is all rather error prone, it is honoured with the | |||
|
850 | // only assertion in the whole file. | |||
|
851 | if (lineDiv.childNodes.length != showingTo - showingFrom) | |||
|
852 | throw new Error("BAD PATCH! " + JSON.stringify(intact) + " size=" + (showingTo - showingFrom) + | |||
|
853 | " nodes=" + lineDiv.childNodes.length); | |||
|
854 | ||||
|
855 | if (options.lineWrapping) { | |||
|
856 | maxWidth = scroller.clientWidth; | |||
|
857 | var curNode = lineDiv.firstChild; | |||
|
858 | doc.iter(showingFrom, showingTo, function(line) { | |||
|
859 | if (!line.hidden) { | |||
|
860 | var height = Math.round(curNode.offsetHeight / th) || 1; | |||
|
861 | if (line.height != height) {updateLineHeight(line, height); gutterDirty = true;} | |||
|
862 | } | |||
|
863 | curNode = curNode.nextSibling; | |||
|
864 | }); | |||
|
865 | } else { | |||
|
866 | if (maxWidth == null) maxWidth = stringWidth(maxLine); | |||
|
867 | if (maxWidth > scroller.clientWidth) { | |||
|
868 | lineSpace.style.width = maxWidth + "px"; | |||
|
869 | // Needed to prevent odd wrapping/hiding of widgets placed in here. | |||
|
870 | code.style.width = ""; | |||
|
871 | code.style.width = scroller.scrollWidth + "px"; | |||
|
872 | } else { | |||
|
873 | lineSpace.style.width = code.style.width = ""; | |||
|
874 | } | |||
|
875 | } | |||
|
876 | gutter.style.display = gutterDisplay; | |||
|
877 | if (different || gutterDirty) updateGutter(); | |||
|
878 | updateCursor(); | |||
|
879 | if (!suppressCallback && options.onUpdate) options.onUpdate(instance); | |||
|
880 | return true; | |||
|
881 | } | |||
|
882 | ||||
|
883 | function computeIntact(intact, changes) { | |||
748 | for (var i = 0, l = changes.length || 0; i < l; ++i) { |
|
884 | for (var i = 0, l = changes.length || 0; i < l; ++i) { | |
749 | var change = changes[i], intact2 = [], diff = change.diff || 0; |
|
885 | var change = changes[i], intact2 = [], diff = change.diff || 0; | |
750 | for (var j = 0, l2 = intact.length; j < l2; ++j) { |
|
886 | for (var j = 0, l2 = intact.length; j < l2; ++j) { | |
751 | var range = intact[j]; |
|
887 | var range = intact[j]; | |
752 | if (change.to <= range.from) |
|
888 | if (change.to <= range.from && change.diff) | |
753 |
intact2.push({from: range.from + diff, to: range.to + diff, |
|
889 | intact2.push({from: range.from + diff, to: range.to + diff, | |
754 | else if (range.to <= change.from) |
|
890 | domStart: range.domStart}); | |
|
891 | else if (change.to <= range.from || change.from >= range.to) | |||
755 | intact2.push(range); |
|
892 | intact2.push(range); | |
756 | else { |
|
893 | else { | |
757 | if (change.from > range.from) |
|
894 | if (change.from > range.from) | |
758 | intact2.push({from: range.from, to: change.from, domStart: range.domStart}) |
|
895 | intact2.push({from: range.from, to: change.from, domStart: range.domStart}); | |
759 | if (change.to < range.to) |
|
896 | if (change.to < range.to) | |
760 | intact2.push({from: change.to + diff, to: range.to + diff, |
|
897 | intact2.push({from: change.to + diff, to: range.to + diff, | |
761 | domStart: range.domStart + (change.to - range.from)}); |
|
898 | domStart: range.domStart + (change.to - range.from)}); | |
@@ -763,148 +900,75 b' var CodeMirror = (function() {' | |||||
763 | } |
|
900 | } | |
764 | intact = intact2; |
|
901 | intact = intact2; | |
765 | } |
|
902 | } | |
|
903 | return intact; | |||
|
904 | } | |||
766 |
|
905 | |||
767 | // Then, determine which lines we'd want to see, and which |
|
906 | function patchDisplay(from, to, intact) { | |
768 | // updates have to be made to get there. |
|
907 | // The first pass removes the DOM nodes that aren't intact. | |
769 | var visible = visibleLines(); |
|
908 | if (!intact.length) lineDiv.innerHTML = ""; | |
770 | var from = Math.min(showingFrom, Math.max(visible.from - 3, 0)), |
|
909 | else { | |
771 | to = Math.min(lines.length, Math.max(showingTo, visible.to + 3)), |
|
910 | function killNode(node) { | |
772 | updates = [], domPos = 0, domEnd = showingTo - showingFrom, pos = from, changedLines = 0; |
|
911 | var tmp = node.nextSibling; | |
773 |
|
912 | node.parentNode.removeChild(node); | ||
774 | for (var i = 0, l = intact.length; i < l; ++i) { |
|
913 | return tmp; | |
775 | var range = intact[i]; |
|
|||
776 | if (range.to <= from) continue; |
|
|||
777 | if (range.from >= to) break; |
|
|||
778 | if (range.domStart > domPos || range.from > pos) { |
|
|||
779 | updates.push({from: pos, to: range.from, domSize: range.domStart - domPos, domStart: domPos}); |
|
|||
780 | changedLines += range.from - pos; |
|
|||
781 | } |
|
914 | } | |
782 | pos = range.to; |
|
915 | var domPos = 0, curNode = lineDiv.firstChild, n; | |
783 | domPos = range.domStart + (range.to - range.from); |
|
916 | for (var i = 0; i < intact.length; ++i) { | |
784 | } |
|
917 | var cur = intact[i]; | |
785 | if (domPos != domEnd || pos != to) { |
|
918 | while (cur.domStart > domPos) {curNode = killNode(curNode); domPos++;} | |
786 | changedLines += Math.abs(to - pos); |
|
919 | for (var j = 0, e = cur.to - cur.from; j < e; ++j) {curNode = curNode.nextSibling; domPos++;} | |
787 | updates.push({from: pos, to: to, domSize: domEnd - domPos, domStart: domPos}); |
|
920 | } | |
788 | if (to - pos != domEnd - domPos) gutterDirty = true; |
|
921 | while (curNode) curNode = killNode(curNode); | |
789 | } |
|
|||
790 |
|
||||
791 | if (!updates.length) return; |
|
|||
792 | lineDiv.style.display = "none"; |
|
|||
793 | // If more than 30% of the screen needs update, just do a full |
|
|||
794 | // redraw (which is quicker than patching) |
|
|||
795 | if (changedLines > (visible.to - visible.from) * .3) |
|
|||
796 | refreshDisplay(from = Math.max(visible.from - 10, 0), to = Math.min(visible.to + 7, lines.length)); |
|
|||
797 | // Otherwise, only update the stuff that needs updating. |
|
|||
798 | else |
|
|||
799 | patchDisplay(updates); |
|
|||
800 | lineDiv.style.display = ""; |
|
|||
801 |
|
||||
802 | // Position the mover div to align with the lines it's supposed |
|
|||
803 | // to be showing (which will cover the visible display) |
|
|||
804 | var different = from != showingFrom || to != showingTo || lastHeight != scroller.clientHeight; |
|
|||
805 | showingFrom = from; showingTo = to; |
|
|||
806 | mover.style.top = (from * lineHeight()) + "px"; |
|
|||
807 | if (different) { |
|
|||
808 | lastHeight = scroller.clientHeight; |
|
|||
809 | code.style.height = (lines.length * lineHeight() + 2 * paddingTop()) + "px"; |
|
|||
810 | } |
|
|||
811 | if (different || gutterDirty) updateGutter(); |
|
|||
812 |
|
||||
813 | if (maxWidth == null) maxWidth = stringWidth(maxLine); |
|
|||
814 | if (maxWidth > scroller.clientWidth) { |
|
|||
815 | lineSpace.style.width = maxWidth + "px"; |
|
|||
816 | // Needed to prevent odd wrapping/hiding of widgets placed in here. |
|
|||
817 | code.style.width = ""; |
|
|||
818 | code.style.width = scroller.scrollWidth + "px"; |
|
|||
819 | } else { |
|
|||
820 | lineSpace.style.width = code.style.width = ""; |
|
|||
821 | } |
|
922 | } | |
822 |
|
923 | // This pass fills in the lines that actually changed. | ||
823 | // Since this is all rather error prone, it is honoured with the |
|
924 | var nextIntact = intact.shift(), curNode = lineDiv.firstChild, j = from; | |
824 | // only assertion in the whole file. |
|
925 | var sfrom = sel.from.line, sto = sel.to.line, inSel = sfrom < from && sto >= from; | |
825 | if (lineDiv.childNodes.length != showingTo - showingFrom) |
|
926 | var scratch = targetDocument.createElement("div"), newElt; | |
826 | throw new Error("BAD PATCH! " + JSON.stringify(updates) + " size=" + (showingTo - showingFrom) + |
|
927 | doc.iter(from, to, function(line) { | |
827 | " nodes=" + lineDiv.childNodes.length); |
|
|||
828 | updateCursor(); |
|
|||
829 | } |
|
|||
830 |
|
||||
831 | function refreshDisplay(from, to) { |
|
|||
832 | var html = [], start = {line: from, ch: 0}, inSel = posLess(sel.from, start) && !posLess(sel.to, start); |
|
|||
833 | for (var i = from; i < to; ++i) { |
|
|||
834 | var ch1 = null, ch2 = null; |
|
928 | var ch1 = null, ch2 = null; | |
835 | if (inSel) { |
|
929 | if (inSel) { | |
836 | ch1 = 0; |
|
930 | ch1 = 0; | |
837 |
if (s |
|
931 | if (sto == j) {inSel = false; ch2 = sel.to.ch;} | |
838 | } |
|
932 | } else if (sfrom == j) { | |
839 | else if (sel.from.line == i) { |
|
933 | if (sto == j) {ch1 = sel.from.ch; ch2 = sel.to.ch;} | |
840 | if (sel.to.line == i) {ch1 = sel.from.ch; ch2 = sel.to.ch;} |
|
|||
841 | else {inSel = true; ch1 = sel.from.ch;} |
|
934 | else {inSel = true; ch1 = sel.from.ch;} | |
842 | } |
|
935 | } | |
843 | html.push(lines[i].getHTML(ch1, ch2, true)); |
|
936 | if (nextIntact && nextIntact.to == j) nextIntact = intact.shift(); | |
844 | } |
|
937 | if (!nextIntact || nextIntact.from > j) { | |
845 | lineDiv.innerHTML = html.join(""); |
|
938 | if (line.hidden) scratch.innerHTML = "<pre></pre>"; | |
846 | } |
|
939 | else scratch.innerHTML = line.getHTML(ch1, ch2, true, tabText); | |
847 | function patchDisplay(updates) { |
|
940 | lineDiv.insertBefore(scratch.firstChild, curNode); | |
848 | // Slightly different algorithm for IE (badInnerHTML), since |
|
941 | } else { | |
849 | // there .innerHTML on PRE nodes is dumb, and discards |
|
942 | curNode = curNode.nextSibling; | |
850 | // whitespace. |
|
|||
851 | var sfrom = sel.from.line, sto = sel.to.line, off = 0, |
|
|||
852 | scratch = badInnerHTML && targetDocument.createElement("div"); |
|
|||
853 | for (var i = 0, e = updates.length; i < e; ++i) { |
|
|||
854 | var rec = updates[i]; |
|
|||
855 | var extra = (rec.to - rec.from) - rec.domSize; |
|
|||
856 | var nodeAfter = lineDiv.childNodes[rec.domStart + rec.domSize + off] || null; |
|
|||
857 | if (badInnerHTML) |
|
|||
858 | for (var j = Math.max(-extra, rec.domSize); j > 0; --j) |
|
|||
859 | lineDiv.removeChild(nodeAfter ? nodeAfter.previousSibling : lineDiv.lastChild); |
|
|||
860 | else if (extra) { |
|
|||
861 | for (var j = Math.max(0, extra); j > 0; --j) |
|
|||
862 | lineDiv.insertBefore(targetDocument.createElement("pre"), nodeAfter); |
|
|||
863 | for (var j = Math.max(0, -extra); j > 0; --j) |
|
|||
864 | lineDiv.removeChild(nodeAfter ? nodeAfter.previousSibling : lineDiv.lastChild); |
|
|||
865 | } |
|
|||
866 | var node = lineDiv.childNodes[rec.domStart + off], inSel = sfrom < rec.from && sto >= rec.from; |
|
|||
867 | for (var j = rec.from; j < rec.to; ++j) { |
|
|||
868 | var ch1 = null, ch2 = null; |
|
|||
869 | if (inSel) { |
|
|||
870 | ch1 = 0; |
|
|||
871 | if (sto == j) {inSel = false; ch2 = sel.to.ch;} |
|
|||
872 | } |
|
|||
873 | else if (sfrom == j) { |
|
|||
874 | if (sto == j) {ch1 = sel.from.ch; ch2 = sel.to.ch;} |
|
|||
875 | else {inSel = true; ch1 = sel.from.ch;} |
|
|||
876 | } |
|
|||
877 | if (badInnerHTML) { |
|
|||
878 | scratch.innerHTML = lines[j].getHTML(ch1, ch2, true); |
|
|||
879 | lineDiv.insertBefore(scratch.firstChild, nodeAfter); |
|
|||
880 | } |
|
|||
881 | else { |
|
|||
882 | node.innerHTML = lines[j].getHTML(ch1, ch2, false); |
|
|||
883 | node.className = lines[j].className || ""; |
|
|||
884 | node = node.nextSibling; |
|
|||
885 | } |
|
|||
886 | } |
|
943 | } | |
887 |
|
|
944 | ++j; | |
888 | } |
|
945 | }); | |
889 | } |
|
946 | } | |
890 |
|
947 | |||
891 | function updateGutter() { |
|
948 | function updateGutter() { | |
892 | if (!options.gutter && !options.lineNumbers) return; |
|
949 | if (!options.gutter && !options.lineNumbers) return; | |
893 | var hText = mover.offsetHeight, hEditor = scroller.clientHeight; |
|
950 | var hText = mover.offsetHeight, hEditor = scroller.clientHeight; | |
894 | gutter.style.height = (hText - hEditor < 2 ? hEditor : hText) + "px"; |
|
951 | gutter.style.height = (hText - hEditor < 2 ? hEditor : hText) + "px"; | |
895 | var html = []; |
|
952 | var html = [], i = showingFrom; | |
896 |
|
|
953 | doc.iter(showingFrom, Math.max(showingTo, showingFrom + 1), function(line) { | |
897 | var marker = lines[i].gutterMarker; |
|
954 | if (line.hidden) { | |
898 | var text = options.lineNumbers ? i + options.firstLineNumber : null; |
|
955 | html.push("<pre></pre>"); | |
899 | if (marker && marker.text) |
|
956 | } else { | |
900 | text = marker.text.replace("%N%", text != null ? text : ""); |
|
957 | var marker = line.gutterMarker; | |
901 | else if (text == null) |
|
958 | var text = options.lineNumbers ? i + options.firstLineNumber : null; | |
902 | text = "\u00a0"; |
|
959 | if (marker && marker.text) | |
903 | html.push((marker && marker.style ? '<pre class="' + marker.style + '">' : "<pre>"), text, "</pre>"); |
|
960 | text = marker.text.replace("%N%", text != null ? text : ""); | |
904 | } |
|
961 | else if (text == null) | |
|
962 | text = "\u00a0"; | |||
|
963 | html.push((marker && marker.style ? '<pre class="' + marker.style + '">' : "<pre>"), text); | |||
|
964 | for (var j = 1; j < line.height; ++j) html.push("<br/> "); | |||
|
965 | html.push("</pre>"); | |||
|
966 | } | |||
|
967 | ++i; | |||
|
968 | }); | |||
905 | gutter.style.display = "none"; |
|
969 | gutter.style.display = "none"; | |
906 | gutterText.innerHTML = html.join(""); |
|
970 | gutterText.innerHTML = html.join(""); | |
907 |
var minwidth = String( |
|
971 | var minwidth = String(doc.size).length, firstNode = gutterText.firstChild, val = eltText(firstNode), pad = ""; | |
908 | while (val.length + pad.length < minwidth) pad += "\u00a0"; |
|
972 | while (val.length + pad.length < minwidth) pad += "\u00a0"; | |
909 | if (pad) firstNode.insertBefore(targetDocument.createTextNode(pad), firstNode.firstChild); |
|
973 | if (pad) firstNode.insertBefore(targetDocument.createTextNode(pad), firstNode.firstChild); | |
910 | gutter.style.display = ""; |
|
974 | gutter.style.display = ""; | |
@@ -912,19 +976,23 b' var CodeMirror = (function() {' | |||||
912 | gutterDirty = false; |
|
976 | gutterDirty = false; | |
913 | } |
|
977 | } | |
914 | function updateCursor() { |
|
978 | function updateCursor() { | |
915 |
var head = sel.inverted ? sel.from : sel.to, lh = |
|
979 | var head = sel.inverted ? sel.from : sel.to, lh = textHeight(); | |
916 |
var |
|
980 | var pos = localCoords(head, true); | |
917 | var top = head.line * lh - scroller.scrollTop; |
|
981 | var wrapOff = eltOffset(wrapper), lineOff = eltOffset(lineDiv); | |
918 |
inputDiv.style.top = |
|
982 | inputDiv.style.top = (pos.y + lineOff.top - wrapOff.top) + "px"; | |
919 |
inputDiv.style.left = (x - |
|
983 | inputDiv.style.left = (pos.x + lineOff.left - wrapOff.left) + "px"; | |
920 | if (posEq(sel.from, sel.to)) { |
|
984 | if (posEq(sel.from, sel.to)) { | |
921 |
cursor.style.top = |
|
985 | cursor.style.top = pos.y + "px"; | |
922 | cursor.style.left = x + "px"; |
|
986 | cursor.style.left = (options.lineWrapping ? Math.min(pos.x, lineSpace.offsetWidth) : pos.x) + "px"; | |
923 | cursor.style.display = ""; |
|
987 | cursor.style.display = ""; | |
924 | } |
|
988 | } | |
925 | else cursor.style.display = "none"; |
|
989 | else cursor.style.display = "none"; | |
926 | } |
|
990 | } | |
927 |
|
991 | |||
|
992 | function setShift(val) { | |||
|
993 | if (val) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from); | |||
|
994 | else shiftSelecting = null; | |||
|
995 | } | |||
928 | function setSelectionUser(from, to) { |
|
996 | function setSelectionUser(from, to) { | |
929 | var sh = shiftSelecting && clipPos(shiftSelecting); |
|
997 | var sh = shiftSelecting && clipPos(shiftSelecting); | |
930 | if (sh) { |
|
998 | if (sh) { | |
@@ -932,14 +1000,21 b' var CodeMirror = (function() {' | |||||
932 | else if (posLess(to, sh)) to = sh; |
|
1000 | else if (posLess(to, sh)) to = sh; | |
933 | } |
|
1001 | } | |
934 | setSelection(from, to); |
|
1002 | setSelection(from, to); | |
|
1003 | userSelChange = true; | |||
935 | } |
|
1004 | } | |
936 | // Update the selection. Last two args are only used by |
|
1005 | // Update the selection. Last two args are only used by | |
937 | // updateLines, since they have to be expressed in the line |
|
1006 | // updateLines, since they have to be expressed in the line | |
938 | // numbers before the update. |
|
1007 | // numbers before the update. | |
939 | function setSelection(from, to, oldFrom, oldTo) { |
|
1008 | function setSelection(from, to, oldFrom, oldTo) { | |
|
1009 | goalColumn = null; | |||
|
1010 | if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;} | |||
940 | if (posEq(sel.from, from) && posEq(sel.to, to)) return; |
|
1011 | if (posEq(sel.from, from) && posEq(sel.to, to)) return; | |
941 | if (posLess(to, from)) {var tmp = to; to = from; from = tmp;} |
|
1012 | if (posLess(to, from)) {var tmp = to; to = from; from = tmp;} | |
942 |
|
1013 | |||
|
1014 | // Skip over hidden lines. | |||
|
1015 | if (from.line != oldFrom) from = skipHidden(from, oldFrom, sel.from.ch); | |||
|
1016 | if (to.line != oldTo) to = skipHidden(to, oldTo, sel.to.ch); | |||
|
1017 | ||||
943 | if (posEq(from, to)) sel.inverted = false; |
|
1018 | if (posEq(from, to)) sel.inverted = false; | |
944 | else if (posEq(from, sel.to)) sel.inverted = false; |
|
1019 | else if (posEq(from, sel.to)) sel.inverted = false; | |
945 | else if (posEq(to, sel.from)) sel.inverted = true; |
|
1020 | else if (posEq(to, sel.from)) sel.inverted = true; | |
@@ -947,7 +1022,6 b' var CodeMirror = (function() {' | |||||
947 | // Some ugly logic used to only mark the lines that actually did |
|
1022 | // Some ugly logic used to only mark the lines that actually did | |
948 | // see a change in selection as changed, rather than the whole |
|
1023 | // see a change in selection as changed, rather than the whole | |
949 | // selected range. |
|
1024 | // selected range. | |
950 | if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;} |
|
|||
951 | if (posEq(from, to)) { |
|
1025 | if (posEq(from, to)) { | |
952 | if (!posEq(sel.from, sel.to)) |
|
1026 | if (!posEq(sel.from, sel.to)) | |
953 | changes.push({from: oldFrom, to: oldTo + 1}); |
|
1027 | changes.push({from: oldFrom, to: oldTo + 1}); | |
@@ -972,90 +1046,120 b' var CodeMirror = (function() {' | |||||
972 | sel.from = from; sel.to = to; |
|
1046 | sel.from = from; sel.to = to; | |
973 | selectionChanged = true; |
|
1047 | selectionChanged = true; | |
974 | } |
|
1048 | } | |
|
1049 | function skipHidden(pos, oldLine, oldCh) { | |||
|
1050 | function getNonHidden(dir) { | |||
|
1051 | var lNo = pos.line + dir, end = dir == 1 ? doc.size : -1; | |||
|
1052 | while (lNo != end) { | |||
|
1053 | var line = getLine(lNo); | |||
|
1054 | if (!line.hidden) { | |||
|
1055 | var ch = pos.ch; | |||
|
1056 | if (ch > oldCh || ch > line.text.length) ch = line.text.length; | |||
|
1057 | return {line: lNo, ch: ch}; | |||
|
1058 | } | |||
|
1059 | lNo += dir; | |||
|
1060 | } | |||
|
1061 | } | |||
|
1062 | var line = getLine(pos.line); | |||
|
1063 | if (!line.hidden) return pos; | |||
|
1064 | if (pos.line >= oldLine) return getNonHidden(1) || getNonHidden(-1); | |||
|
1065 | else return getNonHidden(-1) || getNonHidden(1); | |||
|
1066 | } | |||
975 | function setCursor(line, ch, user) { |
|
1067 | function setCursor(line, ch, user) { | |
976 | var pos = clipPos({line: line, ch: ch || 0}); |
|
1068 | var pos = clipPos({line: line, ch: ch || 0}); | |
977 | (user ? setSelectionUser : setSelection)(pos, pos); |
|
1069 | (user ? setSelectionUser : setSelection)(pos, pos); | |
978 | } |
|
1070 | } | |
979 |
|
1071 | |||
980 |
function clipLine(n) {return Math.max(0, Math.min(n, |
|
1072 | function clipLine(n) {return Math.max(0, Math.min(n, doc.size-1));} | |
981 | function clipPos(pos) { |
|
1073 | function clipPos(pos) { | |
982 | if (pos.line < 0) return {line: 0, ch: 0}; |
|
1074 | if (pos.line < 0) return {line: 0, ch: 0}; | |
983 |
if (pos.line >= |
|
1075 | if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc.size-1).text.length}; | |
984 |
var ch = pos.ch, linelen = |
|
1076 | var ch = pos.ch, linelen = getLine(pos.line).text.length; | |
985 | if (ch == null || ch > linelen) return {line: pos.line, ch: linelen}; |
|
1077 | if (ch == null || ch > linelen) return {line: pos.line, ch: linelen}; | |
986 | else if (ch < 0) return {line: pos.line, ch: 0}; |
|
1078 | else if (ch < 0) return {line: pos.line, ch: 0}; | |
987 | else return pos; |
|
1079 | else return pos; | |
988 | } |
|
1080 | } | |
989 |
|
1081 | |||
990 |
function |
|
1082 | function findPosH(dir, unit) { | |
991 | var linesPerPage = Math.floor(scroller.clientHeight / lineHeight()), head = sel.inverted ? sel.from : sel.to; |
|
1083 | var end = sel.inverted ? sel.from : sel.to, line = end.line, ch = end.ch; | |
992 | setCursor(head.line + (Math.max(linesPerPage - 1, 1) * (down ? 1 : -1)), head.ch, true); |
|
1084 | var lineObj = getLine(line); | |
|
1085 | function findNextLine() { | |||
|
1086 | for (var l = line + dir, e = dir < 0 ? -1 : doc.size; l != e; l += dir) { | |||
|
1087 | var lo = getLine(l); | |||
|
1088 | if (!lo.hidden) { line = l; lineObj = lo; return true; } | |||
|
1089 | } | |||
|
1090 | } | |||
|
1091 | function moveOnce(boundToLine) { | |||
|
1092 | if (ch == (dir < 0 ? 0 : lineObj.text.length)) { | |||
|
1093 | if (!boundToLine && findNextLine()) ch = dir < 0 ? lineObj.text.length : 0; | |||
|
1094 | else return false; | |||
|
1095 | } else ch += dir; | |||
|
1096 | return true; | |||
|
1097 | } | |||
|
1098 | if (unit == "char") moveOnce(); | |||
|
1099 | else if (unit == "column") moveOnce(true); | |||
|
1100 | else if (unit == "word") { | |||
|
1101 | var sawWord = false; | |||
|
1102 | for (;;) { | |||
|
1103 | if (dir < 0) if (!moveOnce()) break; | |||
|
1104 | if (isWordChar(lineObj.text.charAt(ch))) sawWord = true; | |||
|
1105 | else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;} | |||
|
1106 | if (dir > 0) if (!moveOnce()) break; | |||
|
1107 | } | |||
|
1108 | } | |||
|
1109 | return {line: line, ch: ch}; | |||
993 | } |
|
1110 | } | |
994 |
function |
|
1111 | function moveH(dir, unit) { | |
995 | var pos = top ? {line: 0, ch: 0} : {line: lines.length - 1, ch: lines[lines.length-1].text.length}; |
|
1112 | var pos = dir < 0 ? sel.from : sel.to; | |
996 | setSelectionUser(pos, pos); |
|
1113 | if (shiftSelecting || posEq(sel.from, sel.to)) pos = findPosH(dir, unit); | |
|
1114 | setCursor(pos.line, pos.ch, true); | |||
997 | } |
|
1115 | } | |
998 |
function |
|
1116 | function deleteH(dir, unit) { | |
999 | var endLine = lines.length - 1; |
|
1117 | if (!posEq(sel.from, sel.to)) replaceRange("", sel.from, sel.to); | |
1000 | setSelection({line: 0, ch: 0}, {line: endLine, ch: lines[endLine].text.length}); |
|
1118 | else if (dir < 0) replaceRange("", findPosH(dir, unit), sel.to); | |
|
1119 | else replaceRange("", sel.from, findPosH(dir, unit)); | |||
|
1120 | userSelChange = true; | |||
1001 | } |
|
1121 | } | |
|
1122 | var goalColumn = null; | |||
|
1123 | function moveV(dir, unit) { | |||
|
1124 | var dist = 0, pos = localCoords(sel.inverted ? sel.from : sel.to, true); | |||
|
1125 | if (goalColumn != null) pos.x = goalColumn; | |||
|
1126 | if (unit == "page") dist = scroller.clientHeight; | |||
|
1127 | else if (unit == "line") dist = textHeight(); | |||
|
1128 | var target = coordsChar(pos.x, pos.y + dist * dir + 2); | |||
|
1129 | setCursor(target.line, target.ch, true); | |||
|
1130 | goalColumn = pos.x; | |||
|
1131 | } | |||
|
1132 | ||||
1002 | function selectWordAt(pos) { |
|
1133 | function selectWordAt(pos) { | |
1003 |
var line = |
|
1134 | var line = getLine(pos.line).text; | |
1004 | var start = pos.ch, end = pos.ch; |
|
1135 | var start = pos.ch, end = pos.ch; | |
1005 |
while (start > 0 && |
|
1136 | while (start > 0 && isWordChar(line.charAt(start - 1))) --start; | |
1006 |
while (end < line.length && |
|
1137 | while (end < line.length && isWordChar(line.charAt(end))) ++end; | |
1007 | setSelectionUser({line: pos.line, ch: start}, {line: pos.line, ch: end}); |
|
1138 | setSelectionUser({line: pos.line, ch: start}, {line: pos.line, ch: end}); | |
1008 | } |
|
1139 | } | |
1009 | function selectLine(line) { |
|
1140 | function selectLine(line) { | |
1010 |
setSelectionUser({line: line, ch: 0}, {line: line, ch: |
|
1141 | setSelectionUser({line: line, ch: 0}, {line: line, ch: getLine(line).text.length}); | |
1011 | } |
|
1142 | } | |
1012 |
function |
|
1143 | function indentSelected(mode) { | |
1013 | replaceSelection("\n", "end"); |
|
1144 | if (posEq(sel.from, sel.to)) return indentLine(sel.from.line, mode); | |
1014 | if (options.enterMode != "flat") |
|
1145 | var e = sel.to.line - (sel.to.ch ? 0 : 1); | |
1015 | indentLine(sel.from.line, options.enterMode == "keep" ? "prev" : "smart"); |
|
1146 | for (var i = sel.from.line; i <= e; ++i) indentLine(i, mode); | |
1016 | } |
|
|||
1017 | function handleTab(shift) { |
|
|||
1018 | function indentSelected(mode) { |
|
|||
1019 | if (posEq(sel.from, sel.to)) return indentLine(sel.from.line, mode); |
|
|||
1020 | var e = sel.to.line - (sel.to.ch ? 0 : 1); |
|
|||
1021 | for (var i = sel.from.line; i <= e; ++i) indentLine(i, mode); |
|
|||
1022 | } |
|
|||
1023 | shiftSelecting = null; |
|
|||
1024 | switch (options.tabMode) { |
|
|||
1025 | case "default": |
|
|||
1026 | return false; |
|
|||
1027 | case "indent": |
|
|||
1028 | indentSelected("smart"); |
|
|||
1029 | break; |
|
|||
1030 | case "classic": |
|
|||
1031 | if (posEq(sel.from, sel.to)) { |
|
|||
1032 | if (shift) indentLine(sel.from.line, "smart"); |
|
|||
1033 | else replaceSelection("\t", "end"); |
|
|||
1034 | break; |
|
|||
1035 | } |
|
|||
1036 | case "shift": |
|
|||
1037 | indentSelected(shift ? "subtract" : "add"); |
|
|||
1038 | break; |
|
|||
1039 | } |
|
|||
1040 | return true; |
|
|||
1041 | } |
|
|||
1042 | function smartHome() { |
|
|||
1043 | var firstNonWS = Math.max(0, lines[sel.from.line].text.search(/\S/)); |
|
|||
1044 | setCursor(sel.from.line, sel.from.ch <= firstNonWS && sel.from.ch ? 0 : firstNonWS, true); |
|
|||
1045 | } |
|
1147 | } | |
1046 |
|
1148 | |||
1047 | function indentLine(n, how) { |
|
1149 | function indentLine(n, how) { | |
|
1150 | if (!how) how = "add"; | |||
1048 | if (how == "smart") { |
|
1151 | if (how == "smart") { | |
1049 | if (!mode.indent) how = "prev"; |
|
1152 | if (!mode.indent) how = "prev"; | |
1050 | else var state = getStateBefore(n); |
|
1153 | else var state = getStateBefore(n); | |
1051 | } |
|
1154 | } | |
1052 |
|
1155 | |||
1053 | var line = lines[n], curSpace = line.indentation(), curSpaceString = line.text.match(/^\s*/)[0], indentation; |
|
1156 | var line = getLine(n), curSpace = line.indentation(options.tabSize), | |
|
1157 | curSpaceString = line.text.match(/^\s*/)[0], indentation; | |||
1054 | if (how == "prev") { |
|
1158 | if (how == "prev") { | |
1055 |
if (n) indentation = |
|
1159 | if (n) indentation = getLine(n-1).indentation(options.tabSize); | |
1056 | else indentation = 0; |
|
1160 | else indentation = 0; | |
1057 | } |
|
1161 | } | |
1058 | else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length)); |
|
1162 | else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length), line.text); | |
1059 | else if (how == "add") indentation = curSpace + options.indentUnit; |
|
1163 | else if (how == "add") indentation = curSpace + options.indentUnit; | |
1060 | else if (how == "subtract") indentation = curSpace - options.indentUnit; |
|
1164 | else if (how == "subtract") indentation = curSpace - options.indentUnit; | |
1061 | indentation = Math.max(0, indentation); |
|
1165 | indentation = Math.max(0, indentation); | |
@@ -1068,7 +1172,7 b' var CodeMirror = (function() {' | |||||
1068 | else { |
|
1172 | else { | |
1069 | var indentString = "", pos = 0; |
|
1173 | var indentString = "", pos = 0; | |
1070 | if (options.indentWithTabs) |
|
1174 | if (options.indentWithTabs) | |
1071 | for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} |
|
1175 | for (var i = Math.floor(indentation / options.tabSize); i; --i) {pos += options.tabSize; indentString += "\t";} | |
1072 | while (pos < indentation) {++pos; indentString += " ";} |
|
1176 | while (pos < indentation) {++pos; indentString += " ";} | |
1073 | } |
|
1177 | } | |
1074 |
|
1178 | |||
@@ -1077,8 +1181,7 b' var CodeMirror = (function() {' | |||||
1077 |
|
1181 | |||
1078 | function loadMode() { |
|
1182 | function loadMode() { | |
1079 | mode = CodeMirror.getMode(options, options.mode); |
|
1183 | mode = CodeMirror.getMode(options, options.mode); | |
1080 | for (var i = 0, l = lines.length; i < l; ++i) |
|
1184 | doc.iter(0, doc.size, function(line) { line.stateAfter = null; }); | |
1081 | lines[i].stateAfter = null; |
|
|||
1082 | work = [0]; |
|
1185 | work = [0]; | |
1083 | startWorker(); |
|
1186 | startWorker(); | |
1084 | } |
|
1187 | } | |
@@ -1088,76 +1191,153 b' var CodeMirror = (function() {' | |||||
1088 | if (visible) gutterDirty = true; |
|
1191 | if (visible) gutterDirty = true; | |
1089 | else lineDiv.parentNode.style.marginLeft = 0; |
|
1192 | else lineDiv.parentNode.style.marginLeft = 0; | |
1090 | } |
|
1193 | } | |
|
1194 | function wrappingChanged(from, to) { | |||
|
1195 | if (options.lineWrapping) { | |||
|
1196 | wrapper.className += " CodeMirror-wrap"; | |||
|
1197 | var perLine = scroller.clientWidth / charWidth() - 3; | |||
|
1198 | doc.iter(0, doc.size, function(line) { | |||
|
1199 | if (line.hidden) return; | |||
|
1200 | var guess = Math.ceil(line.text.length / perLine) || 1; | |||
|
1201 | if (guess != 1) updateLineHeight(line, guess); | |||
|
1202 | }); | |||
|
1203 | lineSpace.style.width = code.style.width = ""; | |||
|
1204 | } else { | |||
|
1205 | wrapper.className = wrapper.className.replace(" CodeMirror-wrap", ""); | |||
|
1206 | maxWidth = null; maxLine = ""; | |||
|
1207 | doc.iter(0, doc.size, function(line) { | |||
|
1208 | if (line.height != 1 && !line.hidden) updateLineHeight(line, 1); | |||
|
1209 | if (line.text.length > maxLine.length) maxLine = line.text; | |||
|
1210 | }); | |||
|
1211 | } | |||
|
1212 | changes.push({from: 0, to: doc.size}); | |||
|
1213 | } | |||
|
1214 | function computeTabText() { | |||
|
1215 | for (var str = '<span class="cm-tab">', i = 0; i < options.tabSize; ++i) str += " "; | |||
|
1216 | return str + "</span>"; | |||
|
1217 | } | |||
|
1218 | function tabsChanged() { | |||
|
1219 | tabText = computeTabText(); | |||
|
1220 | updateDisplay(true); | |||
|
1221 | } | |||
|
1222 | function themeChanged() { | |||
|
1223 | scroller.className = scroller.className.replace(/\s*cm-s-\w+/g, "") + | |||
|
1224 | options.theme.replace(/(^|\s)\s*/g, " cm-s-"); | |||
|
1225 | } | |||
|
1226 | ||||
|
1227 | function TextMarker() { this.set = []; } | |||
|
1228 | TextMarker.prototype.clear = operation(function() { | |||
|
1229 | var min = Infinity, max = -Infinity; | |||
|
1230 | for (var i = 0, e = this.set.length; i < e; ++i) { | |||
|
1231 | var line = this.set[i], mk = line.marked; | |||
|
1232 | if (!mk || !line.parent) continue; | |||
|
1233 | var lineN = lineNo(line); | |||
|
1234 | min = Math.min(min, lineN); max = Math.max(max, lineN); | |||
|
1235 | for (var j = 0; j < mk.length; ++j) | |||
|
1236 | if (mk[j].set == this.set) mk.splice(j--, 1); | |||
|
1237 | } | |||
|
1238 | if (min != Infinity) | |||
|
1239 | changes.push({from: min, to: max + 1}); | |||
|
1240 | }); | |||
|
1241 | TextMarker.prototype.find = function() { | |||
|
1242 | var from, to; | |||
|
1243 | for (var i = 0, e = this.set.length; i < e; ++i) { | |||
|
1244 | var line = this.set[i], mk = line.marked; | |||
|
1245 | for (var j = 0; j < mk.length; ++j) { | |||
|
1246 | var mark = mk[j]; | |||
|
1247 | if (mark.set == this.set) { | |||
|
1248 | if (mark.from != null || mark.to != null) { | |||
|
1249 | var found = lineNo(line); | |||
|
1250 | if (found != null) { | |||
|
1251 | if (mark.from != null) from = {line: found, ch: mark.from}; | |||
|
1252 | if (mark.to != null) to = {line: found, ch: mark.to}; | |||
|
1253 | } | |||
|
1254 | } | |||
|
1255 | } | |||
|
1256 | } | |||
|
1257 | } | |||
|
1258 | return {from: from, to: to}; | |||
|
1259 | }; | |||
1091 |
|
1260 | |||
1092 | function markText(from, to, className) { |
|
1261 | function markText(from, to, className) { | |
1093 | from = clipPos(from); to = clipPos(to); |
|
1262 | from = clipPos(from); to = clipPos(to); | |
1094 | var accum = []; |
|
1263 | var tm = new TextMarker(); | |
1095 | function add(line, from, to, className) { |
|
1264 | function add(line, from, to, className) { | |
1096 | var line = lines[line], mark = line.addMark(from, to, className); |
|
1265 | getLine(line).addMark(new MarkedText(from, to, className, tm.set)); | |
1097 | mark.line = line; |
|
|||
1098 | accum.push(mark); |
|
|||
1099 | } |
|
1266 | } | |
1100 | if (from.line == to.line) add(from.line, from.ch, to.ch, className); |
|
1267 | if (from.line == to.line) add(from.line, from.ch, to.ch, className); | |
1101 | else { |
|
1268 | else { | |
1102 | add(from.line, from.ch, null, className); |
|
1269 | add(from.line, from.ch, null, className); | |
1103 | for (var i = from.line + 1, e = to.line; i < e; ++i) |
|
1270 | for (var i = from.line + 1, e = to.line; i < e; ++i) | |
1104 |
add(i, |
|
1271 | add(i, null, null, className); | |
1105 |
add(to.line, |
|
1272 | add(to.line, null, to.ch, className); | |
1106 | } |
|
1273 | } | |
1107 | changes.push({from: from.line, to: to.line + 1}); |
|
1274 | changes.push({from: from.line, to: to.line + 1}); | |
1108 |
return |
|
1275 | return tm; | |
1109 | var start, end; |
|
1276 | } | |
1110 | for (var i = 0; i < accum.length; ++i) { |
|
1277 | ||
1111 | var mark = accum[i], found = indexOf(lines, mark.line); |
|
1278 | function setBookmark(pos) { | |
1112 | mark.line.removeMark(mark); |
|
1279 | pos = clipPos(pos); | |
1113 | if (found > -1) { |
|
1280 | var bm = new Bookmark(pos.ch); | |
1114 | if (start == null) start = found; |
|
1281 | getLine(pos.line).addMark(bm); | |
1115 | end = found; |
|
1282 | return bm; | |
1116 | } |
|
|||
1117 | } |
|
|||
1118 | if (start != null) changes.push({from: start, to: end + 1}); |
|
|||
1119 | }; |
|
|||
1120 | } |
|
1283 | } | |
1121 |
|
1284 | |||
1122 | function addGutterMarker(line, text, className) { |
|
1285 | function addGutterMarker(line, text, className) { | |
1123 |
if (typeof line == "number") line = |
|
1286 | if (typeof line == "number") line = getLine(clipLine(line)); | |
1124 | line.gutterMarker = {text: text, style: className}; |
|
1287 | line.gutterMarker = {text: text, style: className}; | |
1125 | gutterDirty = true; |
|
1288 | gutterDirty = true; | |
1126 | return line; |
|
1289 | return line; | |
1127 | } |
|
1290 | } | |
1128 | function removeGutterMarker(line) { |
|
1291 | function removeGutterMarker(line) { | |
1129 |
if (typeof line == "number") line = |
|
1292 | if (typeof line == "number") line = getLine(clipLine(line)); | |
1130 | line.gutterMarker = null; |
|
1293 | line.gutterMarker = null; | |
1131 | gutterDirty = true; |
|
1294 | gutterDirty = true; | |
1132 | } |
|
1295 | } | |
1133 | function setLineClass(line, className) { |
|
1296 | ||
1134 | if (typeof line == "number") { |
|
1297 | function changeLine(handle, op) { | |
1135 |
|
|
1298 | var no = handle, line = handle; | |
1136 | line = lines[clipLine(line)]; |
|
1299 | if (typeof handle == "number") line = getLine(clipLine(handle)); | |
1137 | } |
|
1300 | else no = lineNo(handle); | |
1138 | else { |
|
1301 | if (no == null) return null; | |
1139 | var no = indexOf(lines, line); |
|
1302 | if (op(line, no)) changes.push({from: no, to: no + 1}); | |
1140 |
|
|
1303 | else return null; | |
1141 | } |
|
|||
1142 | if (line.className != className) { |
|
|||
1143 | line.className = className; |
|
|||
1144 | changes.push({from: no, to: no + 1}); |
|
|||
1145 | } |
|
|||
1146 | return line; |
|
1304 | return line; | |
1147 | } |
|
1305 | } | |
|
1306 | function setLineClass(handle, className) { | |||
|
1307 | return changeLine(handle, function(line) { | |||
|
1308 | if (line.className != className) { | |||
|
1309 | line.className = className; | |||
|
1310 | return true; | |||
|
1311 | } | |||
|
1312 | }); | |||
|
1313 | } | |||
|
1314 | function setLineHidden(handle, hidden) { | |||
|
1315 | return changeLine(handle, function(line, no) { | |||
|
1316 | if (line.hidden != hidden) { | |||
|
1317 | line.hidden = hidden; | |||
|
1318 | updateLineHeight(line, hidden ? 0 : 1); | |||
|
1319 | if (hidden && (sel.from.line == no || sel.to.line == no)) | |||
|
1320 | setSelection(skipHidden(sel.from, sel.from.line, sel.from.ch), | |||
|
1321 | skipHidden(sel.to, sel.to.line, sel.to.ch)); | |||
|
1322 | return (gutterDirty = true); | |||
|
1323 | } | |||
|
1324 | }); | |||
|
1325 | } | |||
1148 |
|
1326 | |||
1149 | function lineInfo(line) { |
|
1327 | function lineInfo(line) { | |
1150 | if (typeof line == "number") { |
|
1328 | if (typeof line == "number") { | |
|
1329 | if (!isLine(line)) return null; | |||
1151 | var n = line; |
|
1330 | var n = line; | |
1152 |
line = |
|
1331 | line = getLine(line); | |
1153 | if (!line) return null; |
|
1332 | if (!line) return null; | |
1154 | } |
|
1333 | } | |
1155 | else { |
|
1334 | else { | |
1156 |
var n = |
|
1335 | var n = lineNo(line); | |
1157 |
if (n == |
|
1336 | if (n == null) return null; | |
1158 | } |
|
1337 | } | |
1159 | var marker = line.gutterMarker; |
|
1338 | var marker = line.gutterMarker; | |
1160 |
return {line: n, text: line.text, markerText: marker && marker.text, |
|
1339 | return {line: n, handle: line, text: line.text, markerText: marker && marker.text, | |
|
1340 | markerClass: marker && marker.style, lineClass: line.className}; | |||
1161 | } |
|
1341 | } | |
1162 |
|
1342 | |||
1163 | function stringWidth(str) { |
|
1343 | function stringWidth(str) { | |
@@ -1167,21 +1347,16 b' var CodeMirror = (function() {' | |||||
1167 | } |
|
1347 | } | |
1168 | // These are used to go from pixel positions to character |
|
1348 | // These are used to go from pixel positions to character | |
1169 | // positions, taking varying character widths into account. |
|
1349 | // positions, taking varying character widths into account. | |
1170 | function charX(line, pos) { |
|
|||
1171 | if (pos == 0) return 0; |
|
|||
1172 | measure.innerHTML = "<pre><span>" + lines[line].getHTML(null, null, false, pos) + "</span></pre>"; |
|
|||
1173 | return measure.firstChild.firstChild.offsetWidth; |
|
|||
1174 | } |
|
|||
1175 | function charFromX(line, x) { |
|
1350 | function charFromX(line, x) { | |
1176 | if (x <= 0) return 0; |
|
1351 | if (x <= 0) return 0; | |
1177 |
var lineObj = |
|
1352 | var lineObj = getLine(line), text = lineObj.text; | |
1178 | function getX(len) { |
|
1353 | function getX(len) { | |
1179 | measure.innerHTML = "<pre><span>" + lineObj.getHTML(null, null, false, len) + "</span></pre>"; |
|
1354 | measure.innerHTML = "<pre><span>" + lineObj.getHTML(null, null, false, tabText, len) + "</span></pre>"; | |
1180 | return measure.firstChild.firstChild.offsetWidth; |
|
1355 | return measure.firstChild.firstChild.offsetWidth; | |
1181 | } |
|
1356 | } | |
1182 | var from = 0, fromX = 0, to = text.length, toX; |
|
1357 | var from = 0, fromX = 0, to = text.length, toX; | |
1183 | // Guess a suitable upper bound for our search. |
|
1358 | // Guess a suitable upper bound for our search. | |
1184 |
var estimated = Math.min(to, Math.ceil(x / |
|
1359 | var estimated = Math.min(to, Math.ceil(x / charWidth())); | |
1185 | for (;;) { |
|
1360 | for (;;) { | |
1186 | var estX = getX(estimated); |
|
1361 | var estX = getX(estimated); | |
1187 | if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2)); |
|
1362 | if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2)); | |
@@ -1200,20 +1375,100 b' var CodeMirror = (function() {' | |||||
1200 | } |
|
1375 | } | |
1201 | } |
|
1376 | } | |
1202 |
|
1377 | |||
|
1378 | var tempId = Math.floor(Math.random() * 0xffffff).toString(16); | |||
|
1379 | function measureLine(line, ch) { | |||
|
1380 | var extra = ""; | |||
|
1381 | // Include extra text at the end to make sure the measured line is wrapped in the right way. | |||
|
1382 | if (options.lineWrapping) { | |||
|
1383 | var end = line.text.indexOf(" ", ch + 2); | |||
|
1384 | extra = htmlEscape(line.text.slice(ch + 1, end < 0 ? line.text.length : end + (ie ? 5 : 0))); | |||
|
1385 | } | |||
|
1386 | measure.innerHTML = "<pre>" + line.getHTML(null, null, false, tabText, ch) + | |||
|
1387 | '<span id="CodeMirror-temp-' + tempId + '">' + htmlEscape(line.text.charAt(ch) || " ") + "</span>" + | |||
|
1388 | extra + "</pre>"; | |||
|
1389 | var elt = document.getElementById("CodeMirror-temp-" + tempId); | |||
|
1390 | var top = elt.offsetTop, left = elt.offsetLeft; | |||
|
1391 | // Older IEs report zero offsets for spans directly after a wrap | |||
|
1392 | if (ie && ch && top == 0 && left == 0) { | |||
|
1393 | var backup = document.createElement("span"); | |||
|
1394 | backup.innerHTML = "x"; | |||
|
1395 | elt.parentNode.insertBefore(backup, elt.nextSibling); | |||
|
1396 | top = backup.offsetTop; | |||
|
1397 | } | |||
|
1398 | return {top: top, left: left}; | |||
|
1399 | } | |||
1203 | function localCoords(pos, inLineWrap) { |
|
1400 | function localCoords(pos, inLineWrap) { | |
1204 |
var lh = |
|
1401 | var x, lh = textHeight(), y = lh * (heightAtLine(doc, pos.line) - (inLineWrap ? displayOffset : 0)); | |
1205 | return {x: charX(pos.line, pos.ch), y: line * lh, yBot: (line + 1) * lh}; |
|
1402 | if (pos.ch == 0) x = 0; | |
|
1403 | else { | |||
|
1404 | var sp = measureLine(getLine(pos.line), pos.ch); | |||
|
1405 | x = sp.left; | |||
|
1406 | if (options.lineWrapping) y += Math.max(0, sp.top); | |||
|
1407 | } | |||
|
1408 | return {x: x, y: y, yBot: y + lh}; | |||
|
1409 | } | |||
|
1410 | // Coords must be lineSpace-local | |||
|
1411 | function coordsChar(x, y) { | |||
|
1412 | if (y < 0) y = 0; | |||
|
1413 | var th = textHeight(), cw = charWidth(), heightPos = displayOffset + Math.floor(y / th); | |||
|
1414 | var lineNo = lineAtHeight(doc, heightPos); | |||
|
1415 | if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc.size - 1).text.length}; | |||
|
1416 | var lineObj = getLine(lineNo), text = lineObj.text; | |||
|
1417 | var tw = options.lineWrapping, innerOff = tw ? heightPos - heightAtLine(doc, lineNo) : 0; | |||
|
1418 | if (x <= 0 && innerOff == 0) return {line: lineNo, ch: 0}; | |||
|
1419 | function getX(len) { | |||
|
1420 | var sp = measureLine(lineObj, len); | |||
|
1421 | if (tw) { | |||
|
1422 | var off = Math.round(sp.top / th); | |||
|
1423 | return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth); | |||
|
1424 | } | |||
|
1425 | return sp.left; | |||
|
1426 | } | |||
|
1427 | var from = 0, fromX = 0, to = text.length, toX; | |||
|
1428 | // Guess a suitable upper bound for our search. | |||
|
1429 | var estimated = Math.min(to, Math.ceil((x + innerOff * scroller.clientWidth * .9) / cw)); | |||
|
1430 | for (;;) { | |||
|
1431 | var estX = getX(estimated); | |||
|
1432 | if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2)); | |||
|
1433 | else {toX = estX; to = estimated; break;} | |||
|
1434 | } | |||
|
1435 | if (x > toX) return {line: lineNo, ch: to}; | |||
|
1436 | // Try to guess a suitable lower bound as well. | |||
|
1437 | estimated = Math.floor(to * 0.8); estX = getX(estimated); | |||
|
1438 | if (estX < x) {from = estimated; fromX = estX;} | |||
|
1439 | // Do a binary search between these bounds. | |||
|
1440 | for (;;) { | |||
|
1441 | if (to - from <= 1) return {line: lineNo, ch: (toX - x > x - fromX) ? from : to}; | |||
|
1442 | var middle = Math.ceil((from + to) / 2), middleX = getX(middle); | |||
|
1443 | if (middleX > x) {to = middle; toX = middleX;} | |||
|
1444 | else {from = middle; fromX = middleX;} | |||
|
1445 | } | |||
1206 | } |
|
1446 | } | |
1207 | function pageCoords(pos) { |
|
1447 | function pageCoords(pos) { | |
1208 | var local = localCoords(pos, true), off = eltOffset(lineSpace); |
|
1448 | var local = localCoords(pos, true), off = eltOffset(lineSpace); | |
1209 | return {x: off.left + local.x, y: off.top + local.y, yBot: off.top + local.yBot}; |
|
1449 | return {x: off.left + local.x, y: off.top + local.y, yBot: off.top + local.yBot}; | |
1210 | } |
|
1450 | } | |
1211 |
|
1451 | |||
1212 | function lineHeight() { |
|
1452 | var cachedHeight, cachedHeightFor, measureText; | |
1213 | var nlines = lineDiv.childNodes.length; |
|
1453 | function textHeight() { | |
1214 | if (nlines) return (lineDiv.offsetHeight / nlines) || 1; |
|
1454 | if (measureText == null) { | |
1215 |
measure |
|
1455 | measureText = "<pre>"; | |
1216 | return measure.firstChild.offsetHeight || 1; |
|
1456 | for (var i = 0; i < 49; ++i) measureText += "x<br/>"; | |
|
1457 | measureText += "x</pre>"; | |||
|
1458 | } | |||
|
1459 | var offsetHeight = lineDiv.clientHeight; | |||
|
1460 | if (offsetHeight == cachedHeightFor) return cachedHeight; | |||
|
1461 | cachedHeightFor = offsetHeight; | |||
|
1462 | measure.innerHTML = measureText; | |||
|
1463 | cachedHeight = measure.firstChild.offsetHeight / 50 || 1; | |||
|
1464 | measure.innerHTML = ""; | |||
|
1465 | return cachedHeight; | |||
|
1466 | } | |||
|
1467 | var cachedWidth, cachedWidthFor = 0; | |||
|
1468 | function charWidth() { | |||
|
1469 | if (scroller.clientWidth == cachedWidthFor) return cachedWidth; | |||
|
1470 | cachedWidthFor = scroller.clientWidth; | |||
|
1471 | return (cachedWidth = stringWidth("x")); | |||
1217 | } |
|
1472 | } | |
1218 | function paddingTop() {return lineSpace.offsetTop;} |
|
1473 | function paddingTop() {return lineSpace.offsetTop;} | |
1219 | function paddingLeft() {return lineSpace.offsetLeft;} |
|
1474 | function paddingLeft() {return lineSpace.offsetLeft;} | |
@@ -1228,8 +1483,7 b' var CodeMirror = (function() {' | |||||
1228 | if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight)) |
|
1483 | if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight)) | |
1229 | return null; |
|
1484 | return null; | |
1230 | var offL = eltOffset(lineSpace, true); |
|
1485 | var offL = eltOffset(lineSpace, true); | |
1231 | var line = showingFrom + Math.floor((y - offL.top) / lineHeight()); |
|
1486 | return coordsChar(x - offL.left, y - offL.top); | |
1232 | return clipPos({line: line, ch: charFromX(clipLine(line), x - offL.left)}); |
|
|||
1233 | } |
|
1487 | } | |
1234 | function onContextMenu(e) { |
|
1488 | function onContextMenu(e) { | |
1235 | var pos = posFromMouse(e); |
|
1489 | var pos = posFromMouse(e); | |
@@ -1245,14 +1499,14 b' var CodeMirror = (function() {' | |||||
1245 | leaveInputAlone = true; |
|
1499 | leaveInputAlone = true; | |
1246 | var val = input.value = getSelection(); |
|
1500 | var val = input.value = getSelection(); | |
1247 | focusInput(); |
|
1501 | focusInput(); | |
1248 | setSelRange(input, 0, input.value.length); |
|
1502 | input.select(); | |
1249 | function rehide() { |
|
1503 | function rehide() { | |
1250 | var newVal = splitLines(input.value).join("\n"); |
|
1504 | var newVal = splitLines(input.value).join("\n"); | |
1251 | if (newVal != val) operation(replaceSelection)(newVal, "end"); |
|
1505 | if (newVal != val) operation(replaceSelection)(newVal, "end"); | |
1252 | inputDiv.style.position = "relative"; |
|
1506 | inputDiv.style.position = "relative"; | |
1253 | input.style.cssText = oldCSS; |
|
1507 | input.style.cssText = oldCSS; | |
1254 | leaveInputAlone = false; |
|
1508 | leaveInputAlone = false; | |
1255 |
|
|
1509 | resetInput(true); | |
1256 | slowPoll(); |
|
1510 | slowPoll(); | |
1257 | } |
|
1511 | } | |
1258 |
|
1512 | |||
@@ -1280,7 +1534,7 b' var CodeMirror = (function() {' | |||||
1280 |
|
1534 | |||
1281 | var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"}; |
|
1535 | var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"}; | |
1282 | function matchBrackets(autoclear) { |
|
1536 | function matchBrackets(autoclear) { | |
1283 |
var head = sel.inverted ? sel.from : sel.to, line = |
|
1537 | var head = sel.inverted ? sel.from : sel.to, line = getLine(head.line), pos = head.ch - 1; | |
1284 | var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)]; |
|
1538 | var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)]; | |
1285 | if (!match) return; |
|
1539 | if (!match) return; | |
1286 | var ch = match.charAt(0), forward = match.charAt(1) == ">", d = forward ? 1 : -1, st = line.styles; |
|
1540 | var ch = match.charAt(0), forward = match.charAt(1) == ">", d = forward ? 1 : -1, st = line.styles; | |
@@ -1304,18 +1558,16 b' var CodeMirror = (function() {' | |||||
1304 | } |
|
1558 | } | |
1305 | } |
|
1559 | } | |
1306 | } |
|
1560 | } | |
1307 |
for (var i = head.line, e = forward ? Math.min(i + 100, |
|
1561 | for (var i = head.line, e = forward ? Math.min(i + 100, doc.size) : Math.max(-1, i - 100); i != e; i+=d) { | |
1308 |
var line = |
|
1562 | var line = getLine(i), first = i == head.line; | |
1309 | var found = scan(line, first && forward ? pos + 1 : 0, first && !forward ? pos : line.text.length); |
|
1563 | var found = scan(line, first && forward ? pos + 1 : 0, first && !forward ? pos : line.text.length); | |
1310 | if (found) break; |
|
1564 | if (found) break; | |
1311 | } |
|
1565 | } | |
1312 | if (!found) found = {pos: null, match: false}; |
|
1566 | if (!found) found = {pos: null, match: false}; | |
1313 | var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket"; |
|
1567 | var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket"; | |
1314 | var one = markText({line: head.line, ch: pos}, {line: head.line, ch: pos+1}, style), |
|
1568 | var one = markText({line: head.line, ch: pos}, {line: head.line, ch: pos+1}, style), | |
1315 | two = found.pos != null |
|
1569 | two = found.pos != null && markText({line: i, ch: found.pos}, {line: i, ch: found.pos + 1}, style); | |
1316 | ? markText({line: i, ch: found.pos}, {line: i, ch: found.pos + 1}, style) |
|
1570 | var clear = operation(function(){one.clear(); two && two.clear();}); | |
1317 | : function() {}; |
|
|||
1318 | var clear = operation(function(){one(); two();}); |
|
|||
1319 | if (autoclear) setTimeout(clear, 800); |
|
1571 | if (autoclear) setTimeout(clear, 800); | |
1320 | else bracketHighlighted = clear; |
|
1572 | else bracketHighlighted = clear; | |
1321 | } |
|
1573 | } | |
@@ -1329,9 +1581,9 b' var CodeMirror = (function() {' | |||||
1329 | var minindent, minline; |
|
1581 | var minindent, minline; | |
1330 | for (var search = n, lim = n - 40; search > lim; --search) { |
|
1582 | for (var search = n, lim = n - 40; search > lim; --search) { | |
1331 | if (search == 0) return 0; |
|
1583 | if (search == 0) return 0; | |
1332 |
var line = |
|
1584 | var line = getLine(search-1); | |
1333 | if (line.stateAfter) return search; |
|
1585 | if (line.stateAfter) return search; | |
1334 | var indented = line.indentation(); |
|
1586 | var indented = line.indentation(options.tabSize); | |
1335 | if (minline == null || minindent > indented) { |
|
1587 | if (minline == null || minindent > indented) { | |
1336 | minline = search - 1; |
|
1588 | minline = search - 1; | |
1337 | minindent = indented; |
|
1589 | minindent = indented; | |
@@ -1340,55 +1592,58 b' var CodeMirror = (function() {' | |||||
1340 | return minline; |
|
1592 | return minline; | |
1341 | } |
|
1593 | } | |
1342 | function getStateBefore(n) { |
|
1594 | function getStateBefore(n) { | |
1343 |
var start = findStartLine(n), state = start && |
|
1595 | var start = findStartLine(n), state = start && getLine(start-1).stateAfter; | |
1344 | if (!state) state = startState(mode); |
|
1596 | if (!state) state = startState(mode); | |
1345 | else state = copyState(mode, state); |
|
1597 | else state = copyState(mode, state); | |
1346 | for (var i = start; i < n; ++i) { |
|
1598 | doc.iter(start, n, function(line) { | |
1347 | var line = lines[i]; |
|
1599 | line.highlight(mode, state, options.tabSize); | |
1348 | line.highlight(mode, state); |
|
|||
1349 | line.stateAfter = copyState(mode, state); |
|
1600 | line.stateAfter = copyState(mode, state); | |
1350 | } |
|
1601 | }); | |
1351 | if (n < lines.length && !lines[n].stateAfter) work.push(n); |
|
1602 | if (start < n) changes.push({from: start, to: n}); | |
|
1603 | if (n < doc.size && !getLine(n).stateAfter) work.push(n); | |||
1352 | return state; |
|
1604 | return state; | |
1353 | } |
|
1605 | } | |
1354 | function highlightLines(start, end) { |
|
1606 | function highlightLines(start, end) { | |
1355 | var state = getStateBefore(start); |
|
1607 | var state = getStateBefore(start); | |
1356 | for (var i = start; i < end; ++i) { |
|
1608 | doc.iter(start, end, function(line) { | |
1357 | var line = lines[i]; |
|
1609 | line.highlight(mode, state, options.tabSize); | |
1358 | line.highlight(mode, state); |
|
|||
1359 | line.stateAfter = copyState(mode, state); |
|
1610 | line.stateAfter = copyState(mode, state); | |
1360 | } |
|
1611 | }); | |
1361 | } |
|
1612 | } | |
1362 | function highlightWorker() { |
|
1613 | function highlightWorker() { | |
1363 | var end = +new Date + options.workTime; |
|
1614 | var end = +new Date + options.workTime; | |
1364 | var foundWork = work.length; |
|
1615 | var foundWork = work.length; | |
1365 | while (work.length) { |
|
1616 | while (work.length) { | |
1366 |
if (! |
|
1617 | if (!getLine(showingFrom).stateAfter) var task = showingFrom; | |
1367 | else var task = work.pop(); |
|
1618 | else var task = work.pop(); | |
1368 |
if (task >= |
|
1619 | if (task >= doc.size) continue; | |
1369 |
var start = findStartLine(task), state = start && |
|
1620 | var start = findStartLine(task), state = start && getLine(start-1).stateAfter; | |
1370 | if (state) state = copyState(mode, state); |
|
1621 | if (state) state = copyState(mode, state); | |
1371 | else state = startState(mode); |
|
1622 | else state = startState(mode); | |
1372 |
|
1623 | |||
1373 |
var unchanged = 0, compare = mode.compareStates, realChange = false |
|
1624 | var unchanged = 0, compare = mode.compareStates, realChange = false, | |
1374 | for (var i = start, l = lines.length; i < l; ++i) { |
|
1625 | i = start, bail = false; | |
1375 | var line = lines[i], hadState = line.stateAfter; |
|
1626 | doc.iter(i, doc.size, function(line) { | |
|
1627 | var hadState = line.stateAfter; | |||
1376 | if (+new Date > end) { |
|
1628 | if (+new Date > end) { | |
1377 | work.push(i); |
|
1629 | work.push(i); | |
1378 | startWorker(options.workDelay); |
|
1630 | startWorker(options.workDelay); | |
1379 | if (realChange) changes.push({from: task, to: i + 1}); |
|
1631 | if (realChange) changes.push({from: task, to: i + 1}); | |
1380 | return; |
|
1632 | return (bail = true); | |
1381 | } |
|
1633 | } | |
1382 | var changed = line.highlight(mode, state); |
|
1634 | var changed = line.highlight(mode, state, options.tabSize); | |
1383 | if (changed) realChange = true; |
|
1635 | if (changed) realChange = true; | |
1384 | line.stateAfter = copyState(mode, state); |
|
1636 | line.stateAfter = copyState(mode, state); | |
1385 | if (compare) { |
|
1637 | if (compare) { | |
1386 |
if (hadState && compare(hadState, state)) |
|
1638 | if (hadState && compare(hadState, state)) return true; | |
1387 | } else { |
|
1639 | } else { | |
1388 | if (changed !== false || !hadState) unchanged = 0; |
|
1640 | if (changed !== false || !hadState) unchanged = 0; | |
1389 | else if (++unchanged > 3) break; |
|
1641 | else if (++unchanged > 3 && (!mode.indent || mode.indent(hadState, "") == mode.indent(state, ""))) | |
|
1642 | return true; | |||
1390 | } |
|
1643 | } | |
1391 |
|
|
1644 | ++i; | |
|
1645 | }); | |||
|
1646 | if (bail) return; | |||
1392 | if (realChange) changes.push({from: task, to: i + 1}); |
|
1647 | if (realChange) changes.push({from: task, to: i + 1}); | |
1393 | } |
|
1648 | } | |
1394 | if (foundWork && options.onHighlightComplete) |
|
1649 | if (foundWork && options.onHighlightComplete) | |
@@ -1404,12 +1659,13 b' var CodeMirror = (function() {' | |||||
1404 | // be awkward, slow, and error-prone), but instead updates are |
|
1659 | // be awkward, slow, and error-prone), but instead updates are | |
1405 | // batched and then all combined and executed at once. |
|
1660 | // batched and then all combined and executed at once. | |
1406 | function startOperation() { |
|
1661 | function startOperation() { | |
1407 |
updateInput = |
|
1662 | updateInput = userSelChange = textChanged = null; | |
|
1663 | changes = []; selectionChanged = false; callbacks = []; | |||
1408 | } |
|
1664 | } | |
1409 | function endOperation() { |
|
1665 | function endOperation() { | |
1410 | var reScroll = false; |
|
1666 | var reScroll = false, updated; | |
1411 | if (selectionChanged) reScroll = !scrollCursorIntoView(); |
|
1667 | if (selectionChanged) reScroll = !scrollCursorIntoView(); | |
1412 | if (changes.length) updateDisplay(changes); |
|
1668 | if (changes.length) updated = updateDisplay(changes, true); | |
1413 | else { |
|
1669 | else { | |
1414 | if (selectionChanged) updateCursor(); |
|
1670 | if (selectionChanged) updateCursor(); | |
1415 | if (gutterDirty) updateGutter(); |
|
1671 | if (gutterDirty) updateGutter(); | |
@@ -1417,22 +1673,22 b' var CodeMirror = (function() {' | |||||
1417 | if (reScroll) scrollCursorIntoView(); |
|
1673 | if (reScroll) scrollCursorIntoView(); | |
1418 | if (selectionChanged) {scrollEditorIntoView(); restartBlink();} |
|
1674 | if (selectionChanged) {scrollEditorIntoView(); restartBlink();} | |
1419 |
|
1675 | |||
1420 | // updateInput can be set to a boolean value to force/prevent an |
|
|||
1421 | // update. |
|
|||
1422 | if (focused && !leaveInputAlone && |
|
1676 | if (focused && !leaveInputAlone && | |
1423 | (updateInput === true || (updateInput !== false && selectionChanged))) |
|
1677 | (updateInput === true || (updateInput !== false && selectionChanged))) | |
1424 |
|
|
1678 | resetInput(userSelChange); | |
1425 |
|
1679 | |||
1426 | if (selectionChanged && options.matchBrackets) |
|
1680 | if (selectionChanged && options.matchBrackets) | |
1427 | setTimeout(operation(function() { |
|
1681 | setTimeout(operation(function() { | |
1428 | if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;} |
|
1682 | if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;} | |
1429 | matchBrackets(false); |
|
1683 | if (posEq(sel.from, sel.to)) matchBrackets(false); | |
1430 | }), 20); |
|
1684 | }), 20); | |
1431 |
var tc = textChanged; // t |
|
1685 | var tc = textChanged, cbs = callbacks; // these can be reset by callbacks | |
1432 | if (selectionChanged && options.onCursorActivity) |
|
1686 | if (selectionChanged && options.onCursorActivity) | |
1433 | options.onCursorActivity(instance); |
|
1687 | options.onCursorActivity(instance); | |
1434 | if (tc && options.onChange && instance) |
|
1688 | if (tc && options.onChange && instance) | |
1435 | options.onChange(instance, tc); |
|
1689 | options.onChange(instance, tc); | |
|
1690 | for (var i = 0; i < cbs.length; ++i) cbs[i](instance); | |||
|
1691 | if (updated && options.onUpdate) options.onUpdate(instance); | |||
1436 | } |
|
1692 | } | |
1437 | var nestedOperation = 0; |
|
1693 | var nestedOperation = 0; | |
1438 | function operation(f) { |
|
1694 | function operation(f) { | |
@@ -1444,120 +1700,6 b' var CodeMirror = (function() {' | |||||
1444 | }; |
|
1700 | }; | |
1445 | } |
|
1701 | } | |
1446 |
|
1702 | |||
1447 | function SearchCursor(query, pos, caseFold) { |
|
|||
1448 | this.atOccurrence = false; |
|
|||
1449 | if (caseFold == null) caseFold = typeof query == "string" && query == query.toLowerCase(); |
|
|||
1450 |
|
||||
1451 | if (pos && typeof pos == "object") pos = clipPos(pos); |
|
|||
1452 | else pos = {line: 0, ch: 0}; |
|
|||
1453 | this.pos = {from: pos, to: pos}; |
|
|||
1454 |
|
||||
1455 | // The matches method is filled in based on the type of query. |
|
|||
1456 | // It takes a position and a direction, and returns an object |
|
|||
1457 | // describing the next occurrence of the query, or null if no |
|
|||
1458 | // more matches were found. |
|
|||
1459 | if (typeof query != "string") // Regexp match |
|
|||
1460 | this.matches = function(reverse, pos) { |
|
|||
1461 | if (reverse) { |
|
|||
1462 | var line = lines[pos.line].text.slice(0, pos.ch), match = line.match(query), start = 0; |
|
|||
1463 | while (match) { |
|
|||
1464 | var ind = line.indexOf(match[0]); |
|
|||
1465 | start += ind; |
|
|||
1466 | line = line.slice(ind + 1); |
|
|||
1467 | var newmatch = line.match(query); |
|
|||
1468 | if (newmatch) match = newmatch; |
|
|||
1469 | else break; |
|
|||
1470 | start++; |
|
|||
1471 | } |
|
|||
1472 | } |
|
|||
1473 | else { |
|
|||
1474 | var line = lines[pos.line].text.slice(pos.ch), match = line.match(query), |
|
|||
1475 | start = match && pos.ch + line.indexOf(match[0]); |
|
|||
1476 | } |
|
|||
1477 | if (match) |
|
|||
1478 | return {from: {line: pos.line, ch: start}, |
|
|||
1479 | to: {line: pos.line, ch: start + match[0].length}, |
|
|||
1480 | match: match}; |
|
|||
1481 | }; |
|
|||
1482 | else { // String query |
|
|||
1483 | if (caseFold) query = query.toLowerCase(); |
|
|||
1484 | var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;}; |
|
|||
1485 | var target = query.split("\n"); |
|
|||
1486 | // Different methods for single-line and multi-line queries |
|
|||
1487 | if (target.length == 1) |
|
|||
1488 | this.matches = function(reverse, pos) { |
|
|||
1489 | var line = fold(lines[pos.line].text), len = query.length, match; |
|
|||
1490 | if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1) |
|
|||
1491 | : (match = line.indexOf(query, pos.ch)) != -1) |
|
|||
1492 | return {from: {line: pos.line, ch: match}, |
|
|||
1493 | to: {line: pos.line, ch: match + len}}; |
|
|||
1494 | }; |
|
|||
1495 | else |
|
|||
1496 | this.matches = function(reverse, pos) { |
|
|||
1497 | var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(lines[ln].text); |
|
|||
1498 | var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match)); |
|
|||
1499 | if (reverse ? offsetA >= pos.ch || offsetA != match.length |
|
|||
1500 | : offsetA <= pos.ch || offsetA != line.length - match.length) |
|
|||
1501 | return; |
|
|||
1502 | for (;;) { |
|
|||
1503 | if (reverse ? !ln : ln == lines.length - 1) return; |
|
|||
1504 | line = fold(lines[ln += reverse ? -1 : 1].text); |
|
|||
1505 | match = target[reverse ? --idx : ++idx]; |
|
|||
1506 | if (idx > 0 && idx < target.length - 1) { |
|
|||
1507 | if (line != match) return; |
|
|||
1508 | else continue; |
|
|||
1509 | } |
|
|||
1510 | var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length); |
|
|||
1511 | if (reverse ? offsetB != line.length - match.length : offsetB != match.length) |
|
|||
1512 | return; |
|
|||
1513 | var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB}; |
|
|||
1514 | return {from: reverse ? end : start, to: reverse ? start : end}; |
|
|||
1515 | } |
|
|||
1516 | }; |
|
|||
1517 | } |
|
|||
1518 | } |
|
|||
1519 |
|
||||
1520 | SearchCursor.prototype = { |
|
|||
1521 | findNext: function() {return this.find(false);}, |
|
|||
1522 | findPrevious: function() {return this.find(true);}, |
|
|||
1523 |
|
||||
1524 | find: function(reverse) { |
|
|||
1525 | var self = this, pos = clipPos(reverse ? this.pos.from : this.pos.to); |
|
|||
1526 | function savePosAndFail(line) { |
|
|||
1527 | var pos = {line: line, ch: 0}; |
|
|||
1528 | self.pos = {from: pos, to: pos}; |
|
|||
1529 | self.atOccurrence = false; |
|
|||
1530 | return false; |
|
|||
1531 | } |
|
|||
1532 |
|
||||
1533 | for (;;) { |
|
|||
1534 | if (this.pos = this.matches(reverse, pos)) { |
|
|||
1535 | this.atOccurrence = true; |
|
|||
1536 | return this.pos.match || true; |
|
|||
1537 | } |
|
|||
1538 | if (reverse) { |
|
|||
1539 | if (!pos.line) return savePosAndFail(0); |
|
|||
1540 | pos = {line: pos.line-1, ch: lines[pos.line-1].text.length}; |
|
|||
1541 | } |
|
|||
1542 | else { |
|
|||
1543 | if (pos.line == lines.length - 1) return savePosAndFail(lines.length); |
|
|||
1544 | pos = {line: pos.line+1, ch: 0}; |
|
|||
1545 | } |
|
|||
1546 | } |
|
|||
1547 | }, |
|
|||
1548 |
|
||||
1549 | from: function() {if (this.atOccurrence) return copyPos(this.pos.from);}, |
|
|||
1550 | to: function() {if (this.atOccurrence) return copyPos(this.pos.to);}, |
|
|||
1551 |
|
||||
1552 | replace: function(newText) { |
|
|||
1553 | var self = this; |
|
|||
1554 | if (this.atOccurrence) |
|
|||
1555 | operation(function() { |
|
|||
1556 | self.pos.to = replaceRange(newText, self.pos.from, self.pos.to); |
|
|||
1557 | })(); |
|
|||
1558 | } |
|
|||
1559 | }; |
|
|||
1560 |
|
||||
1561 | for (var ext in extensions) |
|
1703 | for (var ext in extensions) | |
1562 | if (extensions.propertyIsEnumerable(ext) && |
|
1704 | if (extensions.propertyIsEnumerable(ext) && | |
1563 | !instance.propertyIsEnumerable(ext)) |
|
1705 | !instance.propertyIsEnumerable(ext)) | |
@@ -1572,29 +1714,35 b' var CodeMirror = (function() {' | |||||
1572 | theme: "default", |
|
1714 | theme: "default", | |
1573 | indentUnit: 2, |
|
1715 | indentUnit: 2, | |
1574 | indentWithTabs: false, |
|
1716 | indentWithTabs: false, | |
1575 | tabMode: "classic", |
|
1717 | tabSize: 4, | |
1576 |
|
|
1718 | keyMap: "default", | |
|
1719 | extraKeys: null, | |||
1577 | electricChars: true, |
|
1720 | electricChars: true, | |
1578 | onKeyEvent: null, |
|
1721 | onKeyEvent: null, | |
|
1722 | lineWrapping: false, | |||
1579 | lineNumbers: false, |
|
1723 | lineNumbers: false, | |
1580 | gutter: false, |
|
1724 | gutter: false, | |
1581 | fixedGutter: false, |
|
1725 | fixedGutter: false, | |
1582 | firstLineNumber: 1, |
|
1726 | firstLineNumber: 1, | |
1583 | readOnly: false, |
|
1727 | readOnly: false, | |
1584 | smartHome: true, |
|
|||
1585 | onChange: null, |
|
1728 | onChange: null, | |
1586 | onCursorActivity: null, |
|
1729 | onCursorActivity: null, | |
1587 | onGutterClick: null, |
|
1730 | onGutterClick: null, | |
1588 | onHighlightComplete: null, |
|
1731 | onHighlightComplete: null, | |
|
1732 | onUpdate: null, | |||
1589 | onFocus: null, onBlur: null, onScroll: null, |
|
1733 | onFocus: null, onBlur: null, onScroll: null, | |
1590 | matchBrackets: false, |
|
1734 | matchBrackets: false, | |
1591 | workTime: 100, |
|
1735 | workTime: 100, | |
1592 | workDelay: 200, |
|
1736 | workDelay: 200, | |
|
1737 | pollInterval: 100, | |||
1593 | undoDepth: 40, |
|
1738 | undoDepth: 40, | |
1594 | tabindex: null, |
|
1739 | tabindex: null, | |
1595 | document: window.document |
|
1740 | document: window.document | |
1596 | }; |
|
1741 | }; | |
1597 |
|
1742 | |||
|
1743 | var mac = /Mac/.test(navigator.platform); | |||
|
1744 | var win = /Win/.test(navigator.platform); | |||
|
1745 | ||||
1598 | // Known modes, by name and by MIME |
|
1746 | // Known modes, by name and by MIME | |
1599 | var modes = {}, mimeModes = {}; |
|
1747 | var modes = {}, mimeModes = {}; | |
1600 | CodeMirror.defineMode = function(name, mode) { |
|
1748 | CodeMirror.defineMode = function(name, mode) { | |
@@ -1631,11 +1779,114 b' var CodeMirror = (function() {' | |||||
1631 | return list; |
|
1779 | return list; | |
1632 | }; |
|
1780 | }; | |
1633 |
|
1781 | |||
1634 | var extensions = {}; |
|
1782 | var extensions = CodeMirror.extensions = {}; | |
1635 | CodeMirror.defineExtension = function(name, func) { |
|
1783 | CodeMirror.defineExtension = function(name, func) { | |
1636 | extensions[name] = func; |
|
1784 | extensions[name] = func; | |
1637 | }; |
|
1785 | }; | |
1638 |
|
1786 | |||
|
1787 | var commands = CodeMirror.commands = { | |||
|
1788 | selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});}, | |||
|
1789 | killLine: function(cm) { | |||
|
1790 | var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to); | |||
|
1791 | if (!sel && cm.getLine(from.line).length == from.ch) cm.replaceRange("", from, {line: from.line + 1, ch: 0}); | |||
|
1792 | else cm.replaceRange("", from, sel ? to : {line: from.line}); | |||
|
1793 | }, | |||
|
1794 | deleteLine: function(cm) {var l = cm.getCursor().line; cm.replaceRange("", {line: l, ch: 0}, {line: l});}, | |||
|
1795 | undo: function(cm) {cm.undo();}, | |||
|
1796 | redo: function(cm) {cm.redo();}, | |||
|
1797 | goDocStart: function(cm) {cm.setCursor(0, 0, true);}, | |||
|
1798 | goDocEnd: function(cm) {cm.setSelection({line: cm.lineCount() - 1}, null, true);}, | |||
|
1799 | goLineStart: function(cm) {cm.setCursor(cm.getCursor().line, 0, true);}, | |||
|
1800 | goLineStartSmart: function(cm) { | |||
|
1801 | var cur = cm.getCursor(); | |||
|
1802 | var text = cm.getLine(cur.line), firstNonWS = Math.max(0, text.search(/\S/)); | |||
|
1803 | cm.setCursor(cur.line, cur.ch <= firstNonWS && cur.ch ? 0 : firstNonWS, true); | |||
|
1804 | }, | |||
|
1805 | goLineEnd: function(cm) {cm.setSelection({line: cm.getCursor().line}, null, true);}, | |||
|
1806 | goLineUp: function(cm) {cm.moveV(-1, "line");}, | |||
|
1807 | goLineDown: function(cm) {cm.moveV(1, "line");}, | |||
|
1808 | goPageUp: function(cm) {cm.moveV(-1, "page");}, | |||
|
1809 | goPageDown: function(cm) {cm.moveV(1, "page");}, | |||
|
1810 | goCharLeft: function(cm) {cm.moveH(-1, "char");}, | |||
|
1811 | goCharRight: function(cm) {cm.moveH(1, "char");}, | |||
|
1812 | goColumnLeft: function(cm) {cm.moveH(-1, "column");}, | |||
|
1813 | goColumnRight: function(cm) {cm.moveH(1, "column");}, | |||
|
1814 | goWordLeft: function(cm) {cm.moveH(-1, "word");}, | |||
|
1815 | goWordRight: function(cm) {cm.moveH(1, "word");}, | |||
|
1816 | delCharLeft: function(cm) {cm.deleteH(-1, "char");}, | |||
|
1817 | delCharRight: function(cm) {cm.deleteH(1, "char");}, | |||
|
1818 | delWordLeft: function(cm) {cm.deleteH(-1, "word");}, | |||
|
1819 | delWordRight: function(cm) {cm.deleteH(1, "word");}, | |||
|
1820 | indentAuto: function(cm) {cm.indentSelection("smart");}, | |||
|
1821 | indentMore: function(cm) {cm.indentSelection("add");}, | |||
|
1822 | indentLess: function(cm) {cm.indentSelection("subtract");}, | |||
|
1823 | insertTab: function(cm) {cm.replaceSelection("\t", "end");}, | |||
|
1824 | transposeChars: function(cm) { | |||
|
1825 | var cur = cm.getCursor(), line = cm.getLine(cur.line); | |||
|
1826 | if (cur.ch > 0 && cur.ch < line.length - 1) | |||
|
1827 | cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1), | |||
|
1828 | {line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1}); | |||
|
1829 | }, | |||
|
1830 | newlineAndIndent: function(cm) { | |||
|
1831 | cm.replaceSelection("\n", "end"); | |||
|
1832 | cm.indentLine(cm.getCursor().line); | |||
|
1833 | }, | |||
|
1834 | toggleOverwrite: function(cm) {cm.toggleOverwrite();} | |||
|
1835 | }; | |||
|
1836 | ||||
|
1837 | var keyMap = CodeMirror.keyMap = {}; | |||
|
1838 | keyMap.basic = { | |||
|
1839 | "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown", | |||
|
1840 | "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown", | |||
|
1841 | "Delete": "delCharRight", "Backspace": "delCharLeft", "Tab": "indentMore", "Shift-Tab": "indentLess", | |||
|
1842 | "Enter": "newlineAndIndent", "Insert": "toggleOverwrite" | |||
|
1843 | }; | |||
|
1844 | // Note that the save and find-related commands aren't defined by | |||
|
1845 | // default. Unknown commands are simply ignored. | |||
|
1846 | keyMap.pcDefault = { | |||
|
1847 | "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo", | |||
|
1848 | "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd", | |||
|
1849 | "Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd", | |||
|
1850 | "Ctrl-Backspace": "delWordLeft", "Ctrl-Delete": "delWordRight", "Ctrl-S": "save", "Ctrl-F": "find", | |||
|
1851 | "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll", | |||
|
1852 | fallthrough: "basic" | |||
|
1853 | }; | |||
|
1854 | keyMap.macDefault = { | |||
|
1855 | "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo", | |||
|
1856 | "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft", | |||
|
1857 | "Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordLeft", | |||
|
1858 | "Ctrl-Alt-Backspace": "delWordRight", "Alt-Delete": "delWordRight", "Cmd-S": "save", "Cmd-F": "find", | |||
|
1859 | "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll", | |||
|
1860 | fallthrough: ["basic", "emacsy"] | |||
|
1861 | }; | |||
|
1862 | keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault; | |||
|
1863 | keyMap.emacsy = { | |||
|
1864 | "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown", | |||
|
1865 | "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd", | |||
|
1866 | "Ctrl-V": "goPageUp", "Shift-Ctrl-V": "goPageDown", "Ctrl-D": "delCharRight", "Ctrl-H": "delCharLeft", | |||
|
1867 | "Alt-D": "delWordRight", "Alt-Backspace": "delWordLeft", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars" | |||
|
1868 | }; | |||
|
1869 | ||||
|
1870 | function lookupKey(name, extraMap, map) { | |||
|
1871 | function lookup(name, map, ft) { | |||
|
1872 | var found = map[name]; | |||
|
1873 | if (found != null) return found; | |||
|
1874 | if (ft == null) ft = map.fallthrough; | |||
|
1875 | if (ft == null) return map.catchall; | |||
|
1876 | if (typeof ft == "string") return lookup(name, keyMap[ft]); | |||
|
1877 | for (var i = 0, e = ft.length; i < e; ++i) { | |||
|
1878 | found = lookup(name, keyMap[ft[i]]); | |||
|
1879 | if (found != null) return found; | |||
|
1880 | } | |||
|
1881 | return null; | |||
|
1882 | } | |||
|
1883 | return extraMap ? lookup(name, extraMap, map) : lookup(name, keyMap[map]); | |||
|
1884 | } | |||
|
1885 | function isModifierKey(event) { | |||
|
1886 | var name = keyNames[event.keyCode]; | |||
|
1887 | return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"; | |||
|
1888 | } | |||
|
1889 | ||||
1639 | CodeMirror.fromTextArea = function(textarea, options) { |
|
1890 | CodeMirror.fromTextArea = function(textarea, options) { | |
1640 | if (!options) options = {}; |
|
1891 | if (!options) options = {}; | |
1641 | options.value = textarea.value; |
|
1892 | options.value = textarea.value; | |
@@ -1663,6 +1914,7 b' var CodeMirror = (function() {' | |||||
1663 | textarea.parentNode.insertBefore(node, textarea.nextSibling); |
|
1914 | textarea.parentNode.insertBefore(node, textarea.nextSibling); | |
1664 | }, options); |
|
1915 | }, options); | |
1665 | instance.save = save; |
|
1916 | instance.save = save; | |
|
1917 | instance.getTextArea = function() { return textarea; }; | |||
1666 | instance.toTextArea = function() { |
|
1918 | instance.toTextArea = function() { | |
1667 | save(); |
|
1919 | save(); | |
1668 | textarea.parentNode.removeChild(instance.getWrapperElement()); |
|
1920 | textarea.parentNode.removeChild(instance.getWrapperElement()); | |
@@ -1689,16 +1941,17 b' var CodeMirror = (function() {' | |||||
1689 | } |
|
1941 | } | |
1690 | return nstate; |
|
1942 | return nstate; | |
1691 | } |
|
1943 | } | |
1692 |
CodeMirror. |
|
1944 | CodeMirror.copyState = copyState; | |
1693 | function startState(mode, a1, a2) { |
|
1945 | function startState(mode, a1, a2) { | |
1694 | return mode.startState ? mode.startState(a1, a2) : true; |
|
1946 | return mode.startState ? mode.startState(a1, a2) : true; | |
1695 | } |
|
1947 | } | |
1696 |
CodeMirror. |
|
1948 | CodeMirror.startState = startState; | |
1697 |
|
1949 | |||
1698 | // The character stream used by a mode's parser. |
|
1950 | // The character stream used by a mode's parser. | |
1699 | function StringStream(string) { |
|
1951 | function StringStream(string, tabSize) { | |
1700 | this.pos = this.start = 0; |
|
1952 | this.pos = this.start = 0; | |
1701 | this.string = string; |
|
1953 | this.string = string; | |
|
1954 | this.tabSize = tabSize || 8; | |||
1702 | } |
|
1955 | } | |
1703 | StringStream.prototype = { |
|
1956 | StringStream.prototype = { | |
1704 | eol: function() {return this.pos >= this.string.length;}, |
|
1957 | eol: function() {return this.pos >= this.string.length;}, | |
@@ -1730,8 +1983,8 b' var CodeMirror = (function() {' | |||||
1730 | if (found > -1) {this.pos = found; return true;} |
|
1983 | if (found > -1) {this.pos = found; return true;} | |
1731 | }, |
|
1984 | }, | |
1732 | backUp: function(n) {this.pos -= n;}, |
|
1985 | backUp: function(n) {this.pos -= n;}, | |
1733 | column: function() {return countColumn(this.string, this.start);}, |
|
1986 | column: function() {return countColumn(this.string, this.start, this.tabSize);}, | |
1734 | indentation: function() {return countColumn(this.string);}, |
|
1987 | indentation: function() {return countColumn(this.string, null, this.tabSize);}, | |
1735 | match: function(pattern, consume, caseInsensitive) { |
|
1988 | match: function(pattern, consume, caseInsensitive) { | |
1736 | if (typeof pattern == "string") { |
|
1989 | if (typeof pattern == "string") { | |
1737 | function cased(str) {return caseInsensitive ? str.toLowerCase() : str;} |
|
1990 | function cased(str) {return caseInsensitive ? str.toLowerCase() : str;} | |
@@ -1750,18 +2003,95 b' var CodeMirror = (function() {' | |||||
1750 | }; |
|
2003 | }; | |
1751 | CodeMirror.StringStream = StringStream; |
|
2004 | CodeMirror.StringStream = StringStream; | |
1752 |
|
2005 | |||
|
2006 | function MarkedText(from, to, className, set) { | |||
|
2007 | this.from = from; this.to = to; this.style = className; this.set = set; | |||
|
2008 | } | |||
|
2009 | MarkedText.prototype = { | |||
|
2010 | attach: function(line) { this.set.push(line); }, | |||
|
2011 | detach: function(line) { | |||
|
2012 | var ix = indexOf(this.set, line); | |||
|
2013 | if (ix > -1) this.set.splice(ix, 1); | |||
|
2014 | }, | |||
|
2015 | split: function(pos, lenBefore) { | |||
|
2016 | if (this.to <= pos && this.to != null) return null; | |||
|
2017 | var from = this.from < pos || this.from == null ? null : this.from - pos + lenBefore; | |||
|
2018 | var to = this.to == null ? null : this.to - pos + lenBefore; | |||
|
2019 | return new MarkedText(from, to, this.style, this.set); | |||
|
2020 | }, | |||
|
2021 | dup: function() { return new MarkedText(null, null, this.style, this.set); }, | |||
|
2022 | clipTo: function(fromOpen, from, toOpen, to, diff) { | |||
|
2023 | if (this.from != null && this.from >= from) | |||
|
2024 | this.from = Math.max(to, this.from) + diff; | |||
|
2025 | if (this.to != null && this.to > from) | |||
|
2026 | this.to = to < this.to ? this.to + diff : from; | |||
|
2027 | if (fromOpen && to > this.from && (to < this.to || this.to == null)) | |||
|
2028 | this.from = null; | |||
|
2029 | if (toOpen && (from < this.to || this.to == null) && (from > this.from || this.from == null)) | |||
|
2030 | this.to = null; | |||
|
2031 | }, | |||
|
2032 | isDead: function() { return this.from != null && this.to != null && this.from >= this.to; }, | |||
|
2033 | sameSet: function(x) { return this.set == x.set; } | |||
|
2034 | }; | |||
|
2035 | ||||
|
2036 | function Bookmark(pos) { | |||
|
2037 | this.from = pos; this.to = pos; this.line = null; | |||
|
2038 | } | |||
|
2039 | Bookmark.prototype = { | |||
|
2040 | attach: function(line) { this.line = line; }, | |||
|
2041 | detach: function(line) { if (this.line == line) this.line = null; }, | |||
|
2042 | split: function(pos, lenBefore) { | |||
|
2043 | if (pos < this.from) { | |||
|
2044 | this.from = this.to = (this.from - pos) + lenBefore; | |||
|
2045 | return this; | |||
|
2046 | } | |||
|
2047 | }, | |||
|
2048 | isDead: function() { return this.from > this.to; }, | |||
|
2049 | clipTo: function(fromOpen, from, toOpen, to, diff) { | |||
|
2050 | if ((fromOpen || from < this.from) && (toOpen || to > this.to)) { | |||
|
2051 | this.from = 0; this.to = -1; | |||
|
2052 | } else if (this.from > from) { | |||
|
2053 | this.from = this.to = Math.max(to, this.from) + diff; | |||
|
2054 | } | |||
|
2055 | }, | |||
|
2056 | sameSet: function(x) { return false; }, | |||
|
2057 | find: function() { | |||
|
2058 | if (!this.line || !this.line.parent) return null; | |||
|
2059 | return {line: lineNo(this.line), ch: this.from}; | |||
|
2060 | }, | |||
|
2061 | clear: function() { | |||
|
2062 | if (this.line) { | |||
|
2063 | var found = indexOf(this.line.marked, this); | |||
|
2064 | if (found != -1) this.line.marked.splice(found, 1); | |||
|
2065 | this.line = null; | |||
|
2066 | } | |||
|
2067 | } | |||
|
2068 | }; | |||
|
2069 | ||||
1753 | // Line objects. These hold state related to a line, including |
|
2070 | // Line objects. These hold state related to a line, including | |
1754 | // highlighting info (the styles array). |
|
2071 | // highlighting info (the styles array). | |
1755 | function Line(text, styles) { |
|
2072 | function Line(text, styles) { | |
1756 | this.styles = styles || [text, null]; |
|
2073 | this.styles = styles || [text, null]; | |
1757 | this.stateAfter = null; |
|
|||
1758 | this.text = text; |
|
2074 | this.text = text; | |
1759 | this.marked = this.gutterMarker = this.className = null; |
|
2075 | this.height = 1; | |
|
2076 | this.marked = this.gutterMarker = this.className = this.handlers = null; | |||
|
2077 | this.stateAfter = this.parent = this.hidden = null; | |||
|
2078 | } | |||
|
2079 | Line.inheritMarks = function(text, orig) { | |||
|
2080 | var ln = new Line(text), mk = orig && orig.marked; | |||
|
2081 | if (mk) { | |||
|
2082 | for (var i = 0; i < mk.length; ++i) { | |||
|
2083 | if (mk[i].to == null && mk[i].style) { | |||
|
2084 | var newmk = ln.marked || (ln.marked = []), mark = mk[i]; | |||
|
2085 | var nmark = mark.dup(); newmk.push(nmark); nmark.attach(ln); | |||
|
2086 | } | |||
|
2087 | } | |||
|
2088 | } | |||
|
2089 | return ln; | |||
1760 | } |
|
2090 | } | |
1761 | Line.prototype = { |
|
2091 | Line.prototype = { | |
1762 | // Replace a piece of a line, keeping the styles around it intact. |
|
2092 | // Replace a piece of a line, keeping the styles around it intact. | |
1763 | replace: function(from, to, text) { |
|
2093 | replace: function(from, to_, text) { | |
1764 | var st = [], mk = this.marked; |
|
2094 | var st = [], mk = this.marked, to = to_ == null ? this.text.length : to_; | |
1765 | copyStyles(0, from, this.styles, st); |
|
2095 | copyStyles(0, from, this.styles, st); | |
1766 | if (text) st.push(text, null); |
|
2096 | if (text) st.push(text, null); | |
1767 | copyStyles(to, this.text.length, this.styles, st); |
|
2097 | copyStyles(to, this.text.length, this.styles, st); | |
@@ -1769,40 +2099,91 b' var CodeMirror = (function() {' | |||||
1769 | this.text = this.text.slice(0, from) + text + this.text.slice(to); |
|
2099 | this.text = this.text.slice(0, from) + text + this.text.slice(to); | |
1770 | this.stateAfter = null; |
|
2100 | this.stateAfter = null; | |
1771 | if (mk) { |
|
2101 | if (mk) { | |
1772 |
var diff = text.length - (to - from) |
|
2102 | var diff = text.length - (to - from); | |
1773 | function fix(n) {return n <= Math.min(to, to + diff) ? n : n + diff;} |
|
2103 | for (var i = 0, mark = mk[i]; i < mk.length; ++i) { | |
1774 | for (var i = 0; i < mk.length; ++i) { |
|
2104 | mark.clipTo(from == null, from || 0, to_ == null, to, diff); | |
1775 | var mark = mk[i], del = false; |
|
2105 | if (mark.isDead()) {mark.detach(this); mk.splice(i--, 1);} | |
1776 | if (mark.from >= end) del = true; |
|
|||
1777 | else {mark.from = fix(mark.from); if (mark.to != null) mark.to = fix(mark.to);} |
|
|||
1778 | if (del || mark.from >= mark.to) {mk.splice(i, 1); i--;} |
|
|||
1779 | } |
|
2106 | } | |
1780 | } |
|
2107 | } | |
1781 | }, |
|
2108 | }, | |
1782 |
// Split a |
|
2109 | // Split a part off a line, keeping styles and markers intact. | |
1783 | split: function(pos, textBefore) { |
|
2110 | split: function(pos, textBefore) { | |
1784 | var st = [textBefore, null]; |
|
2111 | var st = [textBefore, null], mk = this.marked; | |
1785 | copyStyles(pos, this.text.length, this.styles, st); |
|
2112 | copyStyles(pos, this.text.length, this.styles, st); | |
1786 |
re |
|
2113 | var taken = new Line(textBefore + this.text.slice(pos), st); | |
|
2114 | if (mk) { | |||
|
2115 | for (var i = 0; i < mk.length; ++i) { | |||
|
2116 | var mark = mk[i]; | |||
|
2117 | var newmark = mark.split(pos, textBefore.length); | |||
|
2118 | if (newmark) { | |||
|
2119 | if (!taken.marked) taken.marked = []; | |||
|
2120 | taken.marked.push(newmark); newmark.attach(taken); | |||
|
2121 | } | |||
|
2122 | } | |||
|
2123 | } | |||
|
2124 | return taken; | |||
1787 | }, |
|
2125 | }, | |
1788 |
a |
|
2126 | append: function(line) { | |
1789 | var mk = this.marked, mark = {from: from, to: to, style: style}; |
|
2127 | var mylen = this.text.length, mk = line.marked, mymk = this.marked; | |
1790 | if (this.marked == null) this.marked = []; |
|
2128 | this.text += line.text; | |
1791 | this.marked.push(mark); |
|
2129 | copyStyles(0, line.text.length, line.styles, this.styles); | |
1792 | this.marked.sort(function(a, b){return a.from - b.from;}); |
|
2130 | if (mymk) { | |
1793 | return mark; |
|
2131 | for (var i = 0; i < mymk.length; ++i) | |
|
2132 | if (mymk[i].to == null) mymk[i].to = mylen; | |||
|
2133 | } | |||
|
2134 | if (mk && mk.length) { | |||
|
2135 | if (!mymk) this.marked = mymk = []; | |||
|
2136 | outer: for (var i = 0; i < mk.length; ++i) { | |||
|
2137 | var mark = mk[i]; | |||
|
2138 | if (!mark.from) { | |||
|
2139 | for (var j = 0; j < mymk.length; ++j) { | |||
|
2140 | var mymark = mymk[j]; | |||
|
2141 | if (mymark.to == mylen && mymark.sameSet(mark)) { | |||
|
2142 | mymark.to = mark.to == null ? null : mark.to + mylen; | |||
|
2143 | if (mymark.isDead()) { | |||
|
2144 | mymark.detach(this); | |||
|
2145 | mk.splice(i--, 1); | |||
|
2146 | } | |||
|
2147 | continue outer; | |||
|
2148 | } | |||
|
2149 | } | |||
|
2150 | } | |||
|
2151 | mymk.push(mark); | |||
|
2152 | mark.attach(this); | |||
|
2153 | mark.from += mylen; | |||
|
2154 | if (mark.to != null) mark.to += mylen; | |||
|
2155 | } | |||
|
2156 | } | |||
|
2157 | }, | |||
|
2158 | fixMarkEnds: function(other) { | |||
|
2159 | var mk = this.marked, omk = other.marked; | |||
|
2160 | if (!mk) return; | |||
|
2161 | for (var i = 0; i < mk.length; ++i) { | |||
|
2162 | var mark = mk[i], close = mark.to == null; | |||
|
2163 | if (close && omk) { | |||
|
2164 | for (var j = 0; j < omk.length; ++j) | |||
|
2165 | if (omk[j].sameSet(mark)) {close = false; break;} | |||
|
2166 | } | |||
|
2167 | if (close) mark.to = this.text.length; | |||
|
2168 | } | |||
1794 | }, |
|
2169 | }, | |
1795 |
|
|
2170 | fixMarkStarts: function() { | |
1796 | var mk = this.marked; |
|
2171 | var mk = this.marked; | |
1797 | if (!mk) return; |
|
2172 | if (!mk) return; | |
1798 | for (var i = 0; i < mk.length; ++i) |
|
2173 | for (var i = 0; i < mk.length; ++i) | |
1799 | if (mk[i] == mark) {mk.splice(i, 1); break;} |
|
2174 | if (mk[i].from == null) mk[i].from = 0; | |
|
2175 | }, | |||
|
2176 | addMark: function(mark) { | |||
|
2177 | mark.attach(this); | |||
|
2178 | if (this.marked == null) this.marked = []; | |||
|
2179 | this.marked.push(mark); | |||
|
2180 | this.marked.sort(function(a, b){return (a.from || 0) - (b.from || 0);}); | |||
1800 | }, |
|
2181 | }, | |
1801 | // Run the given mode's parser over a line, update the styles |
|
2182 | // Run the given mode's parser over a line, update the styles | |
1802 | // array, which contains alternating fragments of text and CSS |
|
2183 | // array, which contains alternating fragments of text and CSS | |
1803 | // classes. |
|
2184 | // classes. | |
1804 | highlight: function(mode, state) { |
|
2185 | highlight: function(mode, state, tabSize) { | |
1805 | var stream = new StringStream(this.text), st = this.styles, pos = 0; |
|
2186 | var stream = new StringStream(this.text, tabSize), st = this.styles, pos = 0; | |
1806 | var changed = false, curWord = st[0], prevWord; |
|
2187 | var changed = false, curWord = st[0], prevWord; | |
1807 | if (this.text == "" && mode.blankLine) mode.blankLine(state); |
|
2188 | if (this.text == "" && mode.blankLine) mode.blankLine(state); | |
1808 | while (!stream.eol()) { |
|
2189 | while (!stream.eol()) { | |
@@ -1843,17 +2224,20 b' var CodeMirror = (function() {' | |||||
1843 | className: style || null, |
|
2224 | className: style || null, | |
1844 | state: state}; |
|
2225 | state: state}; | |
1845 | }, |
|
2226 | }, | |
1846 | indentation: function() {return countColumn(this.text);}, |
|
2227 | indentation: function(tabSize) {return countColumn(this.text, null, tabSize);}, | |
1847 | // Produces an HTML fragment for the line, taking selection, |
|
2228 | // Produces an HTML fragment for the line, taking selection, | |
1848 | // marking, and highlighting into account. |
|
2229 | // marking, and highlighting into account. | |
1849 | getHTML: function(sfrom, sto, includePre, endAt) { |
|
2230 | getHTML: function(sfrom, sto, includePre, tabText, endAt) { | |
1850 | var html = []; |
|
2231 | var html = [], first = true; | |
1851 | if (includePre) |
|
2232 | if (includePre) | |
1852 | html.push(this.className ? '<pre class="' + this.className + '">': "<pre>"); |
|
2233 | html.push(this.className ? '<pre class="' + this.className + '">': "<pre>"); | |
1853 | function span(text, style) { |
|
2234 | function span(text, style) { | |
1854 | if (!text) return; |
|
2235 | if (!text) return; | |
1855 | if (style) html.push('<span class="', style, '">', htmlEscape(text), "</span>"); |
|
2236 | // Work around a bug where, in some compat modes, IE ignores leading spaces | |
1856 | else html.push(htmlEscape(text)); |
|
2237 | if (first && ie && text.charAt(0) == " ") text = "\u00a0" + text.slice(1); | |
|
2238 | first = false; | |||
|
2239 | if (style) html.push('<span class="', style, '">', htmlEscape(text).replace(/\t/g, tabText), "</span>"); | |||
|
2240 | else html.push(htmlEscape(text).replace(/\t/g, tabText)); | |||
1857 | } |
|
2241 | } | |
1858 | var st = this.styles, allText = this.text, marked = this.marked; |
|
2242 | var st = this.styles, allText = this.text, marked = this.marked; | |
1859 | if (sfrom == sto) sfrom = null; |
|
2243 | if (sfrom == sto) sfrom = null; | |
@@ -1864,10 +2248,10 b' var CodeMirror = (function() {' | |||||
1864 | span(" ", sfrom != null && sto == null ? "CodeMirror-selected" : null); |
|
2248 | span(" ", sfrom != null && sto == null ? "CodeMirror-selected" : null); | |
1865 | else if (!marked && sfrom == null) |
|
2249 | else if (!marked && sfrom == null) | |
1866 | for (var i = 0, ch = 0; ch < len; i+=2) { |
|
2250 | for (var i = 0, ch = 0; ch < len; i+=2) { | |
1867 | var str = st[i], l = str.length; |
|
2251 | var str = st[i], style = st[i+1], l = str.length; | |
1868 | if (ch + l > len) str = str.slice(0, len - ch); |
|
2252 | if (ch + l > len) str = str.slice(0, len - ch); | |
1869 | ch += l; |
|
2253 | ch += l; | |
1870 |
span(str, "cm-" + st |
|
2254 | span(str, style && "cm-" + style); | |
1871 | } |
|
2255 | } | |
1872 | else { |
|
2256 | else { | |
1873 | var pos = 0, i = 0, text = "", style, sg = 0; |
|
2257 | var pos = 0, i = 0, text = "", style, sg = 0; | |
@@ -1911,6 +2295,11 b' var CodeMirror = (function() {' | |||||
1911 | } |
|
2295 | } | |
1912 | if (includePre) html.push("</pre>"); |
|
2296 | if (includePre) html.push("</pre>"); | |
1913 | return html.join(""); |
|
2297 | return html.join(""); | |
|
2298 | }, | |||
|
2299 | cleanUp: function() { | |||
|
2300 | this.parent = null; | |||
|
2301 | if (this.marked) | |||
|
2302 | for (var i = 0, e = this.marked.length; i < e; ++i) this.marked[i].detach(this); | |||
1914 | } |
|
2303 | } | |
1915 | }; |
|
2304 | }; | |
1916 | // Utility used by replace and split above |
|
2305 | // Utility used by replace and split above | |
@@ -1929,6 +2318,193 b' var CodeMirror = (function() {' | |||||
1929 | } |
|
2318 | } | |
1930 | } |
|
2319 | } | |
1931 |
|
2320 | |||
|
2321 | // Data structure that holds the sequence of lines. | |||
|
2322 | function LeafChunk(lines) { | |||
|
2323 | this.lines = lines; | |||
|
2324 | this.parent = null; | |||
|
2325 | for (var i = 0, e = lines.length, height = 0; i < e; ++i) { | |||
|
2326 | lines[i].parent = this; | |||
|
2327 | height += lines[i].height; | |||
|
2328 | } | |||
|
2329 | this.height = height; | |||
|
2330 | } | |||
|
2331 | LeafChunk.prototype = { | |||
|
2332 | chunkSize: function() { return this.lines.length; }, | |||
|
2333 | remove: function(at, n, callbacks) { | |||
|
2334 | for (var i = at, e = at + n; i < e; ++i) { | |||
|
2335 | var line = this.lines[i]; | |||
|
2336 | this.height -= line.height; | |||
|
2337 | line.cleanUp(); | |||
|
2338 | if (line.handlers) | |||
|
2339 | for (var j = 0; j < line.handlers.length; ++j) callbacks.push(line.handlers[j]); | |||
|
2340 | } | |||
|
2341 | this.lines.splice(at, n); | |||
|
2342 | }, | |||
|
2343 | collapse: function(lines) { | |||
|
2344 | lines.splice.apply(lines, [lines.length, 0].concat(this.lines)); | |||
|
2345 | }, | |||
|
2346 | insertHeight: function(at, lines, height) { | |||
|
2347 | this.height += height; | |||
|
2348 | this.lines.splice.apply(this.lines, [at, 0].concat(lines)); | |||
|
2349 | for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this; | |||
|
2350 | }, | |||
|
2351 | iterN: function(at, n, op) { | |||
|
2352 | for (var e = at + n; at < e; ++at) | |||
|
2353 | if (op(this.lines[at])) return true; | |||
|
2354 | } | |||
|
2355 | }; | |||
|
2356 | function BranchChunk(children) { | |||
|
2357 | this.children = children; | |||
|
2358 | var size = 0, height = 0; | |||
|
2359 | for (var i = 0, e = children.length; i < e; ++i) { | |||
|
2360 | var ch = children[i]; | |||
|
2361 | size += ch.chunkSize(); height += ch.height; | |||
|
2362 | ch.parent = this; | |||
|
2363 | } | |||
|
2364 | this.size = size; | |||
|
2365 | this.height = height; | |||
|
2366 | this.parent = null; | |||
|
2367 | } | |||
|
2368 | BranchChunk.prototype = { | |||
|
2369 | chunkSize: function() { return this.size; }, | |||
|
2370 | remove: function(at, n, callbacks) { | |||
|
2371 | this.size -= n; | |||
|
2372 | for (var i = 0; i < this.children.length; ++i) { | |||
|
2373 | var child = this.children[i], sz = child.chunkSize(); | |||
|
2374 | if (at < sz) { | |||
|
2375 | var rm = Math.min(n, sz - at), oldHeight = child.height; | |||
|
2376 | child.remove(at, rm, callbacks); | |||
|
2377 | this.height -= oldHeight - child.height; | |||
|
2378 | if (sz == rm) { this.children.splice(i--, 1); child.parent = null; } | |||
|
2379 | if ((n -= rm) == 0) break; | |||
|
2380 | at = 0; | |||
|
2381 | } else at -= sz; | |||
|
2382 | } | |||
|
2383 | if (this.size - n < 25) { | |||
|
2384 | var lines = []; | |||
|
2385 | this.collapse(lines); | |||
|
2386 | this.children = [new LeafChunk(lines)]; | |||
|
2387 | } | |||
|
2388 | }, | |||
|
2389 | collapse: function(lines) { | |||
|
2390 | for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines); | |||
|
2391 | }, | |||
|
2392 | insert: function(at, lines) { | |||
|
2393 | var height = 0; | |||
|
2394 | for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height; | |||
|
2395 | this.insertHeight(at, lines, height); | |||
|
2396 | }, | |||
|
2397 | insertHeight: function(at, lines, height) { | |||
|
2398 | this.size += lines.length; | |||
|
2399 | this.height += height; | |||
|
2400 | for (var i = 0, e = this.children.length; i < e; ++i) { | |||
|
2401 | var child = this.children[i], sz = child.chunkSize(); | |||
|
2402 | if (at <= sz) { | |||
|
2403 | child.insertHeight(at, lines, height); | |||
|
2404 | if (child.lines && child.lines.length > 50) { | |||
|
2405 | while (child.lines.length > 50) { | |||
|
2406 | var spilled = child.lines.splice(child.lines.length - 25, 25); | |||
|
2407 | var newleaf = new LeafChunk(spilled); | |||
|
2408 | child.height -= newleaf.height; | |||
|
2409 | this.children.splice(i + 1, 0, newleaf); | |||
|
2410 | newleaf.parent = this; | |||
|
2411 | } | |||
|
2412 | this.maybeSpill(); | |||
|
2413 | } | |||
|
2414 | break; | |||
|
2415 | } | |||
|
2416 | at -= sz; | |||
|
2417 | } | |||
|
2418 | }, | |||
|
2419 | maybeSpill: function() { | |||
|
2420 | if (this.children.length <= 10) return; | |||
|
2421 | var me = this; | |||
|
2422 | do { | |||
|
2423 | var spilled = me.children.splice(me.children.length - 5, 5); | |||
|
2424 | var sibling = new BranchChunk(spilled); | |||
|
2425 | if (!me.parent) { // Become the parent node | |||
|
2426 | var copy = new BranchChunk(me.children); | |||
|
2427 | copy.parent = me; | |||
|
2428 | me.children = [copy, sibling]; | |||
|
2429 | me = copy; | |||
|
2430 | } else { | |||
|
2431 | me.size -= sibling.size; | |||
|
2432 | me.height -= sibling.height; | |||
|
2433 | var myIndex = indexOf(me.parent.children, me); | |||
|
2434 | me.parent.children.splice(myIndex + 1, 0, sibling); | |||
|
2435 | } | |||
|
2436 | sibling.parent = me.parent; | |||
|
2437 | } while (me.children.length > 10); | |||
|
2438 | me.parent.maybeSpill(); | |||
|
2439 | }, | |||
|
2440 | iter: function(from, to, op) { this.iterN(from, to - from, op); }, | |||
|
2441 | iterN: function(at, n, op) { | |||
|
2442 | for (var i = 0, e = this.children.length; i < e; ++i) { | |||
|
2443 | var child = this.children[i], sz = child.chunkSize(); | |||
|
2444 | if (at < sz) { | |||
|
2445 | var used = Math.min(n, sz - at); | |||
|
2446 | if (child.iterN(at, used, op)) return true; | |||
|
2447 | if ((n -= used) == 0) break; | |||
|
2448 | at = 0; | |||
|
2449 | } else at -= sz; | |||
|
2450 | } | |||
|
2451 | } | |||
|
2452 | }; | |||
|
2453 | ||||
|
2454 | function getLineAt(chunk, n) { | |||
|
2455 | while (!chunk.lines) { | |||
|
2456 | for (var i = 0;; ++i) { | |||
|
2457 | var child = chunk.children[i], sz = child.chunkSize(); | |||
|
2458 | if (n < sz) { chunk = child; break; } | |||
|
2459 | n -= sz; | |||
|
2460 | } | |||
|
2461 | } | |||
|
2462 | return chunk.lines[n]; | |||
|
2463 | } | |||
|
2464 | function lineNo(line) { | |||
|
2465 | if (line.parent == null) return null; | |||
|
2466 | var cur = line.parent, no = indexOf(cur.lines, line); | |||
|
2467 | for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) { | |||
|
2468 | for (var i = 0, e = chunk.children.length; ; ++i) { | |||
|
2469 | if (chunk.children[i] == cur) break; | |||
|
2470 | no += chunk.children[i].chunkSize(); | |||
|
2471 | } | |||
|
2472 | } | |||
|
2473 | return no; | |||
|
2474 | } | |||
|
2475 | function lineAtHeight(chunk, h) { | |||
|
2476 | var n = 0; | |||
|
2477 | outer: do { | |||
|
2478 | for (var i = 0, e = chunk.children.length; i < e; ++i) { | |||
|
2479 | var child = chunk.children[i], ch = child.height; | |||
|
2480 | if (h < ch) { chunk = child; continue outer; } | |||
|
2481 | h -= ch; | |||
|
2482 | n += child.chunkSize(); | |||
|
2483 | } | |||
|
2484 | return n; | |||
|
2485 | } while (!chunk.lines); | |||
|
2486 | for (var i = 0, e = chunk.lines.length; i < e; ++i) { | |||
|
2487 | var line = chunk.lines[i], lh = line.height; | |||
|
2488 | if (h < lh) break; | |||
|
2489 | h -= lh; | |||
|
2490 | } | |||
|
2491 | return n + i; | |||
|
2492 | } | |||
|
2493 | function heightAtLine(chunk, n) { | |||
|
2494 | var h = 0; | |||
|
2495 | outer: do { | |||
|
2496 | for (var i = 0, e = chunk.children.length; i < e; ++i) { | |||
|
2497 | var child = chunk.children[i], sz = child.chunkSize(); | |||
|
2498 | if (n < sz) { chunk = child; continue outer; } | |||
|
2499 | n -= sz; | |||
|
2500 | h += child.height; | |||
|
2501 | } | |||
|
2502 | return h; | |||
|
2503 | } while (!chunk.lines); | |||
|
2504 | for (var i = 0; i < n; ++i) h += chunk.lines[i].height; | |||
|
2505 | return h; | |||
|
2506 | } | |||
|
2507 | ||||
1932 | // The history object 'chunks' changes that are made close together |
|
2508 | // The history object 'chunks' changes that are made close together | |
1933 | // and at almost the same time into bigger undoable units. |
|
2509 | // and at almost the same time into bigger undoable units. | |
1934 | function History() { |
|
2510 | function History() { | |
@@ -1978,6 +2554,10 b' var CodeMirror = (function() {' | |||||
1978 | else e.cancelBubble = true; |
|
2554 | else e.cancelBubble = true; | |
1979 | } |
|
2555 | } | |
1980 | function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);} |
|
2556 | function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);} | |
|
2557 | CodeMirror.e_stop = e_stop; | |||
|
2558 | CodeMirror.e_preventDefault = e_preventDefault; | |||
|
2559 | CodeMirror.e_stopPropagation = e_stopPropagation; | |||
|
2560 | ||||
1981 | function e_target(e) {return e.target || e.srcElement;} |
|
2561 | function e_target(e) {return e.target || e.srcElement;} | |
1982 | function e_button(e) { |
|
2562 | function e_button(e) { | |
1983 | if (e.which) return e.which; |
|
2563 | if (e.which) return e.which; | |
@@ -1989,39 +2569,33 b' var CodeMirror = (function() {' | |||||
1989 | // Event handler registration. If disconnect is true, it'll return a |
|
2569 | // Event handler registration. If disconnect is true, it'll return a | |
1990 | // function that unregisters the handler. |
|
2570 | // function that unregisters the handler. | |
1991 | function connect(node, type, handler, disconnect) { |
|
2571 | function connect(node, type, handler, disconnect) { | |
1992 | function wrapHandler(event) {handler(event || window.event);} |
|
|||
1993 | if (typeof node.addEventListener == "function") { |
|
2572 | if (typeof node.addEventListener == "function") { | |
1994 |
node.addEventListener(type, |
|
2573 | node.addEventListener(type, handler, false); | |
1995 |
if (disconnect) return function() {node.removeEventListener(type, |
|
2574 | if (disconnect) return function() {node.removeEventListener(type, handler, false);}; | |
1996 | } |
|
2575 | } | |
1997 | else { |
|
2576 | else { | |
|
2577 | var wrapHandler = function(event) {handler(event || window.event);}; | |||
1998 | node.attachEvent("on" + type, wrapHandler); |
|
2578 | node.attachEvent("on" + type, wrapHandler); | |
1999 | if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);}; |
|
2579 | if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);}; | |
2000 | } |
|
2580 | } | |
2001 | } |
|
2581 | } | |
|
2582 | CodeMirror.connect = connect; | |||
2002 |
|
2583 | |||
2003 | function Delayed() {this.id = null;} |
|
2584 | function Delayed() {this.id = null;} | |
2004 | Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}}; |
|
2585 | Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}}; | |
2005 |
|
2586 | |||
2006 | // Some IE versions don't preserve whitespace when setting the |
|
|||
2007 | // innerHTML of a PRE tag. |
|
|||
2008 | var badInnerHTML = (function() { |
|
|||
2009 | var pre = document.createElement("pre"); |
|
|||
2010 | pre.innerHTML = " "; return !pre.innerHTML; |
|
|||
2011 | })(); |
|
|||
2012 |
|
||||
2013 | // Detect drag-and-drop |
|
2587 | // Detect drag-and-drop | |
2014 |
var dragAndDrop = |
|
2588 | var dragAndDrop = function() { | |
2015 | // IE8 has ondragstart and ondrop properties, but doesn't seem to |
|
2589 | // IE8 has ondragstart and ondrop properties, but doesn't seem to | |
2016 | // actually support ondragstart the way it's supposed to work. |
|
2590 | // actually support ondragstart the way it's supposed to work. | |
2017 | if (/MSIE [1-8]\b/.test(navigator.userAgent)) return false; |
|
2591 | if (/MSIE [1-8]\b/.test(navigator.userAgent)) return false; | |
2018 | var div = document.createElement('div'); |
|
2592 | var div = document.createElement('div'); | |
2019 |
return " |
|
2593 | return "draggable" in div; | |
2020 |
} |
|
2594 | }(); | |
2021 |
|
2595 | |||
2022 | var gecko = /gecko\/\d{7}/i.test(navigator.userAgent); |
|
2596 | var gecko = /gecko\/\d{7}/i.test(navigator.userAgent); | |
2023 | var ie = /MSIE \d/.test(navigator.userAgent); |
|
2597 | var ie = /MSIE \d/.test(navigator.userAgent); | |
2024 |
var |
|
2598 | var webkit = /WebKit\//.test(navigator.userAgent); | |
2025 |
|
2599 | |||
2026 | var lineSep = "\n"; |
|
2600 | var lineSep = "\n"; | |
2027 | // Feature-detect whether newlines in textareas are converted to \r\n |
|
2601 | // Feature-detect whether newlines in textareas are converted to \r\n | |
@@ -2031,15 +2605,9 b' var CodeMirror = (function() {' | |||||
2031 | if (te.value.indexOf("\r") > -1) lineSep = "\r\n"; |
|
2605 | if (te.value.indexOf("\r") > -1) lineSep = "\r\n"; | |
2032 | }()); |
|
2606 | }()); | |
2033 |
|
2607 | |||
2034 | var tabSize = 8; |
|
|||
2035 | var mac = /Mac/.test(navigator.platform); |
|
|||
2036 | var movementKeys = {}; |
|
|||
2037 | for (var i = 35; i <= 40; ++i) |
|
|||
2038 | movementKeys[i] = movementKeys["c" + i] = true; |
|
|||
2039 |
|
||||
2040 | // Counts the column offset in a string, taking tabs into account. |
|
2608 | // Counts the column offset in a string, taking tabs into account. | |
2041 | // Used mostly to find indentation. |
|
2609 | // Used mostly to find indentation. | |
2042 | function countColumn(string, end) { |
|
2610 | function countColumn(string, end, tabSize) { | |
2043 | if (end == null) { |
|
2611 | if (end == null) { | |
2044 | end = string.search(/[^\s\u00a0]/); |
|
2612 | end = string.search(/[^\s\u00a0]/); | |
2045 | if (end == -1) end = string.length; |
|
2613 | if (end == -1) end = string.length; | |
@@ -2055,21 +2623,44 b' var CodeMirror = (function() {' | |||||
2055 | if (elt.currentStyle) return elt.currentStyle; |
|
2623 | if (elt.currentStyle) return elt.currentStyle; | |
2056 | return window.getComputedStyle(elt, null); |
|
2624 | return window.getComputedStyle(elt, null); | |
2057 | } |
|
2625 | } | |
|
2626 | ||||
2058 | // Find the position of an element by following the offsetParent chain. |
|
2627 | // Find the position of an element by following the offsetParent chain. | |
2059 | // If screen==true, it returns screen (rather than page) coordinates. |
|
2628 | // If screen==true, it returns screen (rather than page) coordinates. | |
2060 | function eltOffset(node, screen) { |
|
2629 | function eltOffset(node, screen) { | |
2061 |
var |
|
2630 | var bod = node.ownerDocument.body; | |
2062 |
var x = 0, y = 0, skip |
|
2631 | var x = 0, y = 0, skipBody = false; | |
2063 | for (var n = node; n; n = n.offsetParent) { |
|
2632 | for (var n = node; n; n = n.offsetParent) { | |
2064 |
|
|
2633 | var ol = n.offsetLeft, ot = n.offsetTop; | |
|
2634 | // Firefox reports weird inverted offsets when the body has a border. | |||
|
2635 | if (n == bod) { x += Math.abs(ol); y += Math.abs(ot); } | |||
|
2636 | else { x += ol, y += ot; } | |||
2065 | if (screen && computedStyle(n).position == "fixed") |
|
2637 | if (screen && computedStyle(n).position == "fixed") | |
2066 |
skip |
|
2638 | skipBody = true; | |
2067 | } |
|
2639 | } | |
2068 |
var e = screen && !skip |
|
2640 | var e = screen && !skipBody ? null : bod; | |
2069 | for (var n = node.parentNode; n != e; n = n.parentNode) |
|
2641 | for (var n = node.parentNode; n != e; n = n.parentNode) | |
2070 | if (n.scrollLeft != null) { x -= n.scrollLeft; y -= n.scrollTop;} |
|
2642 | if (n.scrollLeft != null) { x -= n.scrollLeft; y -= n.scrollTop;} | |
2071 | return {left: x, top: y}; |
|
2643 | return {left: x, top: y}; | |
2072 | } |
|
2644 | } | |
|
2645 | // Use the faster and saner getBoundingClientRect method when possible. | |||
|
2646 | if (document.documentElement.getBoundingClientRect != null) eltOffset = function(node, screen) { | |||
|
2647 | // Take the parts of bounding client rect that we are interested in so we are able to edit if need be, | |||
|
2648 | // since the returned value cannot be changed externally (they are kept in sync as the element moves within the page) | |||
|
2649 | try { var box = node.getBoundingClientRect(); box = { top: box.top, left: box.left }; } | |||
|
2650 | catch(e) { box = {top: 0, left: 0}; } | |||
|
2651 | if (!screen) { | |||
|
2652 | // Get the toplevel scroll, working around browser differences. | |||
|
2653 | if (window.pageYOffset == null) { | |||
|
2654 | var t = document.documentElement || document.body.parentNode; | |||
|
2655 | if (t.scrollTop == null) t = document.body; | |||
|
2656 | box.top += t.scrollTop; box.left += t.scrollLeft; | |||
|
2657 | } else { | |||
|
2658 | box.top += window.pageYOffset; box.left += window.pageXOffset; | |||
|
2659 | } | |||
|
2660 | } | |||
|
2661 | return box; | |||
|
2662 | }; | |||
|
2663 | ||||
2073 | // Get a node's text content. |
|
2664 | // Get a node's text content. | |
2074 | function eltText(node) { |
|
2665 | function eltText(node) { | |
2075 | return node.textContent || node.innerText || node.nodeValue || ""; |
|
2666 | return node.textContent || node.innerText || node.nodeValue || ""; | |
@@ -2080,11 +2671,25 b' var CodeMirror = (function() {' | |||||
2080 | function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);} |
|
2671 | function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);} | |
2081 | function copyPos(x) {return {line: x.line, ch: x.ch};} |
|
2672 | function copyPos(x) {return {line: x.line, ch: x.ch};} | |
2082 |
|
2673 | |||
2083 |
var escapeElement = document.createElement(" |
|
2674 | var escapeElement = document.createElement("pre"); | |
2084 | function htmlEscape(str) { |
|
2675 | function htmlEscape(str) { | |
2085 |
|
|
2676 | escapeElement.textContent = str; | |
2086 | return escapeElement.innerHTML; |
|
2677 | return escapeElement.innerHTML; | |
2087 | } |
|
2678 | } | |
|
2679 | // Recent (late 2011) Opera betas insert bogus newlines at the start | |||
|
2680 | // of the textContent, so we strip those. | |||
|
2681 | if (htmlEscape("a") == "\na") | |||
|
2682 | htmlEscape = function(str) { | |||
|
2683 | escapeElement.textContent = str; | |||
|
2684 | return escapeElement.innerHTML.slice(1); | |||
|
2685 | }; | |||
|
2686 | // Some IEs don't preserve tabs through innerHTML | |||
|
2687 | else if (htmlEscape("\t") != "\t") | |||
|
2688 | htmlEscape = function(str) { | |||
|
2689 | escapeElement.innerHTML = ""; | |||
|
2690 | escapeElement.appendChild(document.createTextNode(str)); | |||
|
2691 | return escapeElement.innerHTML; | |||
|
2692 | }; | |||
2088 | CodeMirror.htmlEscape = htmlEscape; |
|
2693 | CodeMirror.htmlEscape = htmlEscape; | |
2089 |
|
2694 | |||
2090 | // Used to position the cursor after an undo/redo by finding the |
|
2695 | // Used to position the cursor after an undo/redo by finding the | |
@@ -2103,95 +2708,54 b' var CodeMirror = (function() {' | |||||
2103 | if (collection[i] == elt) return i; |
|
2708 | if (collection[i] == elt) return i; | |
2104 | return -1; |
|
2709 | return -1; | |
2105 | } |
|
2710 | } | |
|
2711 | function isWordChar(ch) { | |||
|
2712 | return /\w/.test(ch) || ch.toUpperCase() != ch.toLowerCase(); | |||
|
2713 | } | |||
2106 |
|
2714 | |||
2107 | // See if "".split is the broken IE version, if so, provide an |
|
2715 | // See if "".split is the broken IE version, if so, provide an | |
2108 | // alternative way to split lines. |
|
2716 | // alternative way to split lines. | |
2109 | var splitLines, selRange, setSelRange; |
|
2717 | var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) { | |
2110 | if ("\n\nb".split(/\n/).length != 3) |
|
2718 | var pos = 0, nl, result = []; | |
2111 | splitLines = function(string) { |
|
2719 | while ((nl = string.indexOf("\n", pos)) > -1) { | |
2112 | var pos = 0, nl, result = []; |
|
2720 | result.push(string.slice(pos, string.charAt(nl-1) == "\r" ? nl - 1 : nl)); | |
2113 | while ((nl = string.indexOf("\n", pos)) > -1) { |
|
2721 | pos = nl + 1; | |
2114 | result.push(string.slice(pos, string.charAt(nl-1) == "\r" ? nl - 1 : nl)); |
|
2722 | } | |
2115 | pos = nl + 1; |
|
2723 | result.push(string.slice(pos)); | |
2116 | } |
|
2724 | return result; | |
2117 | result.push(string.slice(pos)); |
|
2725 | } : function(string){return string.split(/\r?\n/);}; | |
2118 | return result; |
|
|||
2119 | }; |
|
|||
2120 | else |
|
|||
2121 | splitLines = function(string){return string.split(/\r?\n/);}; |
|
|||
2122 | CodeMirror.splitLines = splitLines; |
|
2726 | CodeMirror.splitLines = splitLines; | |
2123 |
|
2727 | |||
2124 | // Sane model of finding and setting the selection in a textarea |
|
2728 | var hasSelection = window.getSelection ? function(te) { | |
2125 | if (window.getSelection) { |
|
2729 | try { return te.selectionStart != te.selectionEnd; } | |
2126 | selRange = function(te) { |
|
2730 | catch(e) { return false; } | |
2127 | try {return {start: te.selectionStart, end: te.selectionEnd};} |
|
2731 | } : function(te) { | |
2128 | catch(e) {return null;} |
|
2732 | try {var range = te.ownerDocument.selection.createRange();} | |
2129 | }; |
|
2733 | catch(e) {} | |
2130 | if (safari) |
|
2734 | if (!range || range.parentElement() != te) return false; | |
2131 | // On Safari, selection set with setSelectionRange are in a sort |
|
2735 | return range.compareEndPoints("StartToEnd", range) != 0; | |
2132 | // of limbo wrt their anchor. If you press shift-left in them, |
|
2736 | }; | |
2133 | // the anchor is put at the end, and the selection expanded to |
|
|||
2134 | // the left. If you press shift-right, the anchor ends up at the |
|
|||
2135 | // front. This is not what CodeMirror wants, so it does a |
|
|||
2136 | // spurious modify() call to get out of limbo. |
|
|||
2137 | setSelRange = function(te, start, end) { |
|
|||
2138 | if (start == end) |
|
|||
2139 | te.setSelectionRange(start, end); |
|
|||
2140 | else { |
|
|||
2141 | te.setSelectionRange(start, end - 1); |
|
|||
2142 | window.getSelection().modify("extend", "forward", "character"); |
|
|||
2143 | } |
|
|||
2144 | }; |
|
|||
2145 | else |
|
|||
2146 | setSelRange = function(te, start, end) { |
|
|||
2147 | try {te.setSelectionRange(start, end);} |
|
|||
2148 | catch(e) {} // Fails on Firefox when textarea isn't part of the document |
|
|||
2149 | }; |
|
|||
2150 | } |
|
|||
2151 | // IE model. Don't ask. |
|
|||
2152 | else { |
|
|||
2153 | selRange = function(te) { |
|
|||
2154 | try {var range = te.ownerDocument.selection.createRange();} |
|
|||
2155 | catch(e) {return null;} |
|
|||
2156 | if (!range || range.parentElement() != te) return null; |
|
|||
2157 | var val = te.value, len = val.length, localRange = te.createTextRange(); |
|
|||
2158 | localRange.moveToBookmark(range.getBookmark()); |
|
|||
2159 | var endRange = te.createTextRange(); |
|
|||
2160 | endRange.collapse(false); |
|
|||
2161 |
|
||||
2162 | if (localRange.compareEndPoints("StartToEnd", endRange) > -1) |
|
|||
2163 | return {start: len, end: len}; |
|
|||
2164 |
|
||||
2165 | var start = -localRange.moveStart("character", -len); |
|
|||
2166 | for (var i = val.indexOf("\r"); i > -1 && i < start; i = val.indexOf("\r", i+1), start++) {} |
|
|||
2167 |
|
||||
2168 | if (localRange.compareEndPoints("EndToEnd", endRange) > -1) |
|
|||
2169 | return {start: start, end: len}; |
|
|||
2170 |
|
||||
2171 | var end = -localRange.moveEnd("character", -len); |
|
|||
2172 | for (var i = val.indexOf("\r"); i > -1 && i < end; i = val.indexOf("\r", i+1), end++) {} |
|
|||
2173 | return {start: start, end: end}; |
|
|||
2174 | }; |
|
|||
2175 | setSelRange = function(te, start, end) { |
|
|||
2176 | var range = te.createTextRange(); |
|
|||
2177 | range.collapse(true); |
|
|||
2178 | var endrange = range.duplicate(); |
|
|||
2179 | var newlines = 0, txt = te.value; |
|
|||
2180 | for (var pos = txt.indexOf("\n"); pos > -1 && pos < start; pos = txt.indexOf("\n", pos + 1)) |
|
|||
2181 | ++newlines; |
|
|||
2182 | range.move("character", start - newlines); |
|
|||
2183 | for (; pos > -1 && pos < end; pos = txt.indexOf("\n", pos + 1)) |
|
|||
2184 | ++newlines; |
|
|||
2185 | endrange.move("character", end - newlines); |
|
|||
2186 | range.setEndPoint("EndToEnd", endrange); |
|
|||
2187 | range.select(); |
|
|||
2188 | }; |
|
|||
2189 | } |
|
|||
2190 |
|
2737 | |||
2191 | CodeMirror.defineMode("null", function() { |
|
2738 | CodeMirror.defineMode("null", function() { | |
2192 | return {token: function(stream) {stream.skipToEnd();}}; |
|
2739 | return {token: function(stream) {stream.skipToEnd();}}; | |
2193 | }); |
|
2740 | }); | |
2194 | CodeMirror.defineMIME("text/plain", "null"); |
|
2741 | CodeMirror.defineMIME("text/plain", "null"); | |
2195 |
|
2742 | |||
|
2743 | var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt", | |||
|
2744 | 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", | |||
|
2745 | 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert", | |||
|
2746 | 46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 186: ";", 187: "=", 188: ",", | |||
|
2747 | 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'", 63276: "PageUp", | |||
|
2748 | 63277: "PageDown", 63275: "End", 63273: "Home", 63234: "Left", 63232: "Up", 63235: "Right", | |||
|
2749 | 63233: "Down", 63302: "Insert", 63272: "Delete"}; | |||
|
2750 | CodeMirror.keyNames = keyNames; | |||
|
2751 | (function() { | |||
|
2752 | // Number keys | |||
|
2753 | for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i); | |||
|
2754 | // Alphabetic keys | |||
|
2755 | for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i); | |||
|
2756 | // Function keys | |||
|
2757 | for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i; | |||
|
2758 | })(); | |||
|
2759 | ||||
2196 | return CodeMirror; |
|
2760 | return CodeMirror; | |
2197 | })(); |
|
2761 | })(); |
@@ -42,7 +42,7 b' CodeMirror.overlayParser = function(base, overlay, combine) {' | |||||
42 | if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur; |
|
42 | if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur; | |
43 | else return state.overlayCur; |
|
43 | else return state.overlayCur; | |
44 | }, |
|
44 | }, | |
45 |
|
45 | |||
46 | indent: function(state, textAfter) { |
|
46 | indent: function(state, textAfter) { | |
47 | return base.indent(state.base, textAfter); |
|
47 | return base.indent(state.base, textAfter); | |
48 | }, |
|
48 | }, |
@@ -18,7 +18,7 b' CodeMirror.runMode = function(string, modespec, callback) {' | |||||
18 | var stream = new CodeMirror.StringStream(lines[i]); |
|
18 | var stream = new CodeMirror.StringStream(lines[i]); | |
19 | while (!stream.eol()) { |
|
19 | while (!stream.eol()) { | |
20 | var style = mode.token(stream, state); |
|
20 | var style = mode.token(stream, state); | |
21 | callback(stream.current(), style); |
|
21 | callback(stream.current(), style, i, stream.start); | |
22 | stream.start = stream.pos; |
|
22 | stream.start = stream.pos; | |
23 | } |
|
23 | } | |
24 | } |
|
24 | } |
@@ -1,16 +1,15 b'' | |||||
1 | <!doctype html> |
|
1 | <!doctype html> | |
2 | <html> |
|
2 | <html> | |
3 | <head> |
|
3 | <head> | |
4 |
<title>CodeMirror |
|
4 | <title>CodeMirror: CSS mode</title> | |
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> |
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |
6 | <script src="../../lib/codemirror.js"></script> |
|
6 | <script src="../../lib/codemirror.js"></script> | |
7 | <script src="css.js"></script> |
|
7 | <script src="css.js"></script> | |
8 | <link rel="stylesheet" href="../../theme/default.css"> |
|
|||
9 | <style>.CodeMirror {background: #f8f8f8;}</style> |
|
8 | <style>.CodeMirror {background: #f8f8f8;}</style> | |
10 |
<link rel="stylesheet" href="../../c |
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |
11 | </head> |
|
10 | </head> | |
12 | <body> |
|
11 | <body> | |
13 |
<h1>CodeMirror |
|
12 | <h1>CodeMirror: CSS mode</h1> | |
14 | <form><textarea id="code" name="code"> |
|
13 | <form><textarea id="code" name="code"> | |
15 | /* Some example CSS */ |
|
14 | /* Some example CSS */ | |
16 |
|
15 |
@@ -72,6 +72,10 b' CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {' | |||||
72 | return cssMode.indent(state.localState, textAfter); |
|
72 | return cssMode.indent(state.localState, textAfter); | |
73 | }, |
|
73 | }, | |
74 |
|
74 | |||
|
75 | compareStates: function(a, b) { | |||
|
76 | return htmlMode.compareStates(a.htmlState, b.htmlState); | |||
|
77 | }, | |||
|
78 | ||||
75 | electricChars: "/{}:" |
|
79 | electricChars: "/{}:" | |
76 | } |
|
80 | } | |
77 | }); |
|
81 | }); |
@@ -1,19 +1,18 b'' | |||||
1 | <!doctype html> |
|
1 | <!doctype html> | |
2 | <html> |
|
2 | <html> | |
3 | <head> |
|
3 | <head> | |
4 |
<title>CodeMirror |
|
4 | <title>CodeMirror: HTML mixed mode</title> | |
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> |
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |
6 | <script src="../../lib/codemirror.js"></script> |
|
6 | <script src="../../lib/codemirror.js"></script> | |
7 | <script src="../xml/xml.js"></script> |
|
7 | <script src="../xml/xml.js"></script> | |
8 | <script src="../javascript/javascript.js"></script> |
|
8 | <script src="../javascript/javascript.js"></script> | |
9 | <script src="../css/css.js"></script> |
|
9 | <script src="../css/css.js"></script> | |
10 | <link rel="stylesheet" href="../../theme/default.css"> |
|
|||
11 | <script src="htmlmixed.js"></script> |
|
10 | <script src="htmlmixed.js"></script> | |
12 |
<link rel="stylesheet" href="../../c |
|
11 | <link rel="stylesheet" href="../../doc/docs.css"> | |
13 | <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
|
12 | <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |
14 | </head> |
|
13 | </head> | |
15 | <body> |
|
14 | <body> | |
16 |
<h1>CodeMirror |
|
15 | <h1>CodeMirror: HTML mixed mode</h1> | |
17 | <form><textarea id="code" name="code"> |
|
16 | <form><textarea id="code" name="code"> | |
18 | <html style="color: green"> |
|
17 | <html style="color: green"> | |
19 | <!-- this is a comment --> |
|
18 | <!-- this is a comment --> |
@@ -1,16 +1,15 b'' | |||||
1 | <!doctype html> |
|
1 | <!doctype html> | |
2 | <html> |
|
2 | <html> | |
3 | <head> |
|
3 | <head> | |
4 |
<title>CodeMirror |
|
4 | <title>CodeMirror: JavaScript mode</title> | |
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> |
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |
6 | <script src="../../lib/codemirror.js"></script> |
|
6 | <script src="../../lib/codemirror.js"></script> | |
7 | <script src="javascript.js"></script> |
|
7 | <script src="javascript.js"></script> | |
8 |
<link rel="stylesheet" href="../../ |
|
8 | <link rel="stylesheet" href="../../doc/docs.css"> | |
9 | <link rel="stylesheet" href="../../css/docs.css"> |
|
|||
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
|
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |
11 | </head> |
|
10 | </head> | |
12 | <body> |
|
11 | <body> | |
13 |
<h1>CodeMirror |
|
12 | <h1>CodeMirror: JavaScript mode</h1> | |
14 |
|
13 | |||
15 | <div><textarea id="code" name="code"> |
|
14 | <div><textarea id="code" name="code"> | |
16 | // Demo code (the actual new parser character stream implementation) |
|
15 | // Demo code (the actual new parser character stream implementation) |
@@ -11,7 +11,8 b' CodeMirror.defineMode("javascript", function(config, parserConfig) {' | |||||
11 | return { |
|
11 | return { | |
12 | "if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, |
|
12 | "if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, | |
13 | "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, |
|
13 | "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, | |
14 |
"var": kw("var"), " |
|
14 | "var": kw("var"), "const": kw("var"), "let": kw("var"), | |
|
15 | "function": kw("function"), "catch": kw("catch"), | |||
15 | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), |
|
16 | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), | |
16 | "in": operator, "typeof": operator, "instanceof": operator, |
|
17 | "in": operator, "typeof": operator, "instanceof": operator, | |
17 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom |
|
18 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom | |
@@ -52,9 +53,9 b' CodeMirror.defineMode("javascript", function(config, parserConfig) {' | |||||
52 | else if (ch == "0" && stream.eat(/x/i)) { |
|
53 | else if (ch == "0" && stream.eat(/x/i)) { | |
53 | stream.eatWhile(/[\da-f]/i); |
|
54 | stream.eatWhile(/[\da-f]/i); | |
54 | return ret("number", "number"); |
|
55 | return ret("number", "number"); | |
55 | } |
|
56 | } | |
56 | else if (/\d/.test(ch)) { |
|
57 | else if (/\d/.test(ch)) { | |
57 | stream.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/); |
|
58 | stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); | |
58 | return ret("number", "number"); |
|
59 | return ret("number", "number"); | |
59 | } |
|
60 | } | |
60 | else if (ch == "/") { |
|
61 | else if (ch == "/") { | |
@@ -86,7 +87,7 b' CodeMirror.defineMode("javascript", function(config, parserConfig) {' | |||||
86 | else { |
|
87 | else { | |
87 | stream.eatWhile(/[\w\$_]/); |
|
88 | stream.eatWhile(/[\w\$_]/); | |
88 | var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; |
|
89 | var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; | |
89 | return known ? ret(known.type, known.style, word) : |
|
90 | return (known && state.kwAllowed) ? ret(known.type, known.style, word) : | |
90 | ret("variable", "variable", word); |
|
91 | ret("variable", "variable", word); | |
91 | } |
|
92 | } | |
92 | } |
|
93 | } | |
@@ -134,7 +135,7 b' CodeMirror.defineMode("javascript", function(config, parserConfig) {' | |||||
134 | // Communicate our context to the combinators. |
|
135 | // Communicate our context to the combinators. | |
135 | // (Less wasteful than consing up a hundred closures on every call.) |
|
136 | // (Less wasteful than consing up a hundred closures on every call.) | |
136 | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; |
|
137 | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; | |
137 |
|
138 | |||
138 | if (!state.lexical.hasOwnProperty("align")) |
|
139 | if (!state.lexical.hasOwnProperty("align")) | |
139 | state.lexical.align = true; |
|
140 | state.lexical.align = true; | |
140 |
|
141 | |||
@@ -228,13 +229,18 b' CodeMirror.defineMode("javascript", function(config, parserConfig) {' | |||||
228 | function expression(type) { |
|
229 | function expression(type) { | |
229 | if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator); |
|
230 | if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator); | |
230 | if (type == "function") return cont(functiondef); |
|
231 | if (type == "function") return cont(functiondef); | |
231 | if (type == "keyword c") return cont(expression); |
|
232 | if (type == "keyword c") return cont(maybeexpression); | |
232 | if (type == "(") return cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator); |
|
233 | if (type == "(") return cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator); | |
233 | if (type == "operator") return cont(expression); |
|
234 | if (type == "operator") return cont(expression); | |
234 | if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator); |
|
235 | if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator); | |
235 | if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator); |
|
236 | if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator); | |
236 | return cont(); |
|
237 | return cont(); | |
237 | } |
|
238 | } | |
|
239 | function maybeexpression(type) { | |||
|
240 | if (type.match(/[;\}\)\],]/)) return pass(); | |||
|
241 | return pass(expression); | |||
|
242 | } | |||
|
243 | ||||
238 | function maybeoperator(type, value) { |
|
244 | function maybeoperator(type, value) { | |
239 | if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator); |
|
245 | if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator); | |
240 | if (type == "operator") return cont(expression); |
|
246 | if (type == "operator") return cont(expression); | |
@@ -310,6 +316,7 b' CodeMirror.defineMode("javascript", function(config, parserConfig) {' | |||||
310 | return { |
|
316 | return { | |
311 | tokenize: jsTokenBase, |
|
317 | tokenize: jsTokenBase, | |
312 | reAllowed: true, |
|
318 | reAllowed: true, | |
|
319 | kwAllowed: true, | |||
313 | cc: [], |
|
320 | cc: [], | |
314 | lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), |
|
321 | lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), | |
315 | localVars: null, |
|
322 | localVars: null, | |
@@ -328,6 +335,7 b' CodeMirror.defineMode("javascript", function(config, parserConfig) {' | |||||
328 | var style = state.tokenize(stream, state); |
|
335 | var style = state.tokenize(stream, state); | |
329 | if (type == "comment") return style; |
|
336 | if (type == "comment") return style; | |
330 | state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/); |
|
337 | state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/); | |
|
338 | state.kwAllowed = type != '.'; | |||
331 | return parseJS(state, style, type, content, stream); |
|
339 | return parseJS(state, style, type, content, stream); | |
332 | }, |
|
340 | }, | |
333 |
|
341 |
@@ -1,18 +1,17 b'' | |||||
1 | <!doctype html> |
|
1 | <!doctype html> | |
2 | <html> |
|
2 | <html> | |
3 | <head> |
|
3 | <head> | |
4 |
<title>CodeMirror |
|
4 | <title>CodeMirror: Markdown mode</title> | |
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> |
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |
6 | <script src="../../lib/codemirror.js"></script> |
|
6 | <script src="../../lib/codemirror.js"></script> | |
7 | <script src="../xml/xml.js"></script> |
|
7 | <script src="../xml/xml.js"></script> | |
8 | <script src="markdown.js"></script> |
|
8 | <script src="markdown.js"></script> | |
9 | <link rel="stylesheet" href="../../theme/default.css"> |
|
|||
10 | <link rel="stylesheet" href="markdown.css"> |
|
9 | <link rel="stylesheet" href="markdown.css"> | |
11 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
|
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |
12 |
<link rel="stylesheet" href="../../c |
|
11 | <link rel="stylesheet" href="../../doc/docs.css"> | |
13 | </head> |
|
12 | </head> | |
14 | <body> |
|
13 | <body> | |
15 |
<h1>CodeMirror |
|
14 | <h1>CodeMirror: Markdown mode</h1> | |
16 |
|
15 | |||
17 | <!-- source: http://daringfireball.net/projects/markdown/basics.text --> |
|
16 | <!-- source: http://daringfireball.net/projects/markdown/basics.text --> | |
18 | <form><textarea id="code" name="code"> |
|
17 | <form><textarea id="code" name="code"> | |
@@ -71,7 +70,7 b' Markdown:' | |||||
71 |
|
70 | |||
72 | A First Level Header |
|
71 | A First Level Header | |
73 | ==================== |
|
72 | ==================== | |
74 |
|
73 | |||
75 | A Second Level Header |
|
74 | A Second Level Header | |
76 | --------------------- |
|
75 | --------------------- | |
77 |
|
76 | |||
@@ -81,11 +80,11 b' Markdown:' | |||||
81 |
|
80 | |||
82 | The quick brown fox jumped over the lazy |
|
81 | The quick brown fox jumped over the lazy | |
83 | dog's back. |
|
82 | dog's back. | |
84 |
|
83 | |||
85 | ### Header 3 |
|
84 | ### Header 3 | |
86 |
|
85 | |||
87 | > This is a blockquote. |
|
86 | > This is a blockquote. | |
88 | > |
|
87 | > | |
89 | > This is the second paragraph in the blockquote. |
|
88 | > This is the second paragraph in the blockquote. | |
90 | > |
|
89 | > | |
91 | > ## This is an H2 in a blockquote |
|
90 | > ## This is an H2 in a blockquote | |
@@ -94,23 +93,23 b' Markdown:' | |||||
94 | Output: |
|
93 | Output: | |
95 |
|
94 | |||
96 | <h1>A First Level Header</h1> |
|
95 | <h1>A First Level Header</h1> | |
97 |
|
96 | |||
98 | <h2>A Second Level Header</h2> |
|
97 | <h2>A Second Level Header</h2> | |
99 |
|
98 | |||
100 | <p>Now is the time for all good men to come to |
|
99 | <p>Now is the time for all good men to come to | |
101 | the aid of their country. This is just a |
|
100 | the aid of their country. This is just a | |
102 | regular paragraph.</p> |
|
101 | regular paragraph.</p> | |
103 |
|
102 | |||
104 | <p>The quick brown fox jumped over the lazy |
|
103 | <p>The quick brown fox jumped over the lazy | |
105 | dog's back.</p> |
|
104 | dog's back.</p> | |
106 |
|
105 | |||
107 | <h3>Header 3</h3> |
|
106 | <h3>Header 3</h3> | |
108 |
|
107 | |||
109 | <blockquote> |
|
108 | <blockquote> | |
110 | <p>This is a blockquote.</p> |
|
109 | <p>This is a blockquote.</p> | |
111 |
|
110 | |||
112 | <p>This is the second paragraph in the blockquote.</p> |
|
111 | <p>This is the second paragraph in the blockquote.</p> | |
113 |
|
112 | |||
114 | <h2>This is an H2 in a blockquote</h2> |
|
113 | <h2>This is an H2 in a blockquote</h2> | |
115 | </blockquote> |
|
114 | </blockquote> | |
116 |
|
115 | |||
@@ -124,7 +123,7 b' Markdown:' | |||||
124 |
|
123 | |||
125 | Some of these words *are emphasized*. |
|
124 | Some of these words *are emphasized*. | |
126 | Some of these words _are emphasized also_. |
|
125 | Some of these words _are emphasized also_. | |
127 |
|
126 | |||
128 | Use two asterisks for **strong emphasis**. |
|
127 | Use two asterisks for **strong emphasis**. | |
129 | Or, if you prefer, __use two underscores instead__. |
|
128 | Or, if you prefer, __use two underscores instead__. | |
130 |
|
129 | |||
@@ -132,10 +131,10 b' Output:' | |||||
132 |
|
131 | |||
133 | <p>Some of these words <em>are emphasized</em>. |
|
132 | <p>Some of these words <em>are emphasized</em>. | |
134 | Some of these words <em>are emphasized also</em>.</p> |
|
133 | Some of these words <em>are emphasized also</em>.</p> | |
135 |
|
134 | |||
136 | <p>Use two asterisks for <strong>strong emphasis</strong>. |
|
135 | <p>Use two asterisks for <strong>strong emphasis</strong>. | |
137 | Or, if you prefer, <strong>use two underscores instead</strong>.</p> |
|
136 | Or, if you prefer, <strong>use two underscores instead</strong>.</p> | |
138 |
|
137 | |||
139 |
|
138 | |||
140 |
|
139 | |||
141 | ## Lists ## |
|
140 | ## Lists ## | |
@@ -188,7 +187,7 b' list item text. You can create multi-paragraph list items by indenting' | |||||
188 | the paragraphs by 4 spaces or 1 tab: |
|
187 | the paragraphs by 4 spaces or 1 tab: | |
189 |
|
188 | |||
190 | * A list item. |
|
189 | * A list item. | |
191 |
|
190 | |||
192 | With multiple paragraphs. |
|
191 | With multiple paragraphs. | |
193 |
|
192 | |||
194 | * Another item in the list. |
|
193 | * Another item in the list. | |
@@ -200,7 +199,7 b' Output:' | |||||
200 | <p>With multiple paragraphs.</p></li> |
|
199 | <p>With multiple paragraphs.</p></li> | |
201 | <li><p>Another item in the list.</p></li> |
|
200 | <li><p>Another item in the list.</p></li> | |
202 | </ul> |
|
201 | </ul> | |
203 |
|
202 | |||
204 |
|
203 | |||
205 |
|
204 | |||
206 | ### Links ### |
|
205 | ### Links ### | |
@@ -295,7 +294,7 b' Output:' | |||||
295 |
|
294 | |||
296 | <p>I strongly recommend against using any |
|
295 | <p>I strongly recommend against using any | |
297 | <code>&lt;blink&gt;</code> tags.</p> |
|
296 | <code>&lt;blink&gt;</code> tags.</p> | |
298 |
|
297 | |||
299 | <p>I wish SmartyPants used named entities like |
|
298 | <p>I wish SmartyPants used named entities like | |
300 | <code>&amp;mdash;</code> instead of decimal-encoded |
|
299 | <code>&amp;mdash;</code> instead of decimal-encoded | |
301 | entites like <code>&amp;#8212;</code>.</p> |
|
300 | entites like <code>&amp;#8212;</code>.</p> | |
@@ -318,7 +317,7 b' Output:' | |||||
318 |
|
317 | |||
319 | <p>If you want your page to validate under XHTML 1.0 Strict, |
|
318 | <p>If you want your page to validate under XHTML 1.0 Strict, | |
320 | you've got to put paragraph tags in your blockquotes:</p> |
|
319 | you've got to put paragraph tags in your blockquotes:</p> | |
321 |
|
320 | |||
322 | <pre><code>&lt;blockquote&gt; |
|
321 | <pre><code>&lt;blockquote&gt; | |
323 | &lt;p&gt;For example.&lt;/p&gt; |
|
322 | &lt;p&gt;For example.&lt;/p&gt; | |
324 | &lt;/blockquote&gt; |
|
323 | &lt;/blockquote&gt; |
@@ -3,12 +3,12 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
3 | var htmlMode = CodeMirror.getMode(cmCfg, { name: 'xml', htmlMode: true }); |
|
3 | var htmlMode = CodeMirror.getMode(cmCfg, { name: 'xml', htmlMode: true }); | |
4 |
|
4 | |||
5 | var header = 'header' |
|
5 | var header = 'header' | |
6 |
, code = 'co |
|
6 | , code = 'comment' | |
7 | , quote = 'quote' |
|
7 | , quote = 'quote' | |
8 |
, list = ' |
|
8 | , list = 'string' | |
9 | , hr = 'hr' |
|
9 | , hr = 'hr' | |
10 |
, linktext = 'link |
|
10 | , linktext = 'link' | |
11 |
, linkhref = ' |
|
11 | , linkhref = 'string' | |
12 | , em = 'em' |
|
12 | , em = 'em' | |
13 | , strong = 'strong' |
|
13 | , strong = 'strong' | |
14 | , emstrong = 'emstrong'; |
|
14 | , emstrong = 'emstrong'; | |
@@ -38,11 +38,11 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
38 | stream.skipToEnd(); |
|
38 | stream.skipToEnd(); | |
39 | return code; |
|
39 | return code; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | if (stream.eatSpace()) { |
|
42 | if (stream.eatSpace()) { | |
43 | return null; |
|
43 | return null; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | if (stream.peek() === '#' || stream.match(headerRE)) { |
|
46 | if (stream.peek() === '#' || stream.match(headerRE)) { | |
47 | stream.skipToEnd(); |
|
47 | stream.skipToEnd(); | |
48 | return header; |
|
48 | return header; | |
@@ -51,9 +51,6 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
51 | state.indentation++; |
|
51 | state.indentation++; | |
52 | return quote; |
|
52 | return quote; | |
53 | } |
|
53 | } | |
54 | if (stream.peek() === '<') { |
|
|||
55 | return switchBlock(stream, state, htmlBlock); |
|
|||
56 | } |
|
|||
57 | if (stream.peek() === '[') { |
|
54 | if (stream.peek() === '[') { | |
58 | return switchInline(stream, state, footnoteLink); |
|
55 | return switchInline(stream, state, footnoteLink); | |
59 | } |
|
56 | } | |
@@ -63,62 +60,70 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
63 | return hr; |
|
60 | return hr; | |
64 | } |
|
61 | } | |
65 | } |
|
62 | } | |
66 |
|
63 | |||
67 | var match; |
|
64 | var match; | |
68 | if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { |
|
65 | if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { | |
69 | state.indentation += match[0].length; |
|
66 | state.indentation += match[0].length; | |
70 | return list; |
|
67 | return list; | |
71 | } |
|
68 | } | |
72 |
|
69 | |||
73 | return switchInline(stream, state, state.inline); |
|
70 | return switchInline(stream, state, state.inline); | |
74 | } |
|
71 | } | |
75 |
|
72 | |||
76 | function htmlBlock(stream, state) { |
|
73 | function htmlBlock(stream, state) { | |
77 |
var |
|
74 | var style = htmlMode.token(stream, state.htmlState); | |
78 |
if (st |
|
75 | if (style === 'tag' && state.htmlState.type !== 'openTag' && !state.htmlState.context) { | |
|
76 | state.f = inlineNormal; | |||
79 | state.block = blockNormal; |
|
77 | state.block = blockNormal; | |
80 | } |
|
78 | } | |
81 |
return |
|
79 | return style; | |
82 | } |
|
80 | } | |
83 |
|
81 | |||
84 |
|
82 | |||
85 | // Inline |
|
83 | // Inline | |
|
84 | function getType(state) { | |||
|
85 | return state.strong ? (state.em ? emstrong : strong) | |||
|
86 | : (state.em ? em : null); | |||
|
87 | } | |||
86 |
|
88 | |||
87 |
function |
|
89 | function handleText(stream, state) { | |
88 | function getType() { |
|
|||
89 | return state.strong ? (state.em ? emstrong : strong) |
|
|||
90 | : (state.em ? em : null); |
|
|||
91 | } |
|
|||
92 |
|
||||
93 | if (stream.match(textRE, true)) { |
|
90 | if (stream.match(textRE, true)) { | |
94 | return getType(); |
|
91 | return getType(state); | |
95 | } |
|
92 | } | |
|
93 | return undefined; | |||
|
94 | } | |||
96 |
|
95 | |||
|
96 | function inlineNormal(stream, state) { | |||
|
97 | var style = state.text(stream, state) | |||
|
98 | if (typeof style !== 'undefined') | |||
|
99 | return style; | |||
|
100 | ||||
97 | var ch = stream.next(); |
|
101 | var ch = stream.next(); | |
98 |
|
102 | |||
99 | if (ch === '\\') { |
|
103 | if (ch === '\\') { | |
100 | stream.next(); |
|
104 | stream.next(); | |
101 | return getType(); |
|
105 | return getType(state); | |
102 | } |
|
106 | } | |
103 | if (ch === '`') { |
|
107 | if (ch === '`') { | |
104 | return switchInline(stream, state, inlineElement(code, '`')); |
|
108 | return switchInline(stream, state, inlineElement(code, '`')); | |
105 | } |
|
109 | } | |
106 | if (ch === '<') { |
|
|||
107 | return switchInline(stream, state, inlineElement(linktext, '>')); |
|
|||
108 | } |
|
|||
109 | if (ch === '[') { |
|
110 | if (ch === '[') { | |
110 | return switchInline(stream, state, linkText); |
|
111 | return switchInline(stream, state, linkText); | |
111 | } |
|
112 | } | |
|
113 | if (ch === '<' && stream.match(/^\w/, false)) { | |||
|
114 | stream.backUp(1); | |||
|
115 | return switchBlock(stream, state, htmlBlock); | |||
|
116 | } | |||
112 |
|
117 | |||
113 | var t = getType(); |
|
118 | var t = getType(state); | |
114 | if (ch === '*' || ch === '_') { |
|
119 | if (ch === '*' || ch === '_') { | |
115 | if (stream.eat(ch)) { |
|
120 | if (stream.eat(ch)) { | |
116 | return (state.strong = !state.strong) ? getType() : t; |
|
121 | return (state.strong = !state.strong) ? getType(state) : t; | |
117 | } |
|
122 | } | |
118 | return (state.em = !state.em) ? getType() : t; |
|
123 | return (state.em = !state.em) ? getType(state) : t; | |
119 | } |
|
124 | } | |
120 |
|
125 | |||
121 | return getType(); |
|
126 | return getType(state); | |
122 | } |
|
127 | } | |
123 |
|
128 | |||
124 | function linkText(stream, state) { |
|
129 | function linkText(stream, state) { | |
@@ -157,17 +162,20 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
157 | return linkhref; |
|
162 | return linkhref; | |
158 | } |
|
163 | } | |
159 |
|
164 | |||
|
165 | function inlineRE(endChar) { | |||
|
166 | if (!inlineRE[endChar]) { | |||
|
167 | // match any not-escaped-non-endChar and any escaped char | |||
|
168 | // then match endChar or eol | |||
|
169 | inlineRE[endChar] = new RegExp('^(?:[^\\\\\\' + endChar + ']|\\\\.)*(?:\\' + endChar + '|$)'); | |||
|
170 | } | |||
|
171 | return inlineRE[endChar]; | |||
|
172 | } | |||
|
173 | ||||
160 | function inlineElement(type, endChar, next) { |
|
174 | function inlineElement(type, endChar, next) { | |
161 | next = next || inlineNormal; |
|
175 | next = next || inlineNormal; | |
162 | return function(stream, state) { |
|
176 | return function(stream, state) { | |
163 | while (!stream.eol()) { |
|
177 | stream.match(inlineRE(endChar)); | |
164 | var ch = stream.next(); |
|
178 | state.inline = state.f = next; | |
165 | if (ch === '\\') stream.next(); |
|
|||
166 | if (ch === endChar) { |
|
|||
167 | state.inline = state.f = next; |
|
|||
168 | return type; |
|
|||
169 | } |
|
|||
170 | } |
|
|||
171 | return type; |
|
179 | return type; | |
172 | }; |
|
180 | }; | |
173 | } |
|
181 | } | |
@@ -176,12 +184,13 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
176 | startState: function() { |
|
184 | startState: function() { | |
177 | return { |
|
185 | return { | |
178 | f: blockNormal, |
|
186 | f: blockNormal, | |
179 |
|
187 | |||
180 | block: blockNormal, |
|
188 | block: blockNormal, | |
181 | htmlState: htmlMode.startState(), |
|
189 | htmlState: htmlMode.startState(), | |
182 | indentation: 0, |
|
190 | indentation: 0, | |
183 |
|
191 | |||
184 | inline: inlineNormal, |
|
192 | inline: inlineNormal, | |
|
193 | text: handleText, | |||
185 | em: false, |
|
194 | em: false, | |
186 | strong: false |
|
195 | strong: false | |
187 | }; |
|
196 | }; | |
@@ -190,12 +199,13 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
190 | copyState: function(s) { |
|
199 | copyState: function(s) { | |
191 | return { |
|
200 | return { | |
192 | f: s.f, |
|
201 | f: s.f, | |
193 |
|
202 | |||
194 | block: s.block, |
|
203 | block: s.block, | |
195 | htmlState: CodeMirror.copyState(htmlMode, s.htmlState), |
|
204 | htmlState: CodeMirror.copyState(htmlMode, s.htmlState), | |
196 | indentation: s.indentation, |
|
205 | indentation: s.indentation, | |
197 |
|
206 | |||
198 | inline: s.inline, |
|
207 | inline: s.inline, | |
|
208 | text: s.text, | |||
199 | em: s.em, |
|
209 | em: s.em, | |
200 | strong: s.strong |
|
210 | strong: s.strong | |
201 | }; |
|
211 | }; | |
@@ -218,11 +228,13 b' CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {' | |||||
218 | } |
|
228 | } | |
219 | } |
|
229 | } | |
220 | state.indentation = currentIndentation; |
|
230 | state.indentation = currentIndentation; | |
221 |
|
231 | |||
222 | if (currentIndentation > 0) return null; |
|
232 | if (currentIndentation > 0) return null; | |
223 | } |
|
233 | } | |
224 | return state.f(stream, state); |
|
234 | return state.f(stream, state); | |
225 | } |
|
235 | }, | |
|
236 | ||||
|
237 | getType: getType | |||
226 | }; |
|
238 | }; | |
227 |
|
239 | |||
228 | }); |
|
240 | }); |
@@ -1,17 +1,16 b'' | |||||
1 | <!doctype html> |
|
1 | <!doctype html> | |
2 | <html> |
|
2 | <html> | |
3 | <head> |
|
3 | <head> | |
4 |
<title>CodeMirror |
|
4 | <title>CodeMirror: Python mode</title> | |
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> |
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |
6 | <script src="../../lib/codemirror.js"></script> |
|
6 | <script src="../../lib/codemirror.js"></script> | |
7 | <script src="python.js"></script> |
|
7 | <script src="python.js"></script> | |
8 |
<link rel="stylesheet" href="../../ |
|
8 | <link rel="stylesheet" href="../../doc/docs.css"> | |
9 | <link rel="stylesheet" href="../../css/docs.css"> |
|
|||
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
|
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |
11 | </head> |
|
10 | </head> | |
12 | <body> |
|
11 | <body> | |
13 |
<h1>CodeMirror |
|
12 | <h1>CodeMirror: Python mode</h1> | |
14 |
|
13 | |||
15 | <div><textarea id="code" name="code"> |
|
14 | <div><textarea id="code" name="code"> | |
16 | # Literals |
|
15 | # Literals | |
17 | 1234 |
|
16 | 1234 |
@@ -1,15 +1,11 b'' | |||||
1 | CodeMirror.defineMode("python", function(conf, parserConf) { |
|
1 | CodeMirror.defineMode("python", function(conf, parserConf) { | |
2 | var ERRORCLASS = 'error'; |
|
2 | var ERRORCLASS = 'error'; | |
3 |
|
3 | |||
4 | function wordRegexp(words) { |
|
4 | function wordRegexp(words) { | |
5 | return new RegExp("^((" + words.join(")|(") + "))\\b"); |
|
5 | return new RegExp("^((" + words.join(")|(") + "))\\b"); | |
6 | } |
|
6 | } | |
7 |
|
||||
8 | // IPython-specific changes: add '?' as recognized character. |
|
|||
9 | //var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); |
|
|||
10 | var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]"); |
|
|||
11 | // End IPython changes. |
|
|||
12 |
|
7 | |||
|
8 | var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]"); | |||
13 | var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); |
|
9 | var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); | |
14 | var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); |
|
10 | var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); | |
15 | var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); |
|
11 | var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); | |
@@ -69,15 +65,15 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
69 | if (stream.eatSpace()) { |
|
65 | if (stream.eatSpace()) { | |
70 | return null; |
|
66 | return null; | |
71 | } |
|
67 | } | |
72 |
|
68 | |||
73 | var ch = stream.peek(); |
|
69 | var ch = stream.peek(); | |
74 |
|
70 | |||
75 | // Handle Comments |
|
71 | // Handle Comments | |
76 | if (ch === '#') { |
|
72 | if (ch === '#') { | |
77 | stream.skipToEnd(); |
|
73 | stream.skipToEnd(); | |
78 | return 'comment'; |
|
74 | return 'comment'; | |
79 | } |
|
75 | } | |
80 |
|
76 | |||
81 | // Handle Number Literals |
|
77 | // Handle Number Literals | |
82 | if (stream.match(/^[0-9\.]/, false)) { |
|
78 | if (stream.match(/^[0-9\.]/, false)) { | |
83 | var floatLiteral = false; |
|
79 | var floatLiteral = false; | |
@@ -113,13 +109,13 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
113 | return 'number'; |
|
109 | return 'number'; | |
114 | } |
|
110 | } | |
115 | } |
|
111 | } | |
116 |
|
112 | |||
117 | // Handle Strings |
|
113 | // Handle Strings | |
118 | if (stream.match(stringPrefixes)) { |
|
114 | if (stream.match(stringPrefixes)) { | |
119 | state.tokenize = tokenStringFactory(stream.current()); |
|
115 | state.tokenize = tokenStringFactory(stream.current()); | |
120 | return state.tokenize(stream, state); |
|
116 | return state.tokenize(stream, state); | |
121 | } |
|
117 | } | |
122 |
|
118 | |||
123 | // Handle operators and Delimiters |
|
119 | // Handle operators and Delimiters | |
124 | if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { |
|
120 | if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { | |
125 | return null; |
|
121 | return null; | |
@@ -132,31 +128,31 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
132 | if (stream.match(singleDelimiters)) { |
|
128 | if (stream.match(singleDelimiters)) { | |
133 | return null; |
|
129 | return null; | |
134 | } |
|
130 | } | |
135 |
|
131 | |||
136 | if (stream.match(types)) { |
|
132 | if (stream.match(types)) { | |
137 | return 'builtin'; |
|
133 | return 'builtin'; | |
138 | } |
|
134 | } | |
139 |
|
135 | |||
140 | if (stream.match(keywords)) { |
|
136 | if (stream.match(keywords)) { | |
141 | return 'keyword'; |
|
137 | return 'keyword'; | |
142 | } |
|
138 | } | |
143 |
|
139 | |||
144 | if (stream.match(identifiers)) { |
|
140 | if (stream.match(identifiers)) { | |
145 | return 'variable'; |
|
141 | return 'variable'; | |
146 | } |
|
142 | } | |
147 |
|
143 | |||
148 | // Handle non-detected items |
|
144 | // Handle non-detected items | |
149 | stream.next(); |
|
145 | stream.next(); | |
150 | return ERRORCLASS; |
|
146 | return ERRORCLASS; | |
151 | } |
|
147 | } | |
152 |
|
148 | |||
153 | function tokenStringFactory(delimiter) { |
|
149 | function tokenStringFactory(delimiter) { | |
154 | while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) { |
|
150 | while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) { | |
155 | delimiter = delimiter.substr(1); |
|
151 | delimiter = delimiter.substr(1); | |
156 | } |
|
152 | } | |
157 | var singleline = delimiter.length == 1; |
|
153 | var singleline = delimiter.length == 1; | |
158 | var OUTCLASS = 'string'; |
|
154 | var OUTCLASS = 'string'; | |
159 |
|
155 | |||
160 | return function tokenString(stream, state) { |
|
156 | return function tokenString(stream, state) { | |
161 | while (!stream.eol()) { |
|
157 | while (!stream.eol()) { | |
162 | stream.eatWhile(/[^'"\\]/); |
|
158 | stream.eatWhile(/[^'"\\]/); | |
@@ -182,11 +178,15 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
182 | return OUTCLASS; |
|
178 | return OUTCLASS; | |
183 | }; |
|
179 | }; | |
184 | } |
|
180 | } | |
185 |
|
181 | |||
186 | function indent(stream, state, type) { |
|
182 | function indent(stream, state, type) { | |
187 | type = type || 'py'; |
|
183 | type = type || 'py'; | |
188 | var indentUnit = 0; |
|
184 | var indentUnit = 0; | |
189 | if (type === 'py') { |
|
185 | if (type === 'py') { | |
|
186 | if (state.scopes[0].type !== 'py') { | |||
|
187 | state.scopes[0].offset = stream.indentation(); | |||
|
188 | return; | |||
|
189 | } | |||
190 | for (var i = 0; i < state.scopes.length; ++i) { |
|
190 | for (var i = 0; i < state.scopes.length; ++i) { | |
191 | if (state.scopes[i].type === 'py') { |
|
191 | if (state.scopes[i].type === 'py') { | |
192 | indentUnit = state.scopes[i].offset + conf.indentUnit; |
|
192 | indentUnit = state.scopes[i].offset + conf.indentUnit; | |
@@ -201,8 +201,9 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
201 | type: type |
|
201 | type: type | |
202 | }); |
|
202 | }); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | function dedent(stream, state) { |
|
205 | function dedent(stream, state, type) { | |
|
206 | type = type || 'py'; | |||
206 | if (state.scopes.length == 1) return; |
|
207 | if (state.scopes.length == 1) return; | |
207 | if (state.scopes[0].type === 'py') { |
|
208 | if (state.scopes[0].type === 'py') { | |
208 | var _indent = stream.indentation(); |
|
209 | var _indent = stream.indentation(); | |
@@ -221,8 +222,16 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
221 | } |
|
222 | } | |
222 | return false |
|
223 | return false | |
223 | } else { |
|
224 | } else { | |
224 | state.scopes.shift(); |
|
225 | if (type === 'py') { | |
225 | return false; |
|
226 | state.scopes[0].offset = stream.indentation(); | |
|
227 | return false; | |||
|
228 | } else { | |||
|
229 | if (state.scopes[0].type != type) { | |||
|
230 | return true; | |||
|
231 | } | |||
|
232 | state.scopes.shift(); | |||
|
233 | return false; | |||
|
234 | } | |||
226 | } |
|
235 | } | |
227 | } |
|
236 | } | |
228 |
|
237 | |||
@@ -241,7 +250,7 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
241 | return ERRORCLASS; |
|
250 | return ERRORCLASS; | |
242 | } |
|
251 | } | |
243 | } |
|
252 | } | |
244 |
|
253 | |||
245 | // Handle decorators |
|
254 | // Handle decorators | |
246 | if (current === '@') { |
|
255 | if (current === '@') { | |
247 | style = state.tokenize(stream, state); |
|
256 | style = state.tokenize(stream, state); | |
@@ -254,7 +263,7 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
254 | return ERRORCLASS; |
|
263 | return ERRORCLASS; | |
255 | } |
|
264 | } | |
256 | } |
|
265 | } | |
257 |
|
266 | |||
258 | // Handle scope changes. |
|
267 | // Handle scope changes. | |
259 | if (current === 'pass' || current === 'return') { |
|
268 | if (current === 'pass' || current === 'return') { | |
260 | state.dedent += 1; |
|
269 | state.dedent += 1; | |
@@ -274,7 +283,7 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
274 | } |
|
283 | } | |
275 | delimiter_index = '])}'.indexOf(current); |
|
284 | delimiter_index = '])}'.indexOf(current); | |
276 | if (delimiter_index !== -1) { |
|
285 | if (delimiter_index !== -1) { | |
277 | if (dedent(stream, state)) { |
|
286 | if (dedent(stream, state, current)) { | |
278 | return ERRORCLASS; |
|
287 | return ERRORCLASS; | |
279 | } |
|
288 | } | |
280 | } |
|
289 | } | |
@@ -282,7 +291,7 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
282 | if (state.scopes.length > 1) state.scopes.shift(); |
|
291 | if (state.scopes.length > 1) state.scopes.shift(); | |
283 | state.dedent -= 1; |
|
292 | state.dedent -= 1; | |
284 | } |
|
293 | } | |
285 |
|
294 | |||
286 | return style; |
|
295 | return style; | |
287 | } |
|
296 | } | |
288 |
|
297 | |||
@@ -296,27 +305,27 b' CodeMirror.defineMode("python", function(conf, parserConf) {' | |||||
296 | dedent: 0 |
|
305 | dedent: 0 | |
297 | }; |
|
306 | }; | |
298 | }, |
|
307 | }, | |
299 |
|
308 | |||
300 | token: function(stream, state) { |
|
309 | token: function(stream, state) { | |
301 | var style = tokenLexer(stream, state); |
|
310 | var style = tokenLexer(stream, state); | |
302 |
|
311 | |||
303 | state.lastToken = {style:style, content: stream.current()}; |
|
312 | state.lastToken = {style:style, content: stream.current()}; | |
304 |
|
313 | |||
305 | if (stream.eol() && stream.lambda) { |
|
314 | if (stream.eol() && stream.lambda) { | |
306 | state.lambda = false; |
|
315 | state.lambda = false; | |
307 | } |
|
316 | } | |
308 |
|
317 | |||
309 | return style; |
|
318 | return style; | |
310 | }, |
|
319 | }, | |
311 |
|
320 | |||
312 | indent: function(state, textAfter) { |
|
321 | indent: function(state, textAfter) { | |
313 | if (state.tokenize != tokenBase) { |
|
322 | if (state.tokenize != tokenBase) { | |
314 | return 0; |
|
323 | return 0; | |
315 | } |
|
324 | } | |
316 |
|
325 | |||
317 | return state.scopes[0].offset; |
|
326 | return state.scopes[0].offset; | |
318 | } |
|
327 | } | |
319 |
|
328 | |||
320 | }; |
|
329 | }; | |
321 | return external; |
|
330 | return external; | |
322 | }); |
|
331 | }); |
@@ -1,16 +1,15 b'' | |||||
1 | <!doctype html> |
|
1 | <!doctype html> | |
2 | <html> |
|
2 | <html> | |
3 | <head> |
|
3 | <head> | |
4 |
<title>CodeMirror |
|
4 | <title>CodeMirror: reStructuredText mode</title> | |
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> |
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |
6 | <script src="../../lib/codemirror.js"></script> |
|
6 | <script src="../../lib/codemirror.js"></script> | |
7 | <script src="rst.js"></script> |
|
7 | <script src="rst.js"></script> | |
8 | <link rel="stylesheet" href="rst.css"> |
|
|||
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
|
8 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |
10 |
<link rel="stylesheet" href="../../c |
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |
11 | </head> |
|
10 | </head> | |
12 | <body> |
|
11 | <body> | |
13 |
<h1>CodeMirror |
|
12 | <h1>CodeMirror: reStructuredText mode</h1> | |
14 |
|
13 | |||
15 | <form><textarea id="code" name="code"> |
|
14 | <form><textarea id="code" name="code"> | |
16 | .. This is an excerpt from Sphinx documentation: http://sphinx.pocoo.org/_sources/rest.txt |
|
15 | .. This is an excerpt from Sphinx documentation: http://sphinx.pocoo.org/_sources/rest.txt | |
@@ -515,7 +514,7 b' There are some problems one commonly runs into while authoring reST documents:' | |||||
515 | verbatim blocks. By default, reStructuredText mode uses uniform color |
|
514 | verbatim blocks. By default, reStructuredText mode uses uniform color | |
516 | for whole block of verbatim text if no mode is given.</dd> |
|
515 | for whole block of verbatim text if no mode is given.</dd> | |
517 | </dl> |
|
516 | </dl> | |
518 |
<p>If <code>python</code> mode is available |
|
517 | <p>If <code>python</code> mode is available, | |
519 | it will be used for highlighting blocks containing Python/IPython terminal |
|
518 | it will be used for highlighting blocks containing Python/IPython terminal | |
520 | sessions (blocks starting with <code>>>></code> (for Python) or |
|
519 | sessions (blocks starting with <code>>>></code> (for Python) or | |
521 | <code>In [num]:</code> (for IPython). |
|
520 | <code>In [num]:</code> (for IPython). | |
@@ -523,3 +522,4 b' There are some problems one commonly runs into while authoring reST documents:' | |||||
523 | <p><strong>MIME types defined:</strong> <code>text/x-rst</code>.</p> |
|
522 | <p><strong>MIME types defined:</strong> <code>text/x-rst</code>.</p> | |
524 | </body> |
|
523 | </body> | |
525 | </html> |
|
524 | </html> | |
|
525 |
@@ -73,7 +73,7 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
73 |
|
73 | |||
74 | if (i >= 3 && stream.match(/^\s*$/)) { |
|
74 | if (i >= 3 && stream.match(/^\s*$/)) { | |
75 | setNormal(state, null); |
|
75 | setNormal(state, null); | |
76 |
return ' |
|
76 | return 'header'; | |
77 | } else { |
|
77 | } else { | |
78 | stream.backUp(i + 1); |
|
78 | stream.backUp(i + 1); | |
79 | } |
|
79 | } | |
@@ -83,8 +83,7 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
83 | if (!stream.eol()) { |
|
83 | if (!stream.eol()) { | |
84 | setState(state, directive); |
|
84 | setState(state, directive); | |
85 | } |
|
85 | } | |
86 |
|
86 | return 'meta'; | ||
87 | return 'directive-marker'; |
|
|||
88 | } |
|
87 | } | |
89 |
|
88 | |||
90 | if (stream.match(reVerbatimMarker)) { |
|
89 | if (stream.match(reVerbatimMarker)) { | |
@@ -98,14 +97,13 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
98 | local: mode.startState() |
|
97 | local: mode.startState() | |
99 | }); |
|
98 | }); | |
100 | } |
|
99 | } | |
101 |
|
100 | return 'meta'; | ||
102 | return 'verbatim-marker'; |
|
|||
103 | } |
|
101 | } | |
104 |
|
102 | |||
105 | if (sol && stream.match(reExamples, false)) { |
|
103 | if (sol && stream.match(reExamples, false)) { | |
106 | if (!pythonMode) { |
|
104 | if (!pythonMode) { | |
107 | setState(state, verbatim); |
|
105 | setState(state, verbatim); | |
108 |
return ' |
|
106 | return 'meta'; | |
109 | } else { |
|
107 | } else { | |
110 | var mode = pythonMode; |
|
108 | var mode = pythonMode; | |
111 |
|
109 | |||
@@ -118,12 +116,6 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
118 | } |
|
116 | } | |
119 | } |
|
117 | } | |
120 |
|
118 | |||
121 | if (sol && (stream.match(reEnumeratedList) || |
|
|||
122 | stream.match(reBulletedList))) { |
|
|||
123 | setNormal(state, stream); |
|
|||
124 | return 'list'; |
|
|||
125 | } |
|
|||
126 |
|
||||
127 | function testBackward(re) { |
|
119 | function testBackward(re) { | |
128 | return sol || !state.ctx.back || re.test(state.ctx.back); |
|
120 | return sol || !state.ctx.back || re.test(state.ctx.back); | |
129 | } |
|
121 | } | |
@@ -153,9 +145,9 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
153 | var token; |
|
145 | var token; | |
154 |
|
146 | |||
155 | if (ch === ':') { |
|
147 | if (ch === ':') { | |
156 |
token = ' |
|
148 | token = 'builtin'; | |
157 | } else { |
|
149 | } else { | |
158 |
token = ' |
|
150 | token = 'atom'; | |
159 | } |
|
151 | } | |
160 |
|
152 | |||
161 | setState(state, inline, { |
|
153 | setState(state, inline, { | |
@@ -183,9 +175,9 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
183 | var token; |
|
175 | var token; | |
184 |
|
176 | |||
185 | if (orig === '*') { |
|
177 | if (orig === '*') { | |
186 |
token = wide ? 'strong' : 'em |
|
178 | token = wide ? 'strong' : 'em'; | |
187 | } else { |
|
179 | } else { | |
188 |
token = wide ? ' |
|
180 | token = wide ? 'string' : 'string-2'; | |
189 | } |
|
181 | } | |
190 |
|
182 | |||
191 | setState(state, inline, { |
|
183 | setState(state, inline, { | |
@@ -247,13 +239,13 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
247 | var token = null; |
|
239 | var token = null; | |
248 |
|
240 | |||
249 | if (stream.match(reDirective)) { |
|
241 | if (stream.match(reDirective)) { | |
250 |
token = ' |
|
242 | token = 'attribute'; | |
251 | } else if (stream.match(reHyperlink)) { |
|
243 | } else if (stream.match(reHyperlink)) { | |
252 |
token = ' |
|
244 | token = 'link'; | |
253 | } else if (stream.match(reFootnote)) { |
|
245 | } else if (stream.match(reFootnote)) { | |
254 |
token = ' |
|
246 | token = 'quote'; | |
255 | } else if (stream.match(reCitation)) { |
|
247 | } else if (stream.match(reCitation)) { | |
256 |
token = ' |
|
248 | token = 'quote'; | |
257 | } else { |
|
249 | } else { | |
258 | stream.eatSpace(); |
|
250 | stream.eatSpace(); | |
259 |
|
251 | |||
@@ -267,6 +259,7 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
267 | } |
|
259 | } | |
268 | } |
|
260 | } | |
269 |
|
261 | |||
|
262 | // FIXME this is unreachable | |||
270 | setState(state, body, {start: true}); |
|
263 | setState(state, body, {start: true}); | |
271 | return token; |
|
264 | return token; | |
272 | } |
|
265 | } | |
@@ -290,7 +283,7 b" CodeMirror.defineMode('rst', function(config, options) {" | |||||
290 |
|
283 | |||
291 | function verbatim(stream, state) { |
|
284 | function verbatim(stream, state) { | |
292 | if (!verbatimMode) { |
|
285 | if (!verbatimMode) { | |
293 |
return block(stream, state, ' |
|
286 | return block(stream, state, 'meta'); | |
294 | } else { |
|
287 | } else { | |
295 | if (stream.sol()) { |
|
288 | if (stream.sol()) { | |
296 | if (!stream.eatSpace()) { |
|
289 | if (!stream.eatSpace()) { |
@@ -1,16 +1,15 b'' | |||||
1 | <!doctype html> |
|
1 | <!doctype html> | |
2 | <html> |
|
2 | <html> | |
3 | <head> |
|
3 | <head> | |
4 |
<title>CodeMirror |
|
4 | <title>CodeMirror: XML mode</title> | |
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> |
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |
6 | <script src="../../lib/codemirror.js"></script> |
|
6 | <script src="../../lib/codemirror.js"></script> | |
7 | <script src="xml.js"></script> |
|
7 | <script src="xml.js"></script> | |
8 | <link rel="stylesheet" href="../../theme/default.css"> |
|
|||
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
|
8 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |
10 |
<link rel="stylesheet" href="../../c |
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |
11 | </head> |
|
10 | </head> | |
12 | <body> |
|
11 | <body> | |
13 |
<h1>CodeMirror |
|
12 | <h1>CodeMirror: XML mode</h1> | |
14 | <form><textarea id="code" name="code"> |
|
13 | <form><textarea id="code" name="code"> | |
15 | <html style="color: green"> |
|
14 | <html style="color: green"> | |
16 | <!-- this is a comment --> |
|
15 | <!-- this is a comment --> | |
@@ -24,7 +23,10 b'' | |||||
24 | </html> |
|
23 | </html> | |
25 | </textarea></form> |
|
24 | </textarea></form> | |
26 | <script> |
|
25 | <script> | |
27 |
var editor = CodeMirror.fromTextArea(document.getElementById("code"), { |
|
26 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |
|
27 | mode: {name: "xml", alignCDATA: true}, | |||
|
28 | lineNumbers: true | |||
|
29 | }); | |||
28 | </script> |
|
30 | </script> | |
29 | <p>The XML mode supports two configuration parameters:</p> |
|
31 | <p>The XML mode supports two configuration parameters:</p> | |
30 | <dl> |
|
32 | <dl> |
@@ -3,9 +3,9 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
3 | var Kludges = parserConfig.htmlMode ? { |
|
3 | var Kludges = parserConfig.htmlMode ? { | |
4 | autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true, |
|
4 | autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true, | |
5 | "meta": true, "col": true, "frame": true, "base": true, "area": true}, |
|
5 | "meta": true, "col": true, "frame": true, "base": true, "area": true}, | |
6 |
doNotIndent: {"pre": true |
|
6 | doNotIndent: {"pre": true}, | |
7 | allowUnquoted: true |
|
7 | allowUnquoted: true | |
8 |
} : {autoSelfClosers: {}, doNotIndent: { |
|
8 | } : {autoSelfClosers: {}, doNotIndent: {}, allowUnquoted: false}; | |
9 | var alignCDATA = parserConfig.alignCDATA; |
|
9 | var alignCDATA = parserConfig.alignCDATA; | |
10 |
|
10 | |||
11 | // Return variables for tokenizers |
|
11 | // Return variables for tokenizers | |
@@ -27,7 +27,7 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
27 | else if (stream.match("--")) return chain(inBlock("comment", "-->")); |
|
27 | else if (stream.match("--")) return chain(inBlock("comment", "-->")); | |
28 | else if (stream.match("DOCTYPE", true, true)) { |
|
28 | else if (stream.match("DOCTYPE", true, true)) { | |
29 | stream.eatWhile(/[\w\._\-]/); |
|
29 | stream.eatWhile(/[\w\._\-]/); | |
30 |
return chain( |
|
30 | return chain(doctype(1)); | |
31 | } |
|
31 | } | |
32 | else return null; |
|
32 | else return null; | |
33 | } |
|
33 | } | |
@@ -102,6 +102,26 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
102 | return style; |
|
102 | return style; | |
103 | }; |
|
103 | }; | |
104 | } |
|
104 | } | |
|
105 | function doctype(depth) { | |||
|
106 | return function(stream, state) { | |||
|
107 | var ch; | |||
|
108 | while ((ch = stream.next()) != null) { | |||
|
109 | if (ch == "<") { | |||
|
110 | state.tokenize = doctype(depth + 1); | |||
|
111 | return state.tokenize(stream, state); | |||
|
112 | } else if (ch == ">") { | |||
|
113 | if (depth == 1) { | |||
|
114 | state.tokenize = inText; | |||
|
115 | break; | |||
|
116 | } else { | |||
|
117 | state.tokenize = doctype(depth - 1); | |||
|
118 | return state.tokenize(stream, state); | |||
|
119 | } | |||
|
120 | } | |||
|
121 | } | |||
|
122 | return "meta"; | |||
|
123 | }; | |||
|
124 | } | |||
105 |
|
125 | |||
106 | var curState, setStyle; |
|
126 | var curState, setStyle; | |
107 | function pass() { |
|
127 | function pass() { | |
@@ -127,8 +147,10 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
127 | } |
|
147 | } | |
128 |
|
148 | |||
129 | function element(type) { |
|
149 | function element(type) { | |
130 | if (type == "openTag") {curState.tagName = tagName; return cont(attributes, endtag(curState.startOfLine));} |
|
150 | if (type == "openTag") { | |
131 | else if (type == "closeTag") { |
|
151 | curState.tagName = tagName; | |
|
152 | return cont(attributes, endtag(curState.startOfLine)); | |||
|
153 | } else if (type == "closeTag") { | |||
132 | var err = false; |
|
154 | var err = false; | |
133 | if (curState.context) { |
|
155 | if (curState.context) { | |
134 | err = curState.context.tagName != tagName; |
|
156 | err = curState.context.tagName != tagName; | |
@@ -138,12 +160,7 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
138 | if (err) setStyle = "error"; |
|
160 | if (err) setStyle = "error"; | |
139 | return cont(endclosetag(err)); |
|
161 | return cont(endclosetag(err)); | |
140 | } |
|
162 | } | |
141 | else if (type == "string") { |
|
163 | return cont(); | |
142 | if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata"); |
|
|||
143 | if (curState.tokenize == inText) popContext(); |
|
|||
144 | return cont(); |
|
|||
145 | } |
|
|||
146 | else return cont(); |
|
|||
147 | } |
|
164 | } | |
148 | function endtag(startOfLine) { |
|
165 | function endtag(startOfLine) { | |
149 | return function(type) { |
|
166 | return function(type) { | |
@@ -166,6 +183,7 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
166 | function attributes(type) { |
|
183 | function attributes(type) { | |
167 | if (type == "word") {setStyle = "attribute"; return cont(attributes);} |
|
184 | if (type == "word") {setStyle = "attribute"; return cont(attributes);} | |
168 | if (type == "equals") return cont(attvalue, attributes); |
|
185 | if (type == "equals") return cont(attvalue, attributes); | |
|
186 | if (type == "string") {setStyle = "error"; return cont(attributes);} | |||
169 | return pass(); |
|
187 | return pass(); | |
170 | } |
|
188 | } | |
171 | function attvalue(type) { |
|
189 | function attvalue(type) { | |
@@ -192,6 +210,7 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
192 |
|
210 | |||
193 | setStyle = type = tagName = null; |
|
211 | setStyle = type = tagName = null; | |
194 | var style = state.tokenize(stream, state); |
|
212 | var style = state.tokenize(stream, state); | |
|
213 | state.type = type; | |||
195 | if ((style || type) && style != "comment") { |
|
214 | if ((style || type) && style != "comment") { | |
196 | curState = state; |
|
215 | curState = state; | |
197 | while (true) { |
|
216 | while (true) { | |
@@ -203,9 +222,11 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
203 | return setStyle || style; |
|
222 | return setStyle || style; | |
204 | }, |
|
223 | }, | |
205 |
|
224 | |||
206 | indent: function(state, textAfter) { |
|
225 | indent: function(state, textAfter, fullLine) { | |
207 | var context = state.context; |
|
226 | var context = state.context; | |
208 | if (context && context.noIndent) return 0; |
|
227 | if ((state.tokenize != inTag && state.tokenize != inText) || | |
|
228 | context && context.noIndent) | |||
|
229 | return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0; | |||
209 | if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; |
|
230 | if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; | |
210 | if (context && /^<\//.test(textAfter)) |
|
231 | if (context && /^<\//.test(textAfter)) | |
211 | context = context.prev; |
|
232 | context = context.prev; | |
@@ -216,7 +237,7 b' CodeMirror.defineMode("xml", function(config, parserConfig) {' | |||||
216 | }, |
|
237 | }, | |
217 |
|
238 | |||
218 | compareStates: function(a, b) { |
|
239 | compareStates: function(a, b) { | |
219 | if (a.indented != b.indented) return false; |
|
240 | if (a.indented != b.indented || a.tokenize != b.tokenize) return false; | |
220 | for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) { |
|
241 | for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) { | |
221 | if (!ca || !cb) return ca == cb; |
|
242 | if (!ca || !cb) return ca == cb; | |
222 | if (ca.tagName != cb.tagName) return false; |
|
243 | if (ca.tagName != cb.tagName) return false; |
@@ -7,3 +7,4 b'' | |||||
7 | .cm-s-elegant span.cm-keyword {color: #730;} |
|
7 | .cm-s-elegant span.cm-keyword {color: #730;} | |
8 | .cm-s-elegant span.cm-builtin {color: #30a;} |
|
8 | .cm-s-elegant span.cm-builtin {color: #30a;} | |
9 | .cm-s-elegant span.cm-error {background-color: #fdd;} |
|
9 | .cm-s-elegant span.cm-error {background-color: #fdd;} | |
|
10 | .cm-s-elegant span.cm-link {color: #762;} |
@@ -6,3 +6,4 b'' | |||||
6 | .cm-s-neat span.cm-variable { color: black; } |
|
6 | .cm-s-neat span.cm-variable { color: black; } | |
7 | .cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; } |
|
7 | .cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; } | |
8 | .cm-s-neat span.cm-meta {color: #555;} |
|
8 | .cm-s-neat span.cm-meta {color: #555;} | |
|
9 | .cm-s-neat span.cm-link { color: #3a3; } |
@@ -18,3 +18,4 b'' | |||||
18 | .cm-s-night span.cm-bracket { color: #8da6ce; } |
|
18 | .cm-s-night span.cm-bracket { color: #8da6ce; } | |
19 | .cm-s-night span.cm-comment { color: #6900a1; } |
|
19 | .cm-s-night span.cm-comment { color: #6900a1; } | |
20 | .cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; } |
|
20 | .cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; } | |
|
21 | .cm-s-night span.cm-link { color: #845dc4; } |
@@ -137,6 +137,7 b' div#pager_splitter {' | |||||
137 | div#pager { |
|
137 | div#pager { | |
138 | padding: 15px; |
|
138 | padding: 15px; | |
139 | overflow: auto; |
|
139 | overflow: auto; | |
|
140 | display: none; | |||
140 | } |
|
141 | } | |
141 |
|
142 | |||
142 | div.cell { |
|
143 | div.cell { | |
@@ -238,10 +239,14 b' div.output_jpeg {' | |||||
238 |
|
239 | |||
239 | div.text_cell { |
|
240 | div.text_cell { | |
240 | background-color: white; |
|
241 | background-color: white; | |
|
242 | padding: 5px 5px 5px 5px; | |||
241 | } |
|
243 | } | |
242 |
|
244 | |||
243 | div.text_cell_input { |
|
245 | div.text_cell_input { | |
244 | color: black; |
|
246 | color: black; | |
|
247 | border: 1px solid #ddd; | |||
|
248 | border-radius: 3px; | |||
|
249 | background: #f7f7f7; | |||
245 | } |
|
250 | } | |
246 |
|
251 | |||
247 | div.text_cell_render { |
|
252 | div.text_cell_render { |
@@ -13,7 +13,9 b' var IPython = (function (IPython) {' | |||||
13 |
|
13 | |||
14 | var utils = IPython.utils; |
|
14 | var utils = IPython.utils; | |
15 |
|
15 | |||
|
16 | ||||
16 | var Cell = function (notebook) { |
|
17 | var Cell = function (notebook) { | |
|
18 | this.placeholder = this.placeholder || ''; | |||
17 | this.notebook = notebook; |
|
19 | this.notebook = notebook; | |
18 | this.read_only = false; |
|
20 | this.read_only = false; | |
19 | if (notebook){ |
|
21 | if (notebook){ | |
@@ -23,7 +25,6 b' var IPython = (function (IPython) {' | |||||
23 | this.element = null; |
|
25 | this.element = null; | |
24 | this.create_element(); |
|
26 | this.create_element(); | |
25 | if (this.element !== null) { |
|
27 | if (this.element !== null) { | |
26 | this.set_autoindent(true); |
|
|||
27 | this.element.data("cell", this); |
|
28 | this.element.data("cell", this); | |
28 | this.bind_events(); |
|
29 | this.bind_events(); | |
29 | } |
|
30 | } | |
@@ -31,16 +32,8 b' var IPython = (function (IPython) {' | |||||
31 | }; |
|
32 | }; | |
32 |
|
33 | |||
33 |
|
34 | |||
34 | Cell.prototype.select = function () { |
|
35 | // Subclasses must implement create_element. | |
35 | this.element.addClass('ui-widget-content ui-corner-all'); |
|
36 | Cell.prototype.create_element = function () {}; | |
36 | this.selected = true; |
|
|||
37 | }; |
|
|||
38 |
|
||||
39 |
|
||||
40 | Cell.prototype.unselect = function () { |
|
|||
41 | this.element.removeClass('ui-widget-content ui-corner-all'); |
|
|||
42 | this.selected = false; |
|
|||
43 | }; |
|
|||
44 |
|
37 | |||
45 |
|
38 | |||
46 | Cell.prototype.bind_events = function () { |
|
39 | Cell.prototype.bind_events = function () { | |
@@ -58,6 +51,80 b' var IPython = (function (IPython) {' | |||||
58 | }); |
|
51 | }); | |
59 | }; |
|
52 | }; | |
60 |
|
53 | |||
|
54 | ||||
|
55 | // typeset with MathJax if MathJax is available | |||
|
56 | Cell.prototype.typeset = function () { | |||
|
57 | if (window.MathJax){ | |||
|
58 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |||
|
59 | } | |||
|
60 | }; | |||
|
61 | ||||
|
62 | ||||
|
63 | Cell.prototype.select = function () { | |||
|
64 | this.element.addClass('ui-widget-content ui-corner-all'); | |||
|
65 | this.selected = true; | |||
|
66 | }; | |||
|
67 | ||||
|
68 | ||||
|
69 | Cell.prototype.unselect = function () { | |||
|
70 | this.element.removeClass('ui-widget-content ui-corner-all'); | |||
|
71 | this.selected = false; | |||
|
72 | }; | |||
|
73 | ||||
|
74 | ||||
|
75 | Cell.prototype.get_text = function () { | |||
|
76 | }; | |||
|
77 | ||||
|
78 | ||||
|
79 | Cell.prototype.set_text = function (text) { | |||
|
80 | }; | |||
|
81 | ||||
|
82 | ||||
|
83 | Cell.prototype.refresh = function () { | |||
|
84 | this.code_mirror.refresh(); | |||
|
85 | }; | |||
|
86 | ||||
|
87 | ||||
|
88 | Cell.prototype.edit = function () { | |||
|
89 | }; | |||
|
90 | ||||
|
91 | ||||
|
92 | Cell.prototype.render = function () { | |||
|
93 | }; | |||
|
94 | ||||
|
95 | ||||
|
96 | Cell.prototype.toJSON = function () { | |||
|
97 | }; | |||
|
98 | ||||
|
99 | ||||
|
100 | Cell.prototype.fromJSON = function (data) { | |||
|
101 | }; | |||
|
102 | ||||
|
103 | ||||
|
104 | Cell.prototype.is_splittable = function () { | |||
|
105 | return true; | |||
|
106 | }; | |||
|
107 | ||||
|
108 | ||||
|
109 | Cell.prototype.get_pre_cursor = function () { | |||
|
110 | var cursor = this.code_mirror.getCursor(); | |||
|
111 | var text = this.code_mirror.getRange({line:0,ch:0}, cursor); | |||
|
112 | text = text.replace(/^\n+/, '').replace(/\n+$/, ''); | |||
|
113 | return text; | |||
|
114 | } | |||
|
115 | ||||
|
116 | ||||
|
117 | Cell.prototype.get_post_cursor = function () { | |||
|
118 | var cursor = this.code_mirror.getCursor(); | |||
|
119 | var last_line_num = this.code_mirror.lineCount()-1; | |||
|
120 | var last_line_len = this.code_mirror.getLine(last_line_num).length; | |||
|
121 | var end = {line:last_line_num, ch:last_line_len} | |||
|
122 | var text = this.code_mirror.getRange(cursor, end); | |||
|
123 | text = text.replace(/^\n+/, '').replace(/\n+$/, ''); | |||
|
124 | return text; | |||
|
125 | }; | |||
|
126 | ||||
|
127 | ||||
61 | Cell.prototype.grow = function(element) { |
|
128 | Cell.prototype.grow = function(element) { | |
62 | // Grow the cell by hand. This is used upon reloading from JSON, when the |
|
129 | // Grow the cell by hand. This is used upon reloading from JSON, when the | |
63 | // autogrow handler is not called. |
|
130 | // autogrow handler is not called. | |
@@ -75,26 +142,6 b' var IPython = (function (IPython) {' | |||||
75 | }; |
|
142 | }; | |
76 |
|
143 | |||
77 |
|
144 | |||
78 | Cell.prototype.set_autoindent = function (state) { |
|
|||
79 | if (state) { |
|
|||
80 | this.code_mirror.setOption('tabMode', 'indent'); |
|
|||
81 | this.code_mirror.setOption('enterMode', 'indent'); |
|
|||
82 | } else { |
|
|||
83 | this.code_mirror.setOption('tabMode', 'shift'); |
|
|||
84 | this.code_mirror.setOption('enterMode', 'flat'); |
|
|||
85 | } |
|
|||
86 | }; |
|
|||
87 |
|
||||
88 | // Subclasses must implement create_element. |
|
|||
89 | Cell.prototype.create_element = function () {}; |
|
|||
90 |
|
||||
91 | // typeset with MathJax if MathJax is available |
|
|||
92 | Cell.prototype.typeset = function () { |
|
|||
93 | if (window.MathJax){ |
|
|||
94 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); |
|
|||
95 | } |
|
|||
96 | }; |
|
|||
97 |
|
||||
98 | IPython.Cell = Cell; |
|
145 | IPython.Cell = Cell; | |
99 |
|
146 | |||
100 | return IPython; |
|
147 | return IPython; |
@@ -86,13 +86,31 b' var IPython = (function (IPython) {' | |||||
86 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { |
|
86 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { | |
87 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
87 | // Always ignore shift-enter in CodeMirror as we handle it. | |
88 | return true; |
|
88 | return true; | |
89 | }else if (event.which === 40 && event.type === 'keypress' && tooltip_wait_time >= 0) { |
|
89 | } else if (event.which === 40 && event.type === 'keypress' && tooltip_wait_time >= 0) { | |
90 | // triger aon keypress (!) otherwise inconsistent event.which depending on plateform |
|
90 | // triger aon keypress (!) otherwise inconsistent event.which depending on plateform | |
91 | // browser and keyboard layout ! |
|
91 | // browser and keyboard layout ! | |
92 | // Pressing '(' , request tooltip, don't forget to reappend it |
|
92 | // Pressing '(' , request tooltip, don't forget to reappend it | |
93 | var cursor = editor.getCursor(); |
|
93 | var cursor = editor.getCursor(); | |
94 | var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'('; |
|
94 | var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'('; | |
95 | that.request_tooltip_after_time(pre_cursor,tooltip_wait_time); |
|
95 | that.request_tooltip_after_time(pre_cursor,tooltip_wait_time); | |
|
96 | } else if (event.which === 38) { | |||
|
97 | // If we are not at the top, let CM handle the up arrow and | |||
|
98 | // prevent the global keydown handler from handling it. | |||
|
99 | if (!that.at_top()) { | |||
|
100 | event.stop(); | |||
|
101 | return false; | |||
|
102 | } else { | |||
|
103 | return true; | |||
|
104 | }; | |||
|
105 | } else if (event.which === 40) { | |||
|
106 | // If we are not at the bottom, let CM handle the down arrow and | |||
|
107 | // prevent the global keydown handler from handling it. | |||
|
108 | if (!that.at_bottom()) { | |||
|
109 | event.stop(); | |||
|
110 | return false; | |||
|
111 | } else { | |||
|
112 | return true; | |||
|
113 | }; | |||
96 | } else if (event.keyCode === 9 && event.type == 'keydown') { |
|
114 | } else if (event.keyCode === 9 && event.type == 'keydown') { | |
97 | // Tab completion. |
|
115 | // Tab completion. | |
98 | var cur = editor.getCursor(); |
|
116 | var cur = editor.getCursor(); | |
@@ -499,6 +517,7 b' var IPython = (function (IPython) {' | |||||
499 | select.focus(); |
|
517 | select.focus(); | |
500 | }; |
|
518 | }; | |
501 |
|
519 | |||
|
520 | ||||
502 | CodeCell.prototype.toggle_line_numbers = function () { |
|
521 | CodeCell.prototype.toggle_line_numbers = function () { | |
503 | if (this.code_mirror.getOption('lineNumbers') == false) { |
|
522 | if (this.code_mirror.getOption('lineNumbers') == false) { | |
504 | this.code_mirror.setOption('lineNumbers', true); |
|
523 | this.code_mirror.setOption('lineNumbers', true); | |
@@ -508,15 +527,14 b' var IPython = (function (IPython) {' | |||||
508 | this.code_mirror.refresh(); |
|
527 | this.code_mirror.refresh(); | |
509 | }; |
|
528 | }; | |
510 |
|
529 | |||
|
530 | ||||
511 | CodeCell.prototype.select = function () { |
|
531 | CodeCell.prototype.select = function () { | |
512 | IPython.Cell.prototype.select.apply(this); |
|
532 | IPython.Cell.prototype.select.apply(this); | |
513 | // Todo: this dance is needed because as of CodeMirror 2.12, focus is |
|
533 | // In some cases (inserting a new cell) we need a refresh before and | |
514 | // not causing the cursor to blink if the editor is empty initially. |
|
534 | // after the focus. Not sure why this is the case. | |
515 | // While this seems to fix the issue, this should be fixed |
|
535 | this.code_mirror.refresh(); | |
516 | // in CodeMirror proper. |
|
|||
517 | var s = this.code_mirror.getValue(); |
|
|||
518 | this.code_mirror.focus(); |
|
536 | this.code_mirror.focus(); | |
519 |
|
|
537 | this.code_mirror.refresh(); | |
520 | }; |
|
538 | }; | |
521 |
|
539 | |||
522 |
|
540 | |||
@@ -754,12 +772,12 b' var IPython = (function (IPython) {' | |||||
754 | }; |
|
772 | }; | |
755 |
|
773 | |||
756 |
|
774 | |||
757 |
CodeCell.prototype.get_ |
|
775 | CodeCell.prototype.get_text = function () { | |
758 | return this.code_mirror.getValue(); |
|
776 | return this.code_mirror.getValue(); | |
759 | }; |
|
777 | }; | |
760 |
|
778 | |||
761 |
|
779 | |||
762 |
CodeCell.prototype.set_ |
|
780 | CodeCell.prototype.set_text = function (code) { | |
763 | return this.code_mirror.setValue(code); |
|
781 | return this.code_mirror.setValue(code); | |
764 | }; |
|
782 | }; | |
765 |
|
783 | |||
@@ -787,7 +805,7 b' var IPython = (function (IPython) {' | |||||
787 | CodeCell.prototype.fromJSON = function (data) { |
|
805 | CodeCell.prototype.fromJSON = function (data) { | |
788 | if (data.cell_type === 'code') { |
|
806 | if (data.cell_type === 'code') { | |
789 | if (data.input !== undefined) { |
|
807 | if (data.input !== undefined) { | |
790 |
this.set_ |
|
808 | this.set_text(data.input); | |
791 | } |
|
809 | } | |
792 | if (data.prompt_number !== undefined) { |
|
810 | if (data.prompt_number !== undefined) { | |
793 | this.set_input_prompt(data.prompt_number); |
|
811 | this.set_input_prompt(data.prompt_number); | |
@@ -809,7 +827,7 b' var IPython = (function (IPython) {' | |||||
809 |
|
827 | |||
810 | CodeCell.prototype.toJSON = function () { |
|
828 | CodeCell.prototype.toJSON = function () { | |
811 | var data = {}; |
|
829 | var data = {}; | |
812 |
data.input = this.get_ |
|
830 | data.input = this.get_text(); | |
813 | data.cell_type = 'code'; |
|
831 | data.cell_type = 'code'; | |
814 | if (this.input_prompt_number !== ' ') { |
|
832 | if (this.input_prompt_number !== ' ') { | |
815 | data.prompt_number = this.input_prompt_number; |
|
833 | data.prompt_number = this.input_prompt_number; |
@@ -49,14 +49,24 b' var IPython = (function (IPython) {' | |||||
49 |
|
49 | |||
50 |
|
50 | |||
51 | FullEditWidget.prototype.open = function () { |
|
51 | FullEditWidget.prototype.open = function () { | |
52 | var cell = IPython.notebook.selected_cell(); |
|
52 | var cell = IPython.notebook.get_selected_cell(); | |
53 |
if (!this.opened |
|
53 | if (!this.opened) { | |
54 | $('#fulledit_widget').show(); |
|
54 | $('#fulledit_widget').show(); | |
55 | $('#main_app').hide(); |
|
55 | $('#main_app').hide(); | |
56 | $('#menubar').hide(); |
|
56 | $('#menubar').hide(); | |
57 | $('body').css({overflow : 'auto'}); |
|
57 | $('body').css({overflow : 'auto'}); | |
58 |
var code = cell.get_ |
|
58 | var code = cell.get_text(); | |
59 | this.ace_editor.getSession().setValue(code); |
|
59 | this.ace_editor.getSession().setValue(code); | |
|
60 | if (cell instanceof IPython.CodeCell) { | |||
|
61 | var PythonMode = require("ace/mode/python").Mode; | |||
|
62 | this.ace_editor.getSession().setMode(new PythonMode()); | |||
|
63 | } else if (cell instanceof IPython.MarkdownCell) { | |||
|
64 | var MarkdownMode = require("ace/mode/markdown").Mode; | |||
|
65 | this.ace_editor.getSession().setMode(new MarkdownMode()); | |||
|
66 | } else if (cell instanceof IPython.HTMLCell) { | |||
|
67 | var HTMLMode = require("ace/mode/html").Mode; | |||
|
68 | this.ace_editor.getSession().setMode(new HTMLMode()); | |||
|
69 | }; | |||
60 | this.ace_editor.focus(); |
|
70 | this.ace_editor.focus(); | |
61 | // On Safari (and Chrome/FF on Linux) the editor doesn't get |
|
71 | // On Safari (and Chrome/FF on Linux) the editor doesn't get | |
62 | // focus unless there is a window resize. For now, we trigger it |
|
72 | // focus unless there is a window resize. For now, we trigger it | |
@@ -72,12 +82,22 b' var IPython = (function (IPython) {' | |||||
72 | if (this.opened) { |
|
82 | if (this.opened) { | |
73 | $('#fulledit_widget').hide(); |
|
83 | $('#fulledit_widget').hide(); | |
74 | $('#main_app').show(); |
|
84 | $('#main_app').show(); | |
|
85 | // We may need to add a refresh to all CM based cells after | |||
|
86 | // showing them. | |||
75 | $('#menubar').show(); |
|
87 | $('#menubar').show(); | |
76 | $('body').css({overflow : 'hidden'}); |
|
88 | $('body').css({overflow : 'hidden'}); | |
77 | var code = this.ace_editor.getSession().getValue(); |
|
89 | var code = this.ace_editor.getSession().getValue(); | |
78 | var cell = IPython.notebook.selected_cell(); |
|
90 | var cell = IPython.notebook.get_selected_cell(); | |
79 | cell.set_code(code); |
|
91 | if (cell instanceof IPython.CodeCell) { | |
80 |
cell. |
|
92 | cell.code_mirror.refresh(); | |
|
93 | cell.set_text(code); | |||
|
94 | } else if (cell instanceof IPython.MarkdownCell || cell instanceof IPython.HTMLCell) { | |||
|
95 | cell.edit(); | |||
|
96 | // If the cell was already in edit mode, we need to refresh/focus. | |||
|
97 | cell.code_mirror.refresh(); | |||
|
98 | cell.code_mirror.focus(); | |||
|
99 | cell.set_text(code); | |||
|
100 | }; | |||
81 | this.opened = false; |
|
101 | this.opened = false; | |
82 | }; |
|
102 | }; | |
83 | }; |
|
103 | }; |
@@ -26,7 +26,7 b' var IPython = (function (IPython) {' | |||||
26 | select : function (event, ui) { |
|
26 | select : function (event, ui) { | |
27 | // The selected cell loses focus when the menu is entered, so we |
|
27 | // The selected cell loses focus when the menu is entered, so we | |
28 | // re-select it upon selection. |
|
28 | // re-select it upon selection. | |
29 | var i = IPython.notebook.selected_index(); |
|
29 | var i = IPython.notebook.get_selected_index(); | |
30 | IPython.notebook.select(i); |
|
30 | IPython.notebook.select(i); | |
31 | } |
|
31 | } | |
32 | }); |
|
32 | }); | |
@@ -100,10 +100,10 b' var IPython = (function (IPython) {' | |||||
100 | }); |
|
100 | }); | |
101 | // Insert |
|
101 | // Insert | |
102 | this.element.find('#insert_cell_above').click(function () { |
|
102 | this.element.find('#insert_cell_above').click(function () { | |
103 |
IPython.notebook.insert_c |
|
103 | IPython.notebook.insert_cell_above('code'); | |
104 | }); |
|
104 | }); | |
105 | this.element.find('#insert_cell_below').click(function () { |
|
105 | this.element.find('#insert_cell_below').click(function () { | |
106 |
IPython.notebook.insert_c |
|
106 | IPython.notebook.insert_cell_below('code'); | |
107 | }); |
|
107 | }); | |
108 | // Cell |
|
108 | // Cell | |
109 | this.element.find('#full_edit_cell').click(function () { |
|
109 | this.element.find('#full_edit_cell').click(function () { |
This diff has been collapsed as it changes many lines, (647 lines changed) Show them Hide them | |||||
@@ -32,7 +32,6 b' var IPython = (function (IPython) {' | |||||
32 | this.set_tooltipontab(true); |
|
32 | this.set_tooltipontab(true); | |
33 | this.set_smartcompleter(true); |
|
33 | this.set_smartcompleter(true); | |
34 | this.set_timebeforetooltip(1200); |
|
34 | this.set_timebeforetooltip(1200); | |
35 | this.set_autoindent(true); |
|
|||
36 | }; |
|
35 | }; | |
37 |
|
36 | |||
38 |
|
37 | |||
@@ -47,11 +46,11 b' var IPython = (function (IPython) {' | |||||
47 | // ii) to prevent the div from scrolling up when the last cell is being |
|
46 | // ii) to prevent the div from scrolling up when the last cell is being | |
48 | // edited, but is too low on the page, which browsers will do automatically. |
|
47 | // edited, but is too low on the page, which browsers will do automatically. | |
49 | var that = this; |
|
48 | var that = this; | |
50 |
var end_space = $('<div |
|
49 | var end_space = $('<div/>').addClass('end_space').height("30%"); | |
51 | end_space.dblclick(function (e) { |
|
50 | end_space.dblclick(function (e) { | |
52 | if (that.read_only) return; |
|
51 | if (that.read_only) return; | |
53 | var ncells = that.ncells(); |
|
52 | var ncells = that.ncells(); | |
54 |
that.insert_c |
|
53 | that.insert_cell_below('code',ncells-1); | |
55 | }); |
|
54 | }); | |
56 | this.element.append(end_space); |
|
55 | this.element.append(end_space); | |
57 | $('div#notebook').addClass('border-box-sizing'); |
|
56 | $('div#notebook').addClass('border-box-sizing'); | |
@@ -69,13 +68,13 b' var IPython = (function (IPython) {' | |||||
69 | event.preventDefault(); |
|
68 | event.preventDefault(); | |
70 | } |
|
69 | } | |
71 | if (event.which === 38 && !event.shiftKey) { |
|
70 | if (event.which === 38 && !event.shiftKey) { | |
72 | var cell = that.selected_cell(); |
|
71 | var cell = that.get_selected_cell(); | |
73 | if (cell.at_top()) { |
|
72 | if (cell.at_top()) { | |
74 | event.preventDefault(); |
|
73 | event.preventDefault(); | |
75 | that.select_prev(); |
|
74 | that.select_prev(); | |
76 | }; |
|
75 | }; | |
77 | } else if (event.which === 40 && !event.shiftKey) { |
|
76 | } else if (event.which === 40 && !event.shiftKey) { | |
78 | var cell = that.selected_cell(); |
|
77 | var cell = that.get_selected_cell(); | |
79 | if (cell.at_bottom()) { |
|
78 | if (cell.at_bottom()) { | |
80 | event.preventDefault(); |
|
79 | event.preventDefault(); | |
81 | that.select_next(); |
|
80 | that.select_next(); | |
@@ -111,12 +110,12 b' var IPython = (function (IPython) {' | |||||
111 | return false; |
|
110 | return false; | |
112 | } else if (event.which === 65 && that.control_key_active) { |
|
111 | } else if (event.which === 65 && that.control_key_active) { | |
113 | // Insert code cell above selected = a |
|
112 | // Insert code cell above selected = a | |
114 |
that.insert_c |
|
113 | that.insert_cell_above('code'); | |
115 | that.control_key_active = false; |
|
114 | that.control_key_active = false; | |
116 | return false; |
|
115 | return false; | |
117 | } else if (event.which === 66 && that.control_key_active) { |
|
116 | } else if (event.which === 66 && that.control_key_active) { | |
118 | // Insert code cell below selected = b |
|
117 | // Insert code cell below selected = b | |
119 |
that.insert_c |
|
118 | that.insert_cell_below('code'); | |
120 | that.control_key_active = false; |
|
119 | that.control_key_active = false; | |
121 | return false; |
|
120 | return false; | |
122 | } else if (event.which === 89 && that.control_key_active) { |
|
121 | } else if (event.which === 89 && that.control_key_active) { | |
@@ -234,29 +233,67 b' var IPython = (function (IPython) {' | |||||
234 |
|
233 | |||
235 | // Cell indexing, retrieval, etc. |
|
234 | // Cell indexing, retrieval, etc. | |
236 |
|
235 | |||
237 |
|
236 | Notebook.prototype.get_cell_elements = function () { | ||
238 | Notebook.prototype.cell_elements = function () { |
|
|||
239 | return this.element.children("div.cell"); |
|
237 | return this.element.children("div.cell"); | |
240 | }; |
|
238 | }; | |
241 |
|
239 | |||
242 |
|
240 | |||
|
241 | Notebook.prototype.get_cell_element = function (index) { | |||
|
242 | var result = null; | |||
|
243 | var e = this.get_cell_elements().eq(index); | |||
|
244 | if (e.length !== 0) { | |||
|
245 | result = e; | |||
|
246 | } | |||
|
247 | return result; | |||
|
248 | }; | |||
|
249 | ||||
|
250 | ||||
243 | Notebook.prototype.ncells = function (cell) { |
|
251 | Notebook.prototype.ncells = function (cell) { | |
244 | return this.cell_elements().length; |
|
252 | return this.get_cell_elements().length; | |
245 | }; |
|
253 | }; | |
246 |
|
254 | |||
247 |
|
255 | |||
248 | // TODO: we are often calling cells as cells()[i], which we should optimize |
|
256 | // TODO: we are often calling cells as cells()[i], which we should optimize | |
249 | // to cells(i) or a new method. |
|
257 | // to cells(i) or a new method. | |
250 | Notebook.prototype.cells = function () { |
|
258 | Notebook.prototype.get_cells = function () { | |
251 | return this.cell_elements().toArray().map(function (e) { |
|
259 | return this.get_cell_elements().toArray().map(function (e) { | |
252 | return $(e).data("cell"); |
|
260 | return $(e).data("cell"); | |
253 | }); |
|
261 | }); | |
254 | }; |
|
262 | }; | |
255 |
|
263 | |||
256 |
|
264 | |||
|
265 | Notebook.prototype.get_cell = function (index) { | |||
|
266 | var result = null; | |||
|
267 | var ce = this.get_cell_element(index); | |||
|
268 | if (ce !== null) { | |||
|
269 | result = ce.data('cell'); | |||
|
270 | } | |||
|
271 | return result; | |||
|
272 | } | |||
|
273 | ||||
|
274 | ||||
|
275 | Notebook.prototype.get_next_cell = function (cell) { | |||
|
276 | var result = null; | |||
|
277 | var index = this.find_cell_index(cell); | |||
|
278 | if (index !== null && index < this.ncells()) { | |||
|
279 | result = this.get_cell(index+1); | |||
|
280 | } | |||
|
281 | return result; | |||
|
282 | } | |||
|
283 | ||||
|
284 | ||||
|
285 | Notebook.prototype.get_prev_cell = function (cell) { | |||
|
286 | var result = null; | |||
|
287 | var index = this.find_cell_index(cell); | |||
|
288 | if (index !== null && index > 1) { | |||
|
289 | result = this.get_cell(index-1); | |||
|
290 | } | |||
|
291 | return result; | |||
|
292 | } | |||
|
293 | ||||
257 | Notebook.prototype.find_cell_index = function (cell) { |
|
294 | Notebook.prototype.find_cell_index = function (cell) { | |
258 | var result = null; |
|
295 | var result = null; | |
259 | this.cell_elements().filter(function (index) { |
|
296 | this.get_cell_elements().filter(function (index) { | |
260 | if ($(this).data("cell") === cell) { |
|
297 | if ($(this).data("cell") === cell) { | |
261 | result = index; |
|
298 | result = index; | |
262 | }; |
|
299 | }; | |
@@ -267,8 +304,8 b' var IPython = (function (IPython) {' | |||||
267 |
|
304 | |||
268 | Notebook.prototype.index_or_selected = function (index) { |
|
305 | Notebook.prototype.index_or_selected = function (index) { | |
269 | var i; |
|
306 | var i; | |
270 | if (index === undefined) { |
|
307 | if (index === undefined || index === null) { | |
271 | i = this.selected_index(); |
|
308 | i = this.get_selected_index(); | |
272 | if (i === null) { |
|
309 | if (i === null) { | |
273 | i = 0; |
|
310 | i = 0; | |
274 | } |
|
311 | } | |
@@ -279,38 +316,23 b' var IPython = (function (IPython) {' | |||||
279 | }; |
|
316 | }; | |
280 |
|
317 | |||
281 |
|
318 | |||
282 |
Notebook.prototype.select = function ( |
|
319 | Notebook.prototype.get_selected_cell = function () { | |
283 | if (index !== undefined && index >= 0 && index < this.ncells()) { |
|
320 | var index = this.get_selected_index(); | |
284 | if (this.selected_index() !== null) { |
|
321 | return this.get_cell(index); | |
285 | this.selected_cell().unselect(); |
|
|||
286 | }; |
|
|||
287 | this.cells()[index].select(); |
|
|||
288 | }; |
|
|||
289 | return this; |
|
|||
290 | }; |
|
|||
291 |
|
||||
292 |
|
||||
293 | Notebook.prototype.select_next = function () { |
|
|||
294 | var index = this.selected_index(); |
|
|||
295 | if (index !== null && index >= 0 && (index+1) < this.ncells()) { |
|
|||
296 | this.select(index+1); |
|
|||
297 | }; |
|
|||
298 | return this; |
|
|||
299 | }; |
|
322 | }; | |
300 |
|
323 | |||
301 |
|
324 | |||
302 |
Notebook.prototype. |
|
325 | Notebook.prototype.is_valid_cell_index = function (index) { | |
303 | var index = this.selected_index(); |
|
326 | if (index !== null && index >= 0 && index < this.ncells()) { | |
304 | if (index !== null && index >= 0 && (index-1) < this.ncells()) { |
|
327 | return true; | |
305 | this.select(index-1); |
|
328 | } else { | |
|
329 | return false; | |||
306 | }; |
|
330 | }; | |
307 | return this; |
|
331 | } | |
308 | }; |
|
|||
309 |
|
||||
310 |
|
332 | |||
311 | Notebook.prototype.selected_index = function () { |
|
333 | Notebook.prototype.get_selected_index = function () { | |
312 | var result = null; |
|
334 | var result = null; | |
313 | this.cell_elements().filter(function (index) { |
|
335 | this.get_cell_elements().filter(function (index) { | |
314 | if ($(this).data("cell").selected === true) { |
|
336 | if ($(this).data("cell").selected === true) { | |
315 | result = index; |
|
337 | result = index; | |
316 | }; |
|
338 | }; | |
@@ -322,7 +344,7 b' var IPython = (function (IPython) {' | |||||
322 | Notebook.prototype.cell_for_msg = function (msg_id) { |
|
344 | Notebook.prototype.cell_for_msg = function (msg_id) { | |
323 | var cell_id = this.msg_cell_map[msg_id]; |
|
345 | var cell_id = this.msg_cell_map[msg_id]; | |
324 | var result = null; |
|
346 | var result = null; | |
325 | this.cell_elements().filter(function (index) { |
|
347 | this.get_cell_elements().filter(function (index) { | |
326 | cell = $(this).data("cell"); |
|
348 | cell = $(this).data("cell"); | |
327 | if (cell.cell_id === cell_id) { |
|
349 | if (cell.cell_id === cell_id) { | |
328 | result = cell; |
|
350 | result = cell; | |
@@ -332,68 +354,45 b' var IPython = (function (IPython) {' | |||||
332 | }; |
|
354 | }; | |
333 |
|
355 | |||
334 |
|
356 | |||
335 | Notebook.prototype.selected_cell = function () { |
|
357 | // Cell selection. | |
336 | return this.cell_elements().eq(this.selected_index()).data("cell"); |
|
|||
337 | }; |
|
|||
338 |
|
358 | |||
339 |
|
359 | Notebook.prototype.select = function (index) { | ||
340 | // Cell insertion, deletion and moving. |
|
360 | if (index !== undefined && index >= 0 && index < this.ncells()) { | |
341 |
|
361 | sindex = this.get_selected_index() | ||
342 | Notebook.prototype.delete_cell = function (index) { |
|
362 | if (sindex !== null && index !== sindex) { | |
343 |
|
|
363 | this.get_cell(sindex).unselect(); | |
344 | if (i !== null && i >= 0 && i < this.ncells()) { |
|
|||
345 | this.cell_elements().eq(i).remove(); |
|
|||
346 | if (i === (this.ncells())) { |
|
|||
347 | this.select(i-1); |
|
|||
348 | } else { |
|
|||
349 | this.select(i); |
|
|||
350 | }; |
|
364 | }; | |
|
365 | this.get_cell(index).select(); | |||
351 | }; |
|
366 | }; | |
352 | this.dirty = true; |
|
|||
353 | return this; |
|
367 | return this; | |
354 | }; |
|
368 | }; | |
355 |
|
369 | |||
356 |
|
370 | |||
357 |
Notebook.prototype. |
|
371 | Notebook.prototype.select_next = function () { | |
358 | this.element.find('div.end_space').before(cell.element); |
|
372 | var index = this.get_selected_index(); | |
359 | this.dirty = true; |
|
373 | if (index !== null && index >= 0 && (index+1) < this.ncells()) { | |
360 | return this; |
|
374 | this.select(index+1); | |
361 | }; |
|
|||
362 |
|
||||
363 |
|
||||
364 | Notebook.prototype.insert_cell_below = function (cell, index) { |
|
|||
365 | var ncells = this.ncells(); |
|
|||
366 | if (ncells === 0) { |
|
|||
367 | this.append_cell(cell); |
|
|||
368 | return this; |
|
|||
369 | }; |
|
|||
370 | if (index >= 0 && index < ncells) { |
|
|||
371 | this.cell_elements().eq(index).after(cell.element); |
|
|||
372 | }; |
|
375 | }; | |
373 | this.dirty = true; |
|
|||
374 | return this; |
|
376 | return this; | |
375 | }; |
|
377 | }; | |
376 |
|
378 | |||
377 |
|
379 | |||
378 |
Notebook.prototype. |
|
380 | Notebook.prototype.select_prev = function () { | |
379 |
var |
|
381 | var index = this.get_selected_index(); | |
380 | if (ncells === 0) { |
|
382 | if (index !== null && index >= 0 && (index-1) < this.ncells()) { | |
381 |
this. |
|
383 | this.select(index-1); | |
382 | return this; |
|
|||
383 | }; |
|
|||
384 | if (index >= 0 && index < ncells) { |
|
|||
385 | this.cell_elements().eq(index).before(cell.element); |
|
|||
386 | }; |
|
384 | }; | |
387 | this.dirty = true; |
|
|||
388 | return this; |
|
385 | return this; | |
389 | }; |
|
386 | }; | |
390 |
|
387 | |||
391 |
|
388 | |||
|
389 | // Cell movement | |||
|
390 | ||||
392 | Notebook.prototype.move_cell_up = function (index) { |
|
391 | Notebook.prototype.move_cell_up = function (index) { | |
393 |
var i = |
|
392 | var i = this.index_or_selected(); | |
394 | if (i !== null && i < this.ncells() && i > 0) { |
|
393 | if (i !== null && i < this.ncells() && i > 0) { | |
395 |
var pivot = this.cell_element |
|
394 | var pivot = this.get_cell_element(i-1); | |
396 |
var tomove = this.cell_element |
|
395 | var tomove = this.get_cell_element(i); | |
397 | if (pivot !== null && tomove !== null) { |
|
396 | if (pivot !== null && tomove !== null) { | |
398 | tomove.detach(); |
|
397 | tomove.detach(); | |
399 | pivot.before(tomove); |
|
398 | pivot.before(tomove); | |
@@ -406,10 +405,10 b' var IPython = (function (IPython) {' | |||||
406 |
|
405 | |||
407 |
|
406 | |||
408 | Notebook.prototype.move_cell_down = function (index) { |
|
407 | Notebook.prototype.move_cell_down = function (index) { | |
409 |
var i = |
|
408 | var i = this.index_or_selected(); | |
410 | if (i !== null && i < (this.ncells()-1) && i >= 0) { |
|
409 | if (i !== null && i < (this.ncells()-1) && i >= 0) { | |
411 |
var pivot = this.cell_element |
|
410 | var pivot = this.get_cell_element(i+1); | |
412 |
var tomove = this.cell_element |
|
411 | var tomove = this.get_cell_element(i); | |
413 | if (pivot !== null && tomove !== null) { |
|
412 | if (pivot !== null && tomove !== null) { | |
414 | tomove.detach(); |
|
413 | tomove.detach(); | |
415 | pivot.after(tomove); |
|
414 | pivot.after(tomove); | |
@@ -422,14 +421,16 b' var IPython = (function (IPython) {' | |||||
422 |
|
421 | |||
423 |
|
422 | |||
424 | Notebook.prototype.sort_cells = function () { |
|
423 | Notebook.prototype.sort_cells = function () { | |
|
424 | // This is not working right now. Calling this will actually crash | |||
|
425 | // the browser. I think there is an infinite loop in here... | |||
425 | var ncells = this.ncells(); |
|
426 | var ncells = this.ncells(); | |
426 | var sindex = this.selected_index(); |
|
427 | var sindex = this.get_selected_index(); | |
427 | var swapped; |
|
428 | var swapped; | |
428 | do { |
|
429 | do { | |
429 | swapped = false; |
|
430 | swapped = false; | |
430 | for (var i=1; i<ncells; i++) { |
|
431 | for (var i=1; i<ncells; i++) { | |
431 |
current = this. |
|
432 | current = this.get_cell(i); | |
432 |
previous = this. |
|
433 | previous = this.get_cell(i-1); | |
433 | if (previous.input_prompt_number > current.input_prompt_number) { |
|
434 | if (previous.input_prompt_number > current.input_prompt_number) { | |
434 | this.move_cell_up(i); |
|
435 | this.move_cell_up(i); | |
435 | swapped = true; |
|
436 | swapped = true; | |
@@ -440,147 +441,150 b' var IPython = (function (IPython) {' | |||||
440 | return this; |
|
441 | return this; | |
441 | }; |
|
442 | }; | |
442 |
|
443 | |||
|
444 | // Insertion, deletion. | |||
443 |
|
445 | |||
444 |
Notebook.prototype. |
|
446 | Notebook.prototype.delete_cell = function (index) { | |
445 | // TODO: Bounds check for i |
|
|||
446 | var i = this.index_or_selected(index); |
|
|||
447 | var cell = new IPython.CodeCell(this); |
|
|||
448 | cell.set_input_prompt(); |
|
|||
449 | this.insert_cell_above(cell, i); |
|
|||
450 | this.select(this.find_cell_index(cell)); |
|
|||
451 | return cell; |
|
|||
452 | }; |
|
|||
453 |
|
||||
454 |
|
||||
455 | Notebook.prototype.insert_code_cell_below = function (index) { |
|
|||
456 | // TODO: Bounds check for i |
|
|||
457 | var i = this.index_or_selected(index); |
|
|||
458 | var cell = new IPython.CodeCell(this); |
|
|||
459 | cell.set_input_prompt(); |
|
|||
460 | this.insert_cell_below(cell, i); |
|
|||
461 | this.select(this.find_cell_index(cell)); |
|
|||
462 | return cell; |
|
|||
463 | }; |
|
|||
464 |
|
||||
465 |
|
||||
466 | Notebook.prototype.insert_html_cell_above = function (index) { |
|
|||
467 | // TODO: Bounds check for i |
|
|||
468 | var i = this.index_or_selected(index); |
|
|||
469 | var cell = new IPython.HTMLCell(this); |
|
|||
470 | cell.config_mathjax(); |
|
|||
471 | this.insert_cell_above(cell, i); |
|
|||
472 | this.select(this.find_cell_index(cell)); |
|
|||
473 | return cell; |
|
|||
474 | }; |
|
|||
475 |
|
||||
476 |
|
||||
477 | Notebook.prototype.insert_html_cell_below = function (index) { |
|
|||
478 | // TODO: Bounds check for i |
|
|||
479 | var i = this.index_or_selected(index); |
|
447 | var i = this.index_or_selected(index); | |
480 | var cell = new IPython.HTMLCell(this); |
|
448 | if (this.is_valid_cell_index(i)) { | |
481 | cell.config_mathjax(); |
|
449 | var ce = this.get_cell_element(i); | |
482 | this.insert_cell_below(cell, i); |
|
450 | ce.remove(); | |
483 | this.select(this.find_cell_index(cell)); |
|
451 | if (i === (this.ncells())) { | |
484 | return cell; |
|
452 | this.select(i-1); | |
|
453 | } else { | |||
|
454 | this.select(i); | |||
|
455 | }; | |||
|
456 | this.dirty = true; | |||
|
457 | }; | |||
|
458 | return this; | |||
485 | }; |
|
459 | }; | |
486 |
|
460 | |||
487 |
|
461 | |||
488 |
Notebook.prototype.insert_ |
|
462 | Notebook.prototype.insert_cell_below = function (type, index) { | |
489 | // TODO: Bounds check for i |
|
463 | // type = ('code','html','markdown') | |
490 | var i = this.index_or_selected(index); |
|
464 | // index = cell index or undefined to insert below selected | |
491 | var cell = new IPython.MarkdownCell(this); |
|
465 | index = this.index_or_selected(index); | |
492 | cell.config_mathjax(); |
|
466 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { | |
493 | this.insert_cell_above(cell, i); |
|
467 | var cell = null; | |
494 | this.select(this.find_cell_index(cell)); |
|
468 | if (type === 'code') { | |
495 | return cell; |
|
469 | var cell = new IPython.CodeCell(this); | |
|
470 | cell.set_input_prompt(); | |||
|
471 | } else if (type === 'markdown') { | |||
|
472 | var cell = new IPython.MarkdownCell(this); | |||
|
473 | } else if (type === 'html') { | |||
|
474 | var cell = new IPython.HTMLCell(this); | |||
|
475 | }; | |||
|
476 | if (cell !== null) { | |||
|
477 | if (this.ncells() === 0) { | |||
|
478 | this.element.find('div.end_space').before(cell.element); | |||
|
479 | } else if (this.is_valid_cell_index(index)) { | |||
|
480 | this.get_cell_element(index).after(cell.element); | |||
|
481 | }; | |||
|
482 | cell.render(); | |||
|
483 | this.select(this.find_cell_index(cell)); | |||
|
484 | this.dirty = true; | |||
|
485 | return cell; | |||
|
486 | }; | |||
|
487 | }; | |||
496 | }; |
|
488 | }; | |
497 |
|
489 | |||
498 |
|
490 | |||
499 |
Notebook.prototype.insert_ |
|
491 | Notebook.prototype.insert_cell_above = function (type, index) { | |
500 | // TODO: Bounds check for i |
|
492 | // type = ('code','html','markdown') | |
501 | var i = this.index_or_selected(index); |
|
493 | // index = cell index or undefined to insert above selected | |
502 | var cell = new IPython.MarkdownCell(this); |
|
494 | index = this.index_or_selected(index); | |
503 | cell.config_mathjax(); |
|
495 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { | |
504 | this.insert_cell_below(cell, i); |
|
496 | var cell = null; | |
505 | this.select(this.find_cell_index(cell)); |
|
497 | if (type === 'code') { | |
506 | return cell; |
|
498 | var cell = new IPython.CodeCell(this); | |
|
499 | cell.set_input_prompt(); | |||
|
500 | } else if (type === 'markdown') { | |||
|
501 | var cell = new IPython.MarkdownCell(this); | |||
|
502 | } else if (type === 'html') { | |||
|
503 | var cell = new IPython.HTMLCell(this); | |||
|
504 | }; | |||
|
505 | if (cell !== null) { | |||
|
506 | if (this.ncells() === 0) { | |||
|
507 | this.element.find('div.end_space').before(cell.element); | |||
|
508 | } else if (this.is_valid_cell_index(index)) { | |||
|
509 | this.get_cell_element(index).before(cell.element); | |||
|
510 | }; | |||
|
511 | cell.render(); | |||
|
512 | this.select(this.find_cell_index(cell)); | |||
|
513 | this.dirty = true; | |||
|
514 | return cell; | |||
|
515 | }; | |||
|
516 | }; | |||
507 | }; |
|
517 | }; | |
508 |
|
518 | |||
509 |
|
519 | |||
510 | Notebook.prototype.to_code = function (index) { |
|
520 | Notebook.prototype.to_code = function (index) { | |
511 | // TODO: Bounds check for i |
|
|||
512 | var i = this.index_or_selected(index); |
|
521 | var i = this.index_or_selected(index); | |
513 | var source_element = this.cell_elements().eq(i); |
|
522 | if (this.is_valid_cell_index(i)) { | |
514 |
var source_ |
|
523 | var source_element = this.get_cell_element(i); | |
515 | if (source_cell instanceof IPython.HTMLCell || |
|
524 | var source_cell = source_element.data("cell"); | |
516 |
source_cell instanceof IPython. |
|
525 | if (!(source_cell instanceof IPython.CodeCell)) { | |
517 |
this.insert_c |
|
526 | target_cell = this.insert_cell_below('code',i); | |
518 | var target_cell = this.cells()[i+1]; |
|
527 | var text = source_cell.get_text(); | |
519 | target_cell.set_code(source_cell.get_source()); |
|
528 | if (text === source_cell.placeholder) { | |
520 | source_element.remove(); |
|
529 | text = ''; | |
521 | target_cell.select(); |
|
530 | } | |
|
531 | target_cell.set_text(text); | |||
|
532 | source_element.remove(); | |||
|
533 | }; | |||
|
534 | this.dirty = true; | |||
522 | }; |
|
535 | }; | |
523 | this.dirty = true; |
|
|||
524 | }; |
|
536 | }; | |
525 |
|
537 | |||
526 |
|
538 | |||
527 | Notebook.prototype.to_markdown = function (index) { |
|
539 | Notebook.prototype.to_markdown = function (index) { | |
528 | // TODO: Bounds check for i |
|
|||
529 | var i = this.index_or_selected(index); |
|
540 | var i = this.index_or_selected(index); | |
530 | var source_element = this.cell_elements().eq(i); |
|
541 | if (this.is_valid_cell_index(i)) { | |
531 |
var source_ |
|
542 | var source_element = this.get_cell_element(i); | |
532 | var target_cell = null; |
|
543 | var source_cell = source_element.data("cell"); | |
533 | if (source_cell instanceof IPython.CodeCell) { |
|
544 | var target_cell = null; | |
534 | this.insert_markdown_cell_below(i); |
|
545 | if (!(source_cell instanceof IPython.MarkdownCell)) { | |
535 |
target_cell = this. |
|
546 | target_cell = this.insert_cell_below('markdown',i); | |
536 |
var text = source_cell.get_ |
|
547 | var text = source_cell.get_text(); | |
537 | } else if (source_cell instanceof IPython.HTMLCell) { |
|
548 | if (text === source_cell.placeholder) { | |
538 | this.insert_markdown_cell_below(i); |
|
549 | text = ''; | |
539 | target_cell = this.cells()[i+1]; |
|
550 | }; | |
540 | var text = source_cell.get_source(); |
|
551 | if (target_cell !== null) { | |
541 | if (text === source_cell.placeholder) { |
|
552 | // The edit must come before the set_text. | |
542 |
|
|
553 | target_cell.edit(); | |
543 | } |
|
554 | target_cell.set_text(text); | |
544 | } |
|
555 | source_element.remove(); | |
545 | if (target_cell !== null) { |
|
556 | } | |
546 | if (text === "") {text = target_cell.placeholder;}; |
|
557 | this.dirty = true; | |
547 | target_cell.set_source(text); |
|
558 | }; | |
548 | source_element.remove(); |
|
559 | }; | |
549 | target_cell.edit(); |
|
|||
550 | } |
|
|||
551 | this.dirty = true; |
|
|||
552 | }; |
|
560 | }; | |
553 |
|
561 | |||
554 |
|
562 | |||
555 | Notebook.prototype.to_html = function (index) { |
|
563 | Notebook.prototype.to_html = function (index) { | |
556 | // TODO: Bounds check for i |
|
|||
557 | var i = this.index_or_selected(index); |
|
564 | var i = this.index_or_selected(index); | |
558 | var source_element = this.cell_elements().eq(i); |
|
565 | if (this.is_valid_cell_index(i)) { | |
559 |
var source_ |
|
566 | var source_element = this.get_cell_element(i); | |
560 | var target_cell = null; |
|
567 | var source_cell = source_element.data("cell"); | |
561 | if (source_cell instanceof IPython.CodeCell) { |
|
568 | var target_cell = null; | |
562 | this.insert_html_cell_below(i); |
|
569 | if (!(source_cell instanceof IPython.HTMLCell)) { | |
563 |
target_cell = this. |
|
570 | target_cell = this.insert_cell_below('html',i); | |
564 |
var text = source_cell.get_ |
|
571 | var text = source_cell.get_text(); | |
565 | } else if (source_cell instanceof IPython.MarkdownCell) { |
|
572 | if (text === source_cell.placeholder) { | |
566 | this.insert_html_cell_below(i); |
|
573 | text = ''; | |
567 | target_cell = this.cells()[i+1]; |
|
574 | }; | |
568 | var text = source_cell.get_source(); |
|
575 | if (target_cell !== null) { | |
569 | if (text === source_cell.placeholder) { |
|
576 | // The edit must come before the set_text. | |
570 |
|
|
577 | target_cell.edit(); | |
571 | } |
|
578 | target_cell.set_text(text); | |
572 | } |
|
579 | source_element.remove(); | |
573 | if (target_cell !== null) { |
|
580 | } | |
574 | if (text === "") {text = target_cell.placeholder;}; |
|
581 | this.dirty = true; | |
575 | target_cell.set_source(text); |
|
582 | }; | |
576 | source_element.remove(); |
|
583 | }; | |
577 | target_cell.edit(); |
|
|||
578 | } |
|
|||
579 | this.dirty = true; |
|
|||
580 | }; |
|
584 | }; | |
581 |
|
585 | |||
582 |
|
586 | |||
583 |
// Copy/Paste |
|
587 | // Cut/Copy/Paste | |
584 |
|
588 | |||
585 | Notebook.prototype.enable_paste = function () { |
|
589 | Notebook.prototype.enable_paste = function () { | |
586 | var that = this; |
|
590 | var that = this; | |
@@ -612,7 +616,7 b' var IPython = (function (IPython) {' | |||||
612 | } |
|
616 | } | |
613 |
|
617 | |||
614 | Notebook.prototype.copy_cell = function () { |
|
618 | Notebook.prototype.copy_cell = function () { | |
615 | var cell = this.selected_cell(); |
|
619 | var cell = this.get_selected_cell(); | |
616 | this.clipboard = cell.toJSON(); |
|
620 | this.clipboard = cell.toJSON(); | |
617 | this.enable_paste(); |
|
621 | this.enable_paste(); | |
618 | }; |
|
622 | }; | |
@@ -621,18 +625,11 b' var IPython = (function (IPython) {' | |||||
621 | Notebook.prototype.paste_cell = function () { |
|
625 | Notebook.prototype.paste_cell = function () { | |
622 | if (this.clipboard !== null && this.paste_enabled) { |
|
626 | if (this.clipboard !== null && this.paste_enabled) { | |
623 | var cell_data = this.clipboard; |
|
627 | var cell_data = this.clipboard; | |
624 | if (cell_data.cell_type == 'code') { |
|
628 | var new_cell = this.insert_cell_above(cell_data.cell_type); | |
625 |
|
|
629 | new_cell.fromJSON(cell_data); | |
626 | new_cell.fromJSON(cell_data); |
|
630 | old_cell = this.get_next_cell(new_cell); | |
627 | } else if (cell_data.cell_type === 'html') { |
|
631 | this.delete_cell(this.find_cell_index(old_cell)); | |
628 | new_cell = this.insert_html_cell_above(); |
|
632 | this.select(this.find_cell_index(new_cell)); | |
629 | new_cell.fromJSON(cell_data); |
|
|||
630 | } else if (cell_data.cell_type === 'markdown') { |
|
|||
631 | new_cell = this.insert_markdown_cell_above(); |
|
|||
632 | new_cell.fromJSON(cell_data); |
|
|||
633 | }; |
|
|||
634 | this.select_next(); |
|
|||
635 | this.delete_cell(); |
|
|||
636 | }; |
|
633 | }; | |
637 | }; |
|
634 | }; | |
638 |
|
635 | |||
@@ -640,16 +637,8 b' var IPython = (function (IPython) {' | |||||
640 | Notebook.prototype.paste_cell_above = function () { |
|
637 | Notebook.prototype.paste_cell_above = function () { | |
641 | if (this.clipboard !== null && this.paste_enabled) { |
|
638 | if (this.clipboard !== null && this.paste_enabled) { | |
642 | var cell_data = this.clipboard; |
|
639 | var cell_data = this.clipboard; | |
643 | if (cell_data.cell_type == 'code') { |
|
640 | var new_cell = this.insert_cell_above(cell_data.cell_type); | |
644 |
|
|
641 | new_cell.fromJSON(cell_data); | |
645 | new_cell.fromJSON(cell_data); |
|
|||
646 | } else if (cell_data.cell_type === 'html') { |
|
|||
647 | new_cell = this.insert_html_cell_above(); |
|
|||
648 | new_cell.fromJSON(cell_data); |
|
|||
649 | } else if (cell_data.cell_type === 'markdown') { |
|
|||
650 | new_cell = this.insert_markdown_cell_above(); |
|
|||
651 | new_cell.fromJSON(cell_data); |
|
|||
652 | }; |
|
|||
653 | }; |
|
642 | }; | |
654 | }; |
|
643 | }; | |
655 |
|
644 | |||
@@ -657,91 +646,102 b' var IPython = (function (IPython) {' | |||||
657 | Notebook.prototype.paste_cell_below = function () { |
|
646 | Notebook.prototype.paste_cell_below = function () { | |
658 | if (this.clipboard !== null && this.paste_enabled) { |
|
647 | if (this.clipboard !== null && this.paste_enabled) { | |
659 | var cell_data = this.clipboard; |
|
648 | var cell_data = this.clipboard; | |
660 | if (cell_data.cell_type == 'code') { |
|
649 | var new_cell = this.insert_cell_below(cell_data.cell_type); | |
661 |
|
|
650 | new_cell.fromJSON(cell_data); | |
662 | new_cell.fromJSON(cell_data); |
|
|||
663 | } else if (cell_data.cell_type === 'html') { |
|
|||
664 | new_cell = this.insert_html_cell_below(); |
|
|||
665 | new_cell.fromJSON(cell_data); |
|
|||
666 | } else if (cell_data.cell_type === 'markdown') { |
|
|||
667 | new_cell = this.insert_markdown_cell_below(); |
|
|||
668 | new_cell.fromJSON(cell_data); |
|
|||
669 | }; |
|
|||
670 | }; |
|
651 | }; | |
671 | }; |
|
652 | }; | |
672 |
|
653 | |||
673 |
|
654 | |||
|
655 | // Split/merge | |||
|
656 | ||||
674 | Notebook.prototype.split_cell = function () { |
|
657 | Notebook.prototype.split_cell = function () { | |
675 | // Todo: implement spliting for other cell types. |
|
658 | // Todo: implement spliting for other cell types. | |
676 | var cell = this.selected_cell(); |
|
659 | var cell = this.get_selected_cell(); | |
677 | if (cell instanceof IPython.CodeCell) { |
|
660 | if (cell.is_splittable()) { | |
678 |
|
|
661 | texta = cell.get_pre_cursor(); | |
679 | var last_line_num = cell.code_mirror.lineCount()-1; |
|
662 | textb = cell.get_post_cursor(); | |
680 | var last_line_len = cell.code_mirror.getLine(last_line_num).length; |
|
663 | if (cell instanceof IPython.CodeCell) { | |
681 | var end = {line:last_line_num, ch:last_line_len} |
|
664 | cell.set_text(texta); | |
682 | var texta = cell.code_mirror.getRange({line:0,ch:0}, cursor); |
|
665 | var new_cell = this.insert_cell_below('code'); | |
683 | var textb = cell.code_mirror.getRange(cursor, end); |
|
666 | new_cell.set_text(textb); | |
684 | texta = texta.replace(/^\n+/, '').replace(/\n+$/, ''); |
|
667 | } else if (cell instanceof IPython.MarkdownCell) { | |
685 | textb = textb.replace(/^\n+/, '').replace(/\n+$/, ''); |
|
668 | cell.set_text(texta); | |
686 |
cell. |
|
669 | cell.render(); | |
687 |
var new_cell = this.insert_c |
|
670 | var new_cell = this.insert_cell_below('markdown'); | |
688 | new_cell.set_code(textb); |
|
671 | new_cell.edit(); // editor must be visible to call set_text | |
|
672 | new_cell.set_text(textb); | |||
|
673 | new_cell.render(); | |||
|
674 | } else if (cell instanceof IPython.HTMLCell) { | |||
|
675 | cell.set_text(texta); | |||
|
676 | cell.render(); | |||
|
677 | var new_cell = this.insert_cell_below('html'); | |||
|
678 | new_cell.edit(); // editor must be visible to call set_text | |||
|
679 | new_cell.set_text(textb); | |||
|
680 | new_cell.render(); | |||
|
681 | }; | |||
689 | }; |
|
682 | }; | |
690 | }; |
|
683 | }; | |
691 |
|
684 | |||
692 |
|
685 | |||
693 | Notebook.prototype.merge_cell_above = function () { |
|
686 | Notebook.prototype.merge_cell_above = function () { | |
694 | // Todo: implement merging for other cell types. |
|
687 | var index = this.get_selected_index(); | |
695 |
var cell = this. |
|
688 | var cell = this.get_cell(index); | |
696 | var index = this.selected_index(); |
|
|||
697 | if (index > 0) { |
|
689 | if (index > 0) { | |
698 |
upper_cell = this.cell |
|
690 | upper_cell = this.get_cell(index-1); | |
699 | lower_cell = this.cells()[index]; |
|
691 | upper_text = upper_cell.get_text(); | |
700 | if (upper_cell instanceof IPython.CodeCell && lower_cell instanceof IPython.CodeCell) { |
|
692 | text = cell.get_text(); | |
701 | upper_text = upper_cell.get_code(); |
|
693 | if (cell instanceof IPython.CodeCell) { | |
702 | lower_text = lower_cell.get_code(); |
|
694 | cell.set_text(upper_text+'\n'+text); | |
703 | lower_cell.set_code(upper_text+'\n'+lower_text); |
|
695 | } else if (cell instanceof IPython.MarkdownCell || cell instanceof IPython.HTMLCell) { | |
704 |
|
|
696 | cell.edit(); | |
|
697 | cell.set_text(upper_text+'\n'+text); | |||
|
698 | cell.render(); | |||
705 | }; |
|
699 | }; | |
|
700 | this.delete_cell(index-1); | |||
|
701 | this.select(this.find_cell_index(cell)); | |||
706 | }; |
|
702 | }; | |
707 | }; |
|
703 | }; | |
708 |
|
704 | |||
709 |
|
705 | |||
710 | Notebook.prototype.merge_cell_below = function () { |
|
706 | Notebook.prototype.merge_cell_below = function () { | |
711 | // Todo: implement merging for other cell types. |
|
707 | var index = this.get_selected_index(); | |
712 |
var cell = this. |
|
708 | var cell = this.get_cell(index); | |
713 | var index = this.selected_index(); |
|
|||
714 | if (index < this.ncells()-1) { |
|
709 | if (index < this.ncells()-1) { | |
715 |
|
|
710 | lower_cell = this.get_cell(index+1); | |
716 | lower_cell = this.cells()[index+1]; |
|
711 | lower_text = lower_cell.get_text(); | |
717 | if (upper_cell instanceof IPython.CodeCell && lower_cell instanceof IPython.CodeCell) { |
|
712 | text = cell.get_text(); | |
718 | upper_text = upper_cell.get_code(); |
|
713 | if (cell instanceof IPython.CodeCell) { | |
719 | lower_text = lower_cell.get_code(); |
|
714 | cell.set_text(text+'\n'+lower_text); | |
720 | upper_cell.set_code(upper_text+'\n'+lower_text); |
|
715 | } else if (cell instanceof IPython.MarkdownCell || cell instanceof IPython.HTMLCell) { | |
721 |
|
|
716 | cell.edit(); | |
|
717 | cell.set_text(text+'\n'+lower_text); | |||
|
718 | cell.render(); | |||
722 | }; |
|
719 | }; | |
|
720 | this.delete_cell(index+1); | |||
|
721 | this.select(this.find_cell_index(cell)); | |||
723 | }; |
|
722 | }; | |
724 | }; |
|
723 | }; | |
725 |
|
724 | |||
|
725 | ||||
726 | // Cell collapsing and output clearing |
|
726 | // Cell collapsing and output clearing | |
727 |
|
727 | |||
728 | Notebook.prototype.collapse = function (index) { |
|
728 | Notebook.prototype.collapse = function (index) { | |
729 | var i = this.index_or_selected(index); |
|
729 | var i = this.index_or_selected(index); | |
730 |
this.cell |
|
730 | this.get_cell(i).collapse(); | |
731 | this.dirty = true; |
|
731 | this.dirty = true; | |
732 | }; |
|
732 | }; | |
733 |
|
733 | |||
734 |
|
734 | |||
735 | Notebook.prototype.expand = function (index) { |
|
735 | Notebook.prototype.expand = function (index) { | |
736 | var i = this.index_or_selected(index); |
|
736 | var i = this.index_or_selected(index); | |
737 |
this.cell |
|
737 | this.get_cell(i).expand(); | |
738 | this.dirty = true; |
|
738 | this.dirty = true; | |
739 | }; |
|
739 | }; | |
740 |
|
740 | |||
741 |
|
741 | |||
742 | Notebook.prototype.toggle_output = function (index) { |
|
742 | Notebook.prototype.toggle_output = function (index) { | |
743 | var i = this.index_or_selected(index); |
|
743 | var i = this.index_or_selected(index); | |
744 |
this.cell |
|
744 | this.get_cell(i).toggle_output(); | |
745 | this.dirty = true; |
|
745 | this.dirty = true; | |
746 | }; |
|
746 | }; | |
747 |
|
747 | |||
@@ -750,26 +750,20 b' var IPython = (function (IPython) {' | |||||
750 | this.time_before_tooltip = time; |
|
750 | this.time_before_tooltip = time; | |
751 | }; |
|
751 | }; | |
752 |
|
752 | |||
|
753 | ||||
753 | Notebook.prototype.set_tooltipontab = function (state) { |
|
754 | Notebook.prototype.set_tooltipontab = function (state) { | |
754 | this.tooltip_on_tab = state; |
|
755 | this.tooltip_on_tab = state; | |
755 | }; |
|
756 | }; | |
756 |
|
757 | |||
|
758 | ||||
757 | Notebook.prototype.set_smartcompleter = function (state) { |
|
759 | Notebook.prototype.set_smartcompleter = function (state) { | |
758 | this.smart_completer = state; |
|
760 | this.smart_completer = state; | |
759 | }; |
|
761 | }; | |
760 |
|
762 | |||
761 | Notebook.prototype.set_autoindent = function (state) { |
|
|||
762 | var cells = this.cells(); |
|
|||
763 | len = cells.length; |
|
|||
764 | for (var i=0; i<len; i++) { |
|
|||
765 | cells[i].set_autoindent(state); |
|
|||
766 | }; |
|
|||
767 | }; |
|
|||
768 |
|
||||
769 |
|
763 | |||
770 | Notebook.prototype.clear_all_output = function () { |
|
764 | Notebook.prototype.clear_all_output = function () { | |
771 | var ncells = this.ncells(); |
|
765 | var ncells = this.ncells(); | |
772 | var cells = this.cells(); |
|
766 | var cells = this.get_cells(); | |
773 | for (var i=0; i<ncells; i++) { |
|
767 | for (var i=0; i<ncells; i++) { | |
774 | if (cells[i] instanceof IPython.CodeCell) { |
|
768 | if (cells[i] instanceof IPython.CodeCell) { | |
775 | cells[i].clear_output(true,true,true); |
|
769 | cells[i].clear_output(true,true,true); | |
@@ -778,10 +772,11 b' var IPython = (function (IPython) {' | |||||
778 | this.dirty = true; |
|
772 | this.dirty = true; | |
779 | }; |
|
773 | }; | |
780 |
|
774 | |||
|
775 | ||||
781 | // Other cell functions: line numbers, ... |
|
776 | // Other cell functions: line numbers, ... | |
782 |
|
777 | |||
783 | Notebook.prototype.cell_toggle_line_numbers = function() { |
|
778 | Notebook.prototype.cell_toggle_line_numbers = function() { | |
784 | this.selected_cell().toggle_line_numbers(); |
|
779 | this.get_selected_cell().toggle_line_numbers(); | |
785 | }; |
|
780 | }; | |
786 |
|
781 | |||
787 | // Kernel related things |
|
782 | // Kernel related things | |
@@ -868,8 +863,8 b' var IPython = (function (IPython) {' | |||||
868 | } |
|
863 | } | |
869 | } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') { |
|
864 | } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') { | |
870 | var index = this.find_cell_index(cell); |
|
865 | var index = this.find_cell_index(cell); | |
871 |
var new_cell = this.insert_c |
|
866 | var new_cell = this.insert_cell_below('code',index); | |
872 |
new_cell.set_ |
|
867 | new_cell.set_text(payload[i].text); | |
873 | this.dirty = true; |
|
868 | this.dirty = true; | |
874 | } |
|
869 | } | |
875 | }; |
|
870 | }; | |
@@ -988,14 +983,14 b' var IPython = (function (IPython) {' | |||||
988 | default_options = {terminal: false, add_new: true}; |
|
983 | default_options = {terminal: false, add_new: true}; | |
989 | $.extend(default_options, options); |
|
984 | $.extend(default_options, options); | |
990 | var that = this; |
|
985 | var that = this; | |
991 | var cell = that.selected_cell(); |
|
986 | var cell = that.get_selected_cell(); | |
992 | var cell_index = that.find_cell_index(cell); |
|
987 | var cell_index = that.find_cell_index(cell); | |
993 | if (cell instanceof IPython.CodeCell) { |
|
988 | if (cell instanceof IPython.CodeCell) { | |
994 | cell.clear_output(true, true, true); |
|
989 | cell.clear_output(true, true, true); | |
995 | cell.set_input_prompt('*'); |
|
990 | cell.set_input_prompt('*'); | |
996 | cell.element.addClass("running"); |
|
991 | cell.element.addClass("running"); | |
997 |
var code = cell.get_ |
|
992 | var code = cell.get_text(); | |
998 |
var msg_id = that.kernel.execute(cell.get_ |
|
993 | var msg_id = that.kernel.execute(cell.get_text()); | |
999 | that.msg_cell_map[msg_id] = cell.cell_id; |
|
994 | that.msg_cell_map[msg_id] = cell.cell_id; | |
1000 | } else if (cell instanceof IPython.HTMLCell) { |
|
995 | } else if (cell instanceof IPython.HTMLCell) { | |
1001 | cell.render(); |
|
996 | cell.render(); | |
@@ -1004,7 +999,7 b' var IPython = (function (IPython) {' | |||||
1004 | cell.select_all(); |
|
999 | cell.select_all(); | |
1005 | } else { |
|
1000 | } else { | |
1006 | if ((cell_index === (that.ncells()-1)) && default_options.add_new) { |
|
1001 | if ((cell_index === (that.ncells()-1)) && default_options.add_new) { | |
1007 |
that.insert_c |
|
1002 | that.insert_cell_below('code'); | |
1008 | // If we are adding a new cell at the end, scroll down to show it. |
|
1003 | // If we are adding a new cell at the end, scroll down to show it. | |
1009 | that.scroll_to_bottom(); |
|
1004 | that.scroll_to_bottom(); | |
1010 | } else { |
|
1005 | } else { | |
@@ -1019,7 +1014,7 b' var IPython = (function (IPython) {' | |||||
1019 | var ncells = this.ncells(); |
|
1014 | var ncells = this.ncells(); | |
1020 | for (var i=0; i<ncells; i++) { |
|
1015 | for (var i=0; i<ncells; i++) { | |
1021 | this.select(i); |
|
1016 | this.select(i); | |
1022 | this.execute_selected_cell({add_new:false}); |
|
1017 | this.execute_get_selected_cell({add_new:false}); | |
1023 | }; |
|
1018 | }; | |
1024 | this.scroll_to_bottom(); |
|
1019 | this.scroll_to_bottom(); | |
1025 | }; |
|
1020 | }; | |
@@ -1075,23 +1070,15 b' var IPython = (function (IPython) {' | |||||
1075 | var new_cell = null; |
|
1070 | var new_cell = null; | |
1076 | for (i=0; i<ncells; i++) { |
|
1071 | for (i=0; i<ncells; i++) { | |
1077 | cell_data = new_cells[i]; |
|
1072 | cell_data = new_cells[i]; | |
1078 |
|
|
1073 | new_cell = this.insert_cell_below(cell_data.cell_type); | |
1079 |
|
|
1074 | new_cell.fromJSON(cell_data); | |
1080 | new_cell.fromJSON(cell_data); |
|
|||
1081 | } else if (cell_data.cell_type === 'html') { |
|
|||
1082 | new_cell = this.insert_html_cell_below(); |
|
|||
1083 | new_cell.fromJSON(cell_data); |
|
|||
1084 | } else if (cell_data.cell_type === 'markdown') { |
|
|||
1085 | new_cell = this.insert_markdown_cell_below(); |
|
|||
1086 | new_cell.fromJSON(cell_data); |
|
|||
1087 | }; |
|
|||
1088 | }; |
|
1075 | }; | |
1089 | }; |
|
1076 | }; | |
1090 | }; |
|
1077 | }; | |
1091 |
|
1078 | |||
1092 |
|
1079 | |||
1093 | Notebook.prototype.toJSON = function () { |
|
1080 | Notebook.prototype.toJSON = function () { | |
1094 | var cells = this.cells(); |
|
1081 | var cells = this.get_cells(); | |
1095 | var ncells = cells.length; |
|
1082 | var ncells = cells.length; | |
1096 | cell_array = new Array(ncells); |
|
1083 | cell_array = new Array(ncells); | |
1097 | for (var i=0; i<ncells; i++) { |
|
1084 | for (var i=0; i<ncells; i++) { | |
@@ -1106,27 +1093,25 b' var IPython = (function (IPython) {' | |||||
1106 | }; |
|
1093 | }; | |
1107 |
|
1094 | |||
1108 | Notebook.prototype.save_notebook = function () { |
|
1095 | Notebook.prototype.save_notebook = function () { | |
1109 |
|
|
1096 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
1110 |
|
|
1097 | var nbname = IPython.save_widget.get_notebook_name(); | |
1111 | var nbname = IPython.save_widget.get_notebook_name(); |
|
1098 | // We may want to move the name/id/nbformat logic inside toJSON? | |
1112 | // We may want to move the name/id/nbformat logic inside toJSON? |
|
1099 | var data = this.toJSON(); | |
1113 | var data = this.toJSON(); |
|
1100 | data.metadata.name = nbname; | |
1114 |
|
|
1101 | data.nbformat = 2; | |
1115 | data.nbformat = 2; |
|
1102 | // We do the call with settings so we can set cache to false. | |
1116 | // We do the call with settings so we can set cache to false. |
|
1103 | var settings = { | |
1117 | var settings = { |
|
1104 | processData : false, | |
1118 |
|
|
1105 | cache : false, | |
1119 |
|
|
1106 | type : "PUT", | |
1120 | type : "PUT", |
|
1107 | data : JSON.stringify(data), | |
1121 | data : JSON.stringify(data), |
|
1108 | headers : {'Content-Type': 'application/json'}, | |
1122 | headers : {'Content-Type': 'application/json'}, |
|
1109 | success : $.proxy(this.notebook_saved,this), | |
1123 |
|
|
1110 | error : $.proxy(this.notebook_save_failed,this) | |
1124 | error : $.proxy(this.notebook_save_failed,this) |
|
|||
1125 | }; |
|
|||
1126 | IPython.save_widget.status_saving(); |
|
|||
1127 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; |
|
|||
1128 | $.ajax(url, settings); |
|
|||
1129 | }; |
|
1111 | }; | |
|
1112 | IPython.save_widget.status_saving(); | |||
|
1113 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; | |||
|
1114 | $.ajax(url, settings); | |||
1130 | }; |
|
1115 | }; | |
1131 |
|
1116 | |||
1132 |
|
1117 | |||
@@ -1142,7 +1127,7 b' var IPython = (function (IPython) {' | |||||
1142 | }; |
|
1127 | }; | |
1143 |
|
1128 | |||
1144 |
|
1129 | |||
1145 |
Notebook.prototype.load_notebook = function ( |
|
1130 | Notebook.prototype.load_notebook = function () { | |
1146 | var that = this; |
|
1131 | var that = this; | |
1147 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
1132 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
1148 | // We do the call with settings so we can set cache to false. |
|
1133 | // We do the call with settings so we can set cache to false. | |
@@ -1153,9 +1138,6 b' var IPython = (function (IPython) {' | |||||
1153 | dataType : "json", |
|
1138 | dataType : "json", | |
1154 | success : function (data, status, xhr) { |
|
1139 | success : function (data, status, xhr) { | |
1155 | that.notebook_loaded(data, status, xhr); |
|
1140 | that.notebook_loaded(data, status, xhr); | |
1156 | if (callback !== undefined) { |
|
|||
1157 | callback(); |
|
|||
1158 | }; |
|
|||
1159 | } |
|
1141 | } | |
1160 | }; |
|
1142 | }; | |
1161 | IPython.save_widget.status_loading(); |
|
1143 | IPython.save_widget.status_loading(); | |
@@ -1165,10 +1147,9 b' var IPython = (function (IPython) {' | |||||
1165 |
|
1147 | |||
1166 |
|
1148 | |||
1167 | Notebook.prototype.notebook_loaded = function (data, status, xhr) { |
|
1149 | Notebook.prototype.notebook_loaded = function (data, status, xhr) { | |
1168 | var allowed = xhr.getResponseHeader('Allow'); |
|
|||
1169 | this.fromJSON(data); |
|
1150 | this.fromJSON(data); | |
1170 | if (this.ncells() === 0) { |
|
1151 | if (this.ncells() === 0) { | |
1171 |
this.insert_c |
|
1152 | this.insert_cell_below('code'); | |
1172 | }; |
|
1153 | }; | |
1173 | IPython.save_widget.status_last_saved(); |
|
1154 | IPython.save_widget.status_last_saved(); | |
1174 | IPython.save_widget.set_notebook_name(data.metadata.name); |
|
1155 | IPython.save_widget.set_notebook_name(data.metadata.name); | |
@@ -1176,12 +1157,10 b' var IPython = (function (IPython) {' | |||||
1176 | if (! this.read_only) { |
|
1157 | if (! this.read_only) { | |
1177 | this.start_kernel(); |
|
1158 | this.start_kernel(); | |
1178 | } |
|
1159 | } | |
1179 | // fromJSON always selects the last cell inserted. We need to wait |
|
1160 | this.select(0); | |
1180 | // until that is done before scrolling to the top. |
|
1161 | this.scroll_to_top(); | |
1181 | setTimeout(function () { |
|
1162 | IPython.save_widget.update_url(); | |
1182 | IPython.notebook.select(0); |
|
1163 | IPython.layout_manager.do_resize(); | |
1183 | IPython.notebook.scroll_to_top(); |
|
|||
1184 | }, 50); |
|
|||
1185 | }; |
|
1164 | }; | |
1186 |
|
1165 | |||
1187 | IPython.Notebook = Notebook; |
|
1166 | IPython.Notebook = Notebook; |
@@ -109,16 +109,8 b' $(document).ready(function () {' | |||||
109 | $('div#menubar').css('display','block'); |
|
109 | $('div#menubar').css('display','block'); | |
110 | $('div#main_app').css('display','block'); |
|
110 | $('div#main_app').css('display','block'); | |
111 |
|
111 | |||
112 | // Perform these actions after the notebook has been loaded. |
|
112 | IPython.layout_manager.do_resize(); | |
113 | // We wait 100 milliseconds because the notebook scrolls to the top after a load |
|
113 | IPython.notebook.load_notebook(); | |
114 | // is completed and we need to wait for that to mostly finish. |
|
|||
115 | IPython.notebook.load_notebook(function () { |
|
|||
116 | setTimeout(function () { |
|
|||
117 | IPython.save_widget.update_url(); |
|
|||
118 | IPython.layout_manager.do_resize(); |
|
|||
119 | IPython.pager.collapse(); |
|
|||
120 | },100); |
|
|||
121 | }); |
|
|||
122 |
|
114 | |||
123 | }); |
|
115 | }); | |
124 |
|
116 |
@@ -16,7 +16,7 b' var IPython = (function (IPython) {' | |||||
16 | var Pager = function (pager_selector, pager_splitter_selector) { |
|
16 | var Pager = function (pager_selector, pager_splitter_selector) { | |
17 | this.pager_element = $(pager_selector); |
|
17 | this.pager_element = $(pager_selector); | |
18 | this.pager_splitter_element = $(pager_splitter_selector); |
|
18 | this.pager_splitter_element = $(pager_splitter_selector); | |
19 |
this.expanded = |
|
19 | this.expanded = false; | |
20 | this.percentage_height = 0.40; |
|
20 | this.percentage_height = 0.40; | |
21 | this.style(); |
|
21 | this.style(); | |
22 | this.bind_events(); |
|
22 | this.bind_events(); |
@@ -75,8 +75,8 b' var IPython = (function (IPython) {' | |||||
75 | var new_name = $(this).find('input').attr('value'); |
|
75 | var new_name = $(this).find('input').attr('value'); | |
76 | if (!that.test_notebook_name(new_name)) { |
|
76 | if (!that.test_notebook_name(new_name)) { | |
77 | $(this).find('h3').html( |
|
77 | $(this).find('h3').html( | |
78 |
"Invalid notebook name. |
|
78 | "Invalid notebook name. Notebook names must "+ | |
79 |
" |
|
79 | "have 1 or more characters and can contain any characters " + | |
80 | "except / and \\. Please enter a new notebook name:" |
|
80 | "except / and \\. Please enter a new notebook name:" | |
81 | ); |
|
81 | ); | |
82 | } else { |
|
82 | } else { | |
@@ -131,7 +131,8 b' var IPython = (function (IPython) {' | |||||
131 |
|
131 | |||
132 |
|
132 | |||
133 | SaveWidget.prototype.test_notebook_name = function (nbname) { |
|
133 | SaveWidget.prototype.test_notebook_name = function (nbname) { | |
134 | if (this.notebook_name_blacklist_re.test(nbname) == false) { |
|
134 | nbname = nbname || ''; | |
|
135 | if (this.notebook_name_blacklist_re.test(nbname) == false && nbname.length>0) { | |||
135 | return true; |
|
136 | return true; | |
136 | } else { |
|
137 | } else { | |
137 | return false; |
|
138 | return false; |
@@ -15,7 +15,6 b' var IPython = (function (IPython) {' | |||||
15 |
|
15 | |||
16 | var TextCell = function (notebook) { |
|
16 | var TextCell = function (notebook) { | |
17 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; |
|
17 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; | |
18 | this.placeholder = this.placeholder || '\u0000'; |
|
|||
19 | IPython.Cell.apply(this, arguments); |
|
18 | IPython.Cell.apply(this, arguments); | |
20 | this.rendered = false; |
|
19 | this.rendered = false; | |
21 | this.cell_type = this.cell_type || 'text'; |
|
20 | this.cell_type = this.cell_type || 'text'; | |
@@ -28,16 +27,17 b' var IPython = (function (IPython) {' | |||||
28 | TextCell.prototype.create_element = function () { |
|
27 | TextCell.prototype.create_element = function () { | |
29 | var cell = $("<div>").addClass('cell text_cell border-box-sizing'); |
|
28 | var cell = $("<div>").addClass('cell text_cell border-box-sizing'); | |
30 | cell.attr('tabindex','2'); |
|
29 | cell.attr('tabindex','2'); | |
31 | var input_area = $('<div/>').addClass('text_cell_input'); |
|
30 | var input_area = $('<div/>').addClass('text_cell_input border-box-sizing'); | |
32 | this.code_mirror = CodeMirror(input_area.get(0), { |
|
31 | this.code_mirror = CodeMirror(input_area.get(0), { | |
33 | indentUnit : 4, |
|
32 | indentUnit : 4, | |
34 | mode: this.code_mirror_mode, |
|
33 | mode: this.code_mirror_mode, | |
35 | theme: 'default', |
|
34 | theme: 'default', | |
36 | value: this.placeholder, |
|
35 | value: this.placeholder, | |
37 | readOnly: this.read_only |
|
36 | readOnly: this.read_only, | |
|
37 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |||
38 | }); |
|
38 | }); | |
39 | // The tabindex=-1 makes this div focusable. |
|
39 | // The tabindex=-1 makes this div focusable. | |
40 | var render_area = $('<div/>').addClass('text_cell_render'). |
|
40 | var render_area = $('<div/>').addClass('text_cell_render border-box-sizing'). | |
41 | addClass('rendered_html').attr('tabindex','-1'); |
|
41 | addClass('rendered_html').attr('tabindex','-1'); | |
42 | cell.append(input_area).append(render_area); |
|
42 | cell.append(input_area).append(render_area); | |
43 | this.element = cell; |
|
43 | this.element = cell; | |
@@ -51,13 +51,30 b' var IPython = (function (IPython) {' | |||||
51 | if (event.which === 13) { |
|
51 | if (event.which === 13) { | |
52 | if (that.rendered) { |
|
52 | if (that.rendered) { | |
53 | that.edit(); |
|
53 | that.edit(); | |
54 |
|
|
54 | return false; | |
55 | } |
|
55 | }; | |
56 | } |
|
56 | }; | |
|
57 | }); | |||
|
58 | this.element.dblclick(function () { | |||
|
59 | that.edit(); | |||
57 | }); |
|
60 | }); | |
58 | }; |
|
61 | }; | |
59 |
|
62 | |||
60 |
|
63 | |||
|
64 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { | |||
|
65 | // This method gets called in CodeMirror's onKeyDown/onKeyPress | |||
|
66 | // handlers and is used to provide custom key handling. Its return | |||
|
67 | // value is used to determine if CodeMirror should ignore the event: | |||
|
68 | // true = ignore, false = don't ignore. | |||
|
69 | ||||
|
70 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { | |||
|
71 | // Always ignore shift-enter in CodeMirror as we handle it. | |||
|
72 | return true; | |||
|
73 | } | |||
|
74 | return false; | |||
|
75 | }; | |||
|
76 | ||||
|
77 | ||||
61 | TextCell.prototype.select = function () { |
|
78 | TextCell.prototype.select = function () { | |
62 | IPython.Cell.prototype.select.apply(this); |
|
79 | IPython.Cell.prototype.select.apply(this); | |
63 | var output = this.element.find("div.text_cell_render"); |
|
80 | var output = this.element.find("div.text_cell_render"); | |
@@ -79,11 +96,18 b' var IPython = (function (IPython) {' | |||||
79 | var output = text_cell.find("div.text_cell_render"); |
|
96 | var output = text_cell.find("div.text_cell_render"); | |
80 | output.hide(); |
|
97 | output.hide(); | |
81 | text_cell.find('div.text_cell_input').show(); |
|
98 | text_cell.find('div.text_cell_input').show(); | |
|
99 | // I don't know why I need to do this, but if I don't do | |||
|
100 | // refresh/focus/refresh, the to_markdown method won't work. | |||
|
101 | this.code_mirror.refresh(); | |||
82 | this.code_mirror.focus(); |
|
102 | this.code_mirror.focus(); | |
|
103 | // This final refresh is needed on Firefox to trigger the editor | |||
|
104 | // to be auto-sized. This glitch only happens on cell that are | |||
|
105 | // loaded initially and haven't had their editor focused before. | |||
83 | this.code_mirror.refresh(); |
|
106 | this.code_mirror.refresh(); | |
84 | this.rendered = false; |
|
107 | this.rendered = false; | |
85 |
if (this.get_ |
|
108 | if (this.get_text() === this.placeholder) { | |
86 |
this.set_ |
|
109 | this.set_text(''); | |
|
110 | this.refresh(); | |||
87 | } |
|
111 | } | |
88 | } |
|
112 | } | |
89 | }; |
|
113 | }; | |
@@ -93,22 +117,12 b' var IPython = (function (IPython) {' | |||||
93 | TextCell.prototype.render = function () {}; |
|
117 | TextCell.prototype.render = function () {}; | |
94 |
|
118 | |||
95 |
|
119 | |||
96 |
TextCell.prototype. |
|
120 | TextCell.prototype.get_text = function() { | |
97 | var text_cell = this.element; |
|
|||
98 | var that = this; |
|
|||
99 | text_cell.dblclick(function () { |
|
|||
100 | that.edit(); |
|
|||
101 | }); |
|
|||
102 | that.render(); |
|
|||
103 | }; |
|
|||
104 |
|
||||
105 |
|
||||
106 | TextCell.prototype.get_source = function() { |
|
|||
107 | return this.code_mirror.getValue(); |
|
121 | return this.code_mirror.getValue(); | |
108 | }; |
|
122 | }; | |
109 |
|
123 | |||
110 |
|
124 | |||
111 |
TextCell.prototype.set_ |
|
125 | TextCell.prototype.set_text = function(text) { | |
112 | this.code_mirror.setValue(text); |
|
126 | this.code_mirror.setValue(text); | |
113 | this.code_mirror.refresh(); |
|
127 | this.code_mirror.refresh(); | |
114 | }; |
|
128 | }; | |
@@ -145,7 +159,7 b' var IPython = (function (IPython) {' | |||||
145 | TextCell.prototype.fromJSON = function (data) { |
|
159 | TextCell.prototype.fromJSON = function (data) { | |
146 | if (data.cell_type === this.cell_type) { |
|
160 | if (data.cell_type === this.cell_type) { | |
147 | if (data.source !== undefined) { |
|
161 | if (data.source !== undefined) { | |
148 |
this.set_ |
|
162 | this.set_text(data.source); | |
149 | this.set_rendered(data.rendered || ''); |
|
163 | this.set_rendered(data.rendered || ''); | |
150 | this.rendered = false; |
|
164 | this.rendered = false; | |
151 | this.render(); |
|
165 | this.render(); | |
@@ -157,7 +171,7 b' var IPython = (function (IPython) {' | |||||
157 | TextCell.prototype.toJSON = function () { |
|
171 | TextCell.prototype.toJSON = function () { | |
158 | var data = {}; |
|
172 | var data = {}; | |
159 | data.cell_type = this.cell_type; |
|
173 | data.cell_type = this.cell_type; | |
160 |
data.source = this.get_ |
|
174 | data.source = this.get_text(); | |
161 | return data; |
|
175 | return data; | |
162 | }; |
|
176 | }; | |
163 |
|
177 | |||
@@ -165,7 +179,7 b' var IPython = (function (IPython) {' | |||||
165 | // HTMLCell |
|
179 | // HTMLCell | |
166 |
|
180 | |||
167 | var HTMLCell = function (notebook) { |
|
181 | var HTMLCell = function (notebook) { | |
168 |
this.placeholder = " |
|
182 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"; | |
169 | IPython.TextCell.apply(this, arguments); |
|
183 | IPython.TextCell.apply(this, arguments); | |
170 | this.cell_type = 'html'; |
|
184 | this.cell_type = 'html'; | |
171 | }; |
|
185 | }; | |
@@ -176,7 +190,7 b' var IPython = (function (IPython) {' | |||||
176 |
|
190 | |||
177 | HTMLCell.prototype.render = function () { |
|
191 | HTMLCell.prototype.render = function () { | |
178 | if (this.rendered === false) { |
|
192 | if (this.rendered === false) { | |
179 |
var text = this.get_ |
|
193 | var text = this.get_text(); | |
180 | if (text === "") { text = this.placeholder; } |
|
194 | if (text === "") { text = this.placeholder; } | |
181 | this.set_rendered(text); |
|
195 | this.set_rendered(text); | |
182 | this.typeset(); |
|
196 | this.typeset(); | |
@@ -190,7 +204,7 b' var IPython = (function (IPython) {' | |||||
190 | // MarkdownCell |
|
204 | // MarkdownCell | |
191 |
|
205 | |||
192 | var MarkdownCell = function (notebook) { |
|
206 | var MarkdownCell = function (notebook) { | |
193 |
this.placeholder = " |
|
207 | this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$"; | |
194 | IPython.TextCell.apply(this, arguments); |
|
208 | IPython.TextCell.apply(this, arguments); | |
195 | this.cell_type = 'markdown'; |
|
209 | this.cell_type = 'markdown'; | |
196 | }; |
|
210 | }; | |
@@ -201,7 +215,7 b' var IPython = (function (IPython) {' | |||||
201 |
|
215 | |||
202 | MarkdownCell.prototype.render = function () { |
|
216 | MarkdownCell.prototype.render = function () { | |
203 | if (this.rendered === false) { |
|
217 | if (this.rendered === false) { | |
204 |
var text = this.get_ |
|
218 | var text = this.get_text(); | |
205 | if (text === "") { text = this.placeholder; } |
|
219 | if (text === "") { text = this.placeholder; } | |
206 | var html = IPython.markdown_converter.makeHtml(text); |
|
220 | var html = IPython.markdown_converter.makeHtml(text); | |
207 | this.set_rendered(html); |
|
221 | this.set_rendered(html); | |
@@ -228,7 +242,7 b' var IPython = (function (IPython) {' | |||||
228 | // RSTCell |
|
242 | // RSTCell | |
229 |
|
243 | |||
230 | var RSTCell = function (notebook) { |
|
244 | var RSTCell = function (notebook) { | |
231 |
this.placeholder = " |
|
245 | this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$"; | |
232 | IPython.TextCell.apply(this, arguments); |
|
246 | IPython.TextCell.apply(this, arguments); | |
233 | this.cell_type = 'rst'; |
|
247 | this.cell_type = 'rst'; | |
234 | }; |
|
248 | }; | |
@@ -239,7 +253,7 b' var IPython = (function (IPython) {' | |||||
239 |
|
253 | |||
240 | RSTCell.prototype.render = function () { |
|
254 | RSTCell.prototype.render = function () { | |
241 | if (this.rendered === false) { |
|
255 | if (this.rendered === false) { | |
242 |
var text = this.get_ |
|
256 | var text = this.get_text(); | |
243 | if (text === "") { text = this.placeholder; } |
|
257 | if (text === "") { text = this.placeholder; } | |
244 | var settings = { |
|
258 | var settings = { | |
245 | processData : false, |
|
259 | processData : false, |
@@ -17,10 +17,7 b'' | |||||
17 |
|
17 | |||
18 | <link rel="stylesheet" href="/static/jquery/css/themes/base/jquery-ui.min.css" type="text/css" /> |
|
18 | <link rel="stylesheet" href="/static/jquery/css/themes/base/jquery-ui.min.css" type="text/css" /> | |
19 | <link rel="stylesheet" href="/static/codemirror/lib/codemirror.css"> |
|
19 | <link rel="stylesheet" href="/static/codemirror/lib/codemirror.css"> | |
20 | <link rel="stylesheet" href="/static/codemirror/mode/markdown/markdown.css"> |
|
|||
21 | <link rel="stylesheet" href="/static/codemirror/mode/rst/rst.css"> |
|
|||
22 | <link rel="stylesheet" href="/static/codemirror/theme/ipython.css"> |
|
20 | <link rel="stylesheet" href="/static/codemirror/theme/ipython.css"> | |
23 | <link rel="stylesheet" href="/static/codemirror/theme/default.css"> |
|
|||
24 |
|
21 | |||
25 | <link rel="stylesheet" href="/static/prettify/prettify.css"/> |
|
22 | <link rel="stylesheet" href="/static/prettify/prettify.css"/> | |
26 |
|
23 | |||
@@ -179,6 +176,8 b'' | |||||
179 |
|
176 | |||
180 | <script src="/static/ace/ace.js" type="text/javascript" charset="utf-8"></script> |
|
177 | <script src="/static/ace/ace.js" type="text/javascript" charset="utf-8"></script> | |
181 | <script src="/static/ace/mode-python.js" type="text/javascript" charset="utf-8"></script> |
|
178 | <script src="/static/ace/mode-python.js" type="text/javascript" charset="utf-8"></script> | |
|
179 | <script src="/static/ace/mode-markdown.js" type="text/javascript" charset="utf-8"></script> | |||
|
180 | <script src="/static/ace/mode-html.js" type="text/javascript" charset="utf-8"></script> | |||
182 | <script src="/static/ace/theme-textmate.js" type="text/javascript" charset="utf-8"></script> |
|
181 | <script src="/static/ace/theme-textmate.js" type="text/javascript" charset="utf-8"></script> | |
183 |
|
182 | |||
184 | <script src="/static/pagedown/Markdown.Converter.js" charset="utf-8"></script> |
|
183 | <script src="/static/pagedown/Markdown.Converter.js" charset="utf-8"></script> |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now