From 271ee1776b6900d90d138d6770fe288768162ca1 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Thu, 7 Jul 2011 18:59:34 +0100 Subject: [PATCH] beautified all static js files --- static/js/ace.js | 254 +- static/js/ace2_common.js | 81 +- static/js/ace2_inner.js | 5742 ++++++++++++++++----------- static/js/broadcast.js | 115 +- static/js/broadcast_revisions.js | 19 +- static/js/broadcast_slider.js | 61 +- static/js/changesettracker.js | 163 +- static/js/collab_client.js | 616 ++- static/js/colorutils.js | 99 +- static/js/contentcollector.js | 590 ++- static/js/cssmanager.js | 70 +- static/js/cssmanager_client.js | 3 +- static/js/domline.js | 242 +- static/js/domline_client.js | 32 +- static/js/draggable.js | 12 +- static/js/easysync2.js | 2100 ++++++---- static/js/easysync2_client.js | 174 +- static/js/json2.js | 555 ++- static/js/linestylefilter.js | 318 +- static/js/linestylefilter_client.js | 34 +- static/js/pad2.js | 644 +-- static/js/pad_connectionstatus.js | 60 +- static/js/pad_cookie.js | 79 +- static/js/pad_docbar.js | 359 +- static/js/pad_editbar.js | 167 +- static/js/pad_editor.js | 90 +- static/js/pad_impexp.js | 220 +- static/js/pad_modals.js | 221 +- static/js/pad_savedrevs.js | 384 +- static/js/pad_userlist.js | 583 +-- static/js/pad_utils.js | 328 +- static/js/plugins.js | 20 +- static/js/skiplist.js | 395 +- static/js/undo-xpopup.js | 15 +- static/js/undomodule.js | 275 +- static/js/virtual_lines.js | 371 +- 36 files changed, 9456 insertions(+), 6035 deletions(-) diff --git a/static/js/ace.js b/static/js/ace.js index 07906491..e71b857a 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -1,12 +1,12 @@ /** * Copyright 2009 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS-IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,38 +18,54 @@ // requires: plugins // requires: undefined +Ace2Editor.registry = { + nextId: 1 +}; -Ace2Editor.registry = { nextId: 1 }; - -function Ace2Editor() { +function Ace2Editor() +{ var thisFunctionsName = "Ace2Editor"; var ace2 = Ace2Editor; var editor = {}; - var info = { editor: editor, id: (ace2.registry.nextId++) }; + var info = { + editor: editor, + id: (ace2.registry.nextId++) + }; var loaded = false; var actionsPendingInit = []; - function pendingInit(func, optDoNow) { - return function() { + + function pendingInit(func, optDoNow) + { + return function() + { var that = this; var args = arguments; - function action() { - func.apply(that, args); + + function action() + { + func.apply(that, args); } - if (optDoNow) { - optDoNow.apply(that, args); + if (optDoNow) + { + optDoNow.apply(that, args); } - if (loaded) { - action(); + if (loaded) + { + action(); } - else { - actionsPendingInit.push(action); + else + { + actionsPendingInit.push(action); } }; } - function doActionsPendingInit() { - for(var i=0;i, time: +new Date()} return info.ace_getUnhandledErrors(); }; - editor.callWithAce = pendingInit(function(fn, callStack, normalize) { + editor.callWithAce = pendingInit(function(fn, callStack, normalize) + { return info.ace_callWithAce(fn, callStack, normalize); }); - editor.execCommand = pendingInit(function(cmd, arg1) { + editor.execCommand = pendingInit(function(cmd, arg1) + { info.ace_execCommand(cmd, arg1); }); - editor.replaceRange = pendingInit(function(start, end, text) { + editor.replaceRange = pendingInit(function(start, end, text) + { info.ace_replaceRange(start, end, text); }); @@ -127,50 +194,58 @@ function Ace2Editor() { // calls to these functions ($$INCLUDE_...) are replaced when this file is processed // and compressed, putting the compressed code from the named file directly into the // source here. - - var $$INCLUDE_CSS = function(fileName) { - return ''; - }; - var $$INCLUDE_JS = function(fileName) { - return '\x3cscript type="text/javascript" src="'+fileName+'">\x3c/script>'; - }; + var $$INCLUDE_CSS = function(fileName) + { + return ''; + }; + var $$INCLUDE_JS = function(fileName) + { + return '\x3cscript type="text/javascript" src="' + fileName + '">\x3c/script>'; + }; var $$INCLUDE_JS_DEV = $$INCLUDE_JS; var $$INCLUDE_CSS_DEV = $$INCLUDE_CSS; - var $$INCLUDE_CSS_Q = function(fileName) { - return '\'\''; - }; - var $$INCLUDE_JS_Q = function(fileName) { - return '\'\\x3cscript type="text/javascript" src="'+fileName+'">\\x3c/script>\''; - }; + var $$INCLUDE_CSS_Q = function(fileName) + { + return '\'\''; + }; + var $$INCLUDE_JS_Q = function(fileName) + { + return '\'\\x3cscript type="text/javascript" src="' + fileName + '">\\x3c/script>\''; + }; var $$INCLUDE_JS_Q_DEV = $$INCLUDE_JS_Q; var $$INCLUDE_CSS_Q_DEV = $$INCLUDE_CSS_Q; - editor.destroy = pendingInit(function() { + editor.destroy = pendingInit(function() + { info.ace_dispose(); info.frame.parentNode.removeChild(info.frame); delete ace2.registry[info.id]; info = null; // prevent IE 6 closure memory leaks }); - editor.init = function(containerId, initialCode, doneFunc) { + editor.init = function(containerId, initialCode, doneFunc) + { editor.importText(initialCode); - info.onEditorReady = function() { + info.onEditorReady = function() + { loaded = true; doActionsPendingInit(); doneFunc(); }; - (function() { + (function() + { var doctype = ""; - - var iframeHTML = ["'"+doctype+"'"]; - plugins.callHook( - "aceInitInnerdocbodyHead", {iframeHTML:iframeHTML}); - + var iframeHTML = ["'" + doctype + "'"]; + + plugins.callHook("aceInitInnerdocbodyHead", { + iframeHTML: iframeHTML + }); + // these lines must conform to a specific format because they are passed by the build script: iframeHTML.push($$INCLUDE_CSS_Q("static/css/editor.css")); iframeHTML.push($$INCLUDE_CSS_Q("static/css/syntax.css")); @@ -187,39 +262,26 @@ function Ace2Editor() { iframeHTML.push($$INCLUDE_JS_Q("static/js/linestylefilter.js")); iframeHTML.push($$INCLUDE_JS_Q("static/js/domline.js")); iframeHTML.push($$INCLUDE_JS_Q("static/js/ace2_inner.js")); - + iframeHTML.push('\'\\n\\n\''); iframeHTML.push('\' \''); - var outerScript = 'editorId = "'+info.id+'"; editorInfo = parent.'+ - thisFunctionsName+'.registry[editorId]; '+ - 'window.onload = function() '+ - '{ window.onload = null; setTimeout'+ - '(function() '+ - '{ var iframe = document.createElement("IFRAME"); '+ - 'iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); '+ - 'iframe.frameBorder = 0; iframe.allowTransparency = true; '+ // for IE - 'outerdocbody.insertBefore(iframe, outerdocbody.firstChild); '+ - 'iframe.ace_outerWin = window; '+ - 'readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; '+ - 'var doc = iframe.contentWindow.document; doc.open(); var text = ('+ - iframeHTML.join('+')+').replace(/\\\\x3c/g, \'<\');doc.write(text); doc.close(); '+ - '}, 0); }'; + var outerScript = 'editorId = "' + info.id + '"; editorInfo = parent.' + thisFunctionsName + '.registry[editorId]; ' + 'window.onload = function() ' + '{ window.onload = null; setTimeout' + '(function() ' + '{ var iframe = document.createElement("IFRAME"); ' + 'iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); ' + 'iframe.frameBorder = 0; iframe.allowTransparency = true; ' + // for IE + 'outerdocbody.insertBefore(iframe, outerdocbody.firstChild); ' + 'iframe.ace_outerWin = window; ' + 'readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; ' + 'var doc = iframe.contentWindow.document; doc.open(); var text = (' + iframeHTML.join('+') + ').replace(/\\\\x3c/g, \'<\');doc.write(text); doc.close(); ' + '}, 0); }'; - var outerHTML = [doctype, '', - $$INCLUDE_CSS("static/css/editor.css"), - // bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly - // (throbs busy while typing) - '', - '\x3cscript>\n', outerScript, '\n\x3c/script>', - '
x
']; + var outerHTML = [doctype, '', $$INCLUDE_CSS("static/css/editor.css"), + // bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly + // (throbs busy while typing) + '', '\x3cscript>\n', outerScript, '\n\x3c/script>', '
x
']; - if (!Array.prototype.map) Array.prototype.map = function(fun) { //needed for IE + if (!Array.prototype.map) Array.prototype.map = function(fun) + { //needed for IE if (typeof fun != "function") throw new TypeError(); var len = this.length; var res = new Array(len); var thisp = arguments[1]; - for (var i = 0; i < len; i++) { + for (var i = 0; i < len; i++) + { if (i in this) res[i] = fun.call(thisp, this[i], i, this); } return res; diff --git a/static/js/ace2_common.js b/static/js/ace2_common.js index 4a08de6f..02dc350f 100644 --- a/static/js/ace2_common.js +++ b/static/js/ace2_common.js @@ -1,12 +1,12 @@ /** * Copyright 2009 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS-IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,53 +15,63 @@ */ -function isNodeText(node) { +function isNodeText(node) +{ return (node.nodeType == 3); } -function object(o) { - var f = function() {}; +function object(o) +{ + var f = function() + {}; f.prototype = o; return new f(); } -function extend(obj, props) { - for(var p in props) { +function extend(obj, props) +{ + for (var p in props) + { obj[p] = props[p]; } return obj; } -function forEach(array, func) { - for(var i=0;i 1) { - var x = Math.floor((low+high)/2); // x != low, x != high + var high = numItems - 1; // func(high) is always true + while ((high - low) > 1) + { + var x = Math.floor((low + high) / 2); // x != low, x != high if (func(x)) high = x; else low = x; } return high; } -function binarySearchInfinite(expectedLength, func) { +function binarySearchInfinite(expectedLength, func) +{ var i = 0; while (!func(i)) i += expectedLength; return binarySearch(i, func); } -function htmlPrettyEscape(str) { - return str.replace(/&/g, '&').replace(//g, '>') - .replace(/\r?\n/g, '\\n'); +function htmlPrettyEscape(str) +{ + return str.replace(/&/g, '&').replace(//g, '>').replace(/\r?\n/g, '\\n'); } diff --git a/static/js/ace2_inner.js b/static/js/ace2_inner.js index 842c4ea6..69fce950 100644 --- a/static/js/ace2_inner.js +++ b/static/js/ace2_inner.js @@ -1,12 +1,12 @@ /** * Copyright 2009 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS-IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,13 +14,14 @@ * limitations under the License. */ -function OUTER(gscope) { +function OUTER(gscope) +{ - var DEBUG=false;//$$ build script replaces the string "var DEBUG=true;//$$" with "var DEBUG=false;" -// changed to false + var DEBUG = false; //$$ build script replaces the string "var DEBUG=true;//$$" with "var DEBUG=false;" + // changed to false var isSetUp = false; - var THE_TAB = ' ';//4 + var THE_TAB = ' '; //4 var MAX_LIST_LEVEL = 8; var LINE_NUMBER_PADDING_RIGHT = 4; @@ -45,24 +46,35 @@ function OUTER(gscope) { var overlaysdiv = lineMetricsDiv.nextSibling; initLineNumbers(); - var outsideKeyDown = function(evt) {}; - var outsideKeyPress = function(evt) { return true; }; - var outsideNotifyDirty = function() {}; + var outsideKeyDown = function(evt) + {}; + var outsideKeyPress = function(evt) + { + return true; + }; + var outsideNotifyDirty = function() + {}; // selFocusAtStart -- determines whether the selection extends "backwards", so that the focus // point (controlled with the arrow keys) is at the beginning; not supported in IE, though // native IE selections have that behavior (which we try not to interfere with). // Must be false if selection is collapsed! - var rep = { lines: newSkipList(), selStart: null, selEnd: null, selFocusAtStart: false, - alltext: "", alines: [], - apool: new AttribPool() }; + var rep = { + lines: newSkipList(), + selStart: null, + selEnd: null, + selFocusAtStart: false, + alltext: "", + alines: [], + apool: new AttribPool() + }; // lines, alltext, alines, and DOM are set up in setup() - if (undoModule.enabled) { + if (undoModule.enabled) + { undoModule.apool = rep.apool; } var root, doc; // set in setup() - var isEditable = true; var doesWrap = true; var hasLineNumbers = true; @@ -71,24 +83,42 @@ function OUTER(gscope) { // space around the innermost iframe element var iframePadLeft = MIN_LINEDIV_WIDTH + LINE_NUMBER_PADDING_RIGHT + EDIT_BODY_PADDING_LEFT; var iframePadTop = EDIT_BODY_PADDING_TOP; - var iframePadBottom = 0, iframePadRight = 0; + var iframePadBottom = 0, + iframePadRight = 0; var console = (DEBUG && window.console); - if (! window.console) { - var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", - "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; + if (!window.console) + { + var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; console = {}; for (var i = 0; i < names.length; ++i) - console[names[i]] = function() {}; + console[names[i]] = function() + {}; //console.error = function(str) { alert(str); }; } var PROFILER = window.PROFILER; - if (!PROFILER) { - PROFILER = function() { return {start:noop, mark:noop, literal:noop, end:noop, cancel:noop}; }; + if (!PROFILER) + { + PROFILER = function() + { + return { + start: noop, + mark: noop, + literal: noop, + end: noop, + cancel: noop + }; + }; + } + + function noop() + {} + + function identity(x) + { + return x; } - function noop() {} - function identity(x) { return x; } // "dmesg" is for displaying messages in the in-page output pane // visible when "?djs=1" is appended to the pad URL. It generally @@ -101,28 +131,39 @@ function OUTER(gscope) { var textFace = 'monospace'; var textSize = 12; - function textLineHeight() { return Math.round(textSize * 4/3); } + + function textLineHeight() + { + return Math.round(textSize * 4 / 3); + } var dynamicCSS = null; - function initDynamicCSS() { + + function initDynamicCSS() + { dynamicCSS = makeCSSManager("dynamicsyntax"); } var changesetTracker = makeChangesetTracker(scheduler, rep.apool, { - withCallbacks: function(operationName, f) { - inCallStackIfNecessary(operationName, function() { + withCallbacks: function(operationName, f) + { + inCallStackIfNecessary(operationName, function() + { fastIncorp(1); - f({ - setDocumentAttributedText: function(atext) { - setDocAText(atext); + f( + { + setDocumentAttributedText: function(atext) + { + setDocAText(atext); }, - applyChangesetToDocument: function(changeset, preferInsertionAfterCaret) { - var oldEventType = currentCallStack.editEvent.eventType; - currentCallStack.startNewEvent("nonundoable"); + applyChangesetToDocument: function(changeset, preferInsertionAfterCaret) + { + var oldEventType = currentCallStack.editEvent.eventType; + currentCallStack.startNewEvent("nonundoable"); - performDocumentApplyChangeset(changeset, preferInsertionAfterCaret); + performDocumentApplyChangeset(changeset, preferInsertionAfterCaret); - currentCallStack.startNewEvent(oldEventType); + currentCallStack.startNewEvent(oldEventType); } }); }); @@ -131,71 +172,95 @@ function OUTER(gscope) { var authorInfos = {}; // presence of key determines if author is present in doc - function setAuthorInfo(author, info) { - if ((typeof author) != "string") { - throw new Error("setAuthorInfo: author ("+author+") is not a string"); + function setAuthorInfo(author, info) + { + if ((typeof author) != "string") + { + throw new Error("setAuthorInfo: author (" + author + ") is not a string"); } - if (! info) { + if (!info) + { delete authorInfos[author]; - if (dynamicCSS) { - dynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author))); + if (dynamicCSS) + { + dynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author))); } } - else { + else + { authorInfos[author] = info; - if (info.bgcolor) { - if (dynamicCSS) { - var bgcolor = info.bgcolor; - if ((typeof info.fade) == "number") { - bgcolor = fadeColor(bgcolor, info.fade); - } + if (info.bgcolor) + { + if (dynamicCSS) + { + var bgcolor = info.bgcolor; + if ((typeof info.fade) == "number") + { + bgcolor = fadeColor(bgcolor, info.fade); + } - dynamicCSS.selectorStyle(getAuthorColorClassSelector( - getAuthorClassName(author))).backgroundColor = bgcolor; - } + dynamicCSS.selectorStyle(getAuthorColorClassSelector( + getAuthorClassName(author))).backgroundColor = bgcolor; + } } } } - function getAuthorClassName(author) { - return "author-"+author.replace(/[^a-y0-9]/g, function(c) { + function getAuthorClassName(author) + { + return "author-" + author.replace(/[^a-y0-9]/g, function(c) + { if (c == ".") return "-"; - return 'z'+c.charCodeAt(0)+'z'; + return 'z' + c.charCodeAt(0) + 'z'; }); } - function className2Author(className) { - if (className.substring(0,7) == "author-") { - return className.substring(7).replace(/[a-y0-9]+|-|z.+?z/g, function(cc) { + + function className2Author(className) + { + if (className.substring(0, 7) == "author-") + { + return className.substring(7).replace(/[a-y0-9]+|-|z.+?z/g, function(cc) + { if (cc == '-') return '.'; - else if (cc.charAt(0) == 'z') { - return String.fromCharCode(Number(cc.slice(1,-1))); + else if (cc.charAt(0) == 'z') + { + return String.fromCharCode(Number(cc.slice(1, -1))); } - else { + else + { return cc; } }); } return null; } - function getAuthorColorClassSelector(oneClassName) { - return ".authorColors ."+oneClassName; + + function getAuthorColorClassSelector(oneClassName) + { + return ".authorColors ." + oneClassName; } - function setUpTrackingCSS() { - if (dynamicCSS) { + + function setUpTrackingCSS() + { + if (dynamicCSS) + { var backgroundHeight = lineMetricsDiv.offsetHeight; var lineHeight = textLineHeight(); var extraBodding = 0; var extraTodding = 0; - if (backgroundHeight < lineHeight) { - extraBodding = Math.ceil((lineHeight - backgroundHeight)/2); - extraTodding = lineHeight - backgroundHeight - extraBodding; + if (backgroundHeight < lineHeight) + { + extraBodding = Math.ceil((lineHeight - backgroundHeight) / 2); + extraTodding = lineHeight - backgroundHeight - extraBodding; } var spanStyle = dynamicCSS.selectorStyle("#innerdocbody span"); - spanStyle.paddingTop = extraTodding+"px"; - spanStyle.paddingBottom = extraBodding+"px"; + spanStyle.paddingTop = extraTodding + "px"; + spanStyle.paddingBottom = extraBodding + "px"; } } - function boldColorFromColor(lightColorCSS) { + + function boldColorFromColor(lightColorCSS) + { var color = colorutils.css2triple(lightColorCSS); // amp up the saturation to full @@ -206,128 +271,174 @@ function OUTER(gscope) { return colorutils.triple2css(color); } - function fadeColor(colorCSS, fadeFrac) { + + function fadeColor(colorCSS, fadeFrac) + { var color = colorutils.css2triple(colorCSS); - color = colorutils.blend(color, [1,1,1], fadeFrac); + color = colorutils.blend(color, [1, 1, 1], fadeFrac); return colorutils.triple2css(color); } - function doAlert(str) { - scheduler.setTimeout(function() { alert(str); }, 0); + function doAlert(str) + { + scheduler.setTimeout(function() + { + alert(str); + }, 0); } - editorInfo.ace_getRep = function () { + editorInfo.ace_getRep = function() + { return rep; } var currentCallStack = null; - function inCallStack(type, action) { + + function inCallStack(type, action) + { if (disposed) return; - if (currentCallStack) { - console.error("Can't enter callstack "+type+", already in "+ - currentCallStack.type); + if (currentCallStack) + { + console.error("Can't enter callstack " + type + ", already in " + currentCallStack.type); } var profiling = false; - function profileRest() { + + function profileRest() + { profiling = true; console.profile(); } - function newEditEvent(eventType) { - return {eventType:eventType, backset: null}; + function newEditEvent(eventType) + { + return { + eventType: eventType, + backset: null + }; } - function submitOldEvent(evt) { - if (rep.selStart && rep.selEnd) { - var selStartChar = - rep.lines.offsetOfIndex(rep.selStart[0]) + rep.selStart[1]; - var selEndChar = - rep.lines.offsetOfIndex(rep.selEnd[0]) + rep.selEnd[1]; - evt.selStart = selStartChar; - evt.selEnd = selEndChar; - evt.selFocusAtStart = rep.selFocusAtStart; + function submitOldEvent(evt) + { + if (rep.selStart && rep.selEnd) + { + var selStartChar = rep.lines.offsetOfIndex(rep.selStart[0]) + rep.selStart[1]; + var selEndChar = rep.lines.offsetOfIndex(rep.selEnd[0]) + rep.selEnd[1]; + evt.selStart = selStartChar; + evt.selEnd = selEndChar; + evt.selFocusAtStart = rep.selFocusAtStart; } - if (undoModule.enabled) { - var undoWorked = false; - try { - if (evt.eventType == "setup" || evt.eventType == "importText" || - evt.eventType == "setBaseText") { - undoModule.clearHistory(); - } - else if (evt.eventType == "nonundoable") { - if (evt.changeset) { - undoModule.reportExternalChange(evt.changeset); - } - } - else { - undoModule.reportEvent(evt); - } - undoWorked = true; - } - finally { - if (! undoWorked) { - undoModule.enabled = false; // for safety - } - } + if (undoModule.enabled) + { + var undoWorked = false; + try + { + if (evt.eventType == "setup" || evt.eventType == "importText" || evt.eventType == "setBaseText") + { + undoModule.clearHistory(); + } + else if (evt.eventType == "nonundoable") + { + if (evt.changeset) + { + undoModule.reportExternalChange(evt.changeset); + } + } + else + { + undoModule.reportEvent(evt); + } + undoWorked = true; + } + finally + { + if (!undoWorked) + { + undoModule.enabled = false; // for safety + } + } } } - function startNewEvent(eventType, dontSubmitOld) { + function startNewEvent(eventType, dontSubmitOld) + { var oldEvent = currentCallStack.editEvent; - if (! dontSubmitOld) { - submitOldEvent(oldEvent); + if (!dontSubmitOld) + { + submitOldEvent(oldEvent); } currentCallStack.editEvent = newEditEvent(eventType); return oldEvent; } - currentCallStack = {type: type, docTextChanged: false, selectionAffected: false, - userChangedSelection: false, - domClean: false, profileRest:profileRest, - isUserChange: false, // is this a "user change" type of call-stack - repChanged: false, editEvent: newEditEvent(type), - startNewEvent:startNewEvent}; + currentCallStack = { + type: type, + docTextChanged: false, + selectionAffected: false, + userChangedSelection: false, + domClean: false, + profileRest: profileRest, + isUserChange: false, + // is this a "user change" type of call-stack + repChanged: false, + editEvent: newEditEvent(type), + startNewEvent: startNewEvent + }; var cleanExit = false; var result; - try { + try + { result = action(); //console.log("Just did action for: "+type); cleanExit = true; } - catch (e) { - caughtErrors.push({error: e, time: +new Date()}); + catch (e) + { + caughtErrors.push( + { + error: e, + time: +new Date() + }); dmesg(e.toString()); throw e; } - finally { + finally + { var cs = currentCallStack; //console.log("Finished action for: "+type); - if (cleanExit) { - submitOldEvent(cs.editEvent); - if (cs.domClean && cs.type != "setup") { - if (cs.isUserChange) { - if (cs.repChanged) parenModule.notifyChange(); - else parenModule.notifyTick(); - } - recolorModule.recolorLines(); - if (cs.selectionAffected) { - updateBrowserSelectionFromRep(); - } - if ((cs.docTextChanged || cs.userChangedSelection) && cs.type != "applyChangesToBase") { - scrollSelectionIntoView(); - } - if (cs.docTextChanged && cs.type.indexOf("importText") < 0) { - outsideNotifyDirty(); - } - } + if (cleanExit) + { + submitOldEvent(cs.editEvent); + if (cs.domClean && cs.type != "setup") + { + if (cs.isUserChange) + { + if (cs.repChanged) parenModule.notifyChange(); + else parenModule.notifyTick(); + } + recolorModule.recolorLines(); + if (cs.selectionAffected) + { + updateBrowserSelectionFromRep(); + } + if ((cs.docTextChanged || cs.userChangedSelection) && cs.type != "applyChangesToBase") + { + scrollSelectionIntoView(); + } + if (cs.docTextChanged && cs.type.indexOf("importText") < 0) + { + outsideNotifyDirty(); + } + } } - else { - // non-clean exit - if (currentCallStack.type == "idleWorkTimer") { - idleWorkTimer.atLeast(1000); - } + else + { + // non-clean exit + if (currentCallStack.type == "idleWorkTimer") + { + idleWorkTimer.atLeast(1000); + } } currentCallStack = null; if (profiling) console.profileEnd(); @@ -336,59 +447,74 @@ function OUTER(gscope) { } editorInfo.ace_inCallStack = inCallStack; - function inCallStackIfNecessary(type, action) { - if (! currentCallStack) { + function inCallStackIfNecessary(type, action) + { + if (!currentCallStack) + { inCallStack(type, action); } - else { + else + { action(); } } editorInfo.ace_inCallStackIfNecessary = inCallStackIfNecessary; - function recolorLineByKey(key) { - if (rep.lines.containsKey(key)) { + function recolorLineByKey(key) + { + if (rep.lines.containsKey(key)) + { var offset = rep.lines.offsetOfKey(key); var width = rep.lines.atKey(key).width; recolorLinesInRange(offset, offset + width); } } - function getLineKeyForOffset(charOffset) { + function getLineKeyForOffset(charOffset) + { return rep.lines.atOffset(charOffset).key; } - var recolorModule = (function() { + var recolorModule = (function() + { var dirtyLineKeys = {}; var module = {}; - module.setCharNeedsRecoloring = function(offset) { - if (offset >= rep.alltext.length) { - offset = rep.alltext.length-1; + module.setCharNeedsRecoloring = function(offset) + { + if (offset >= rep.alltext.length) + { + offset = rep.alltext.length - 1; } dirtyLineKeys[getLineKeyForOffset(offset)] = true; } - module.setCharRangeNeedsRecoloring = function(offset1, offset2) { - if (offset1 >= rep.alltext.length) { - offset1 = rep.alltext.length-1; + module.setCharRangeNeedsRecoloring = function(offset1, offset2) + { + if (offset1 >= rep.alltext.length) + { + offset1 = rep.alltext.length - 1; } - if (offset2 >= rep.alltext.length) { - offset2 = rep.alltext.length-1; + if (offset2 >= rep.alltext.length) + { + offset2 = rep.alltext.length - 1; } var firstEntry = rep.lines.atOffset(offset1); var lastKey = rep.lines.atOffset(offset2).key; dirtyLineKeys[lastKey] = true; var entry = firstEntry; - while (entry && entry.key != lastKey) { - dirtyLineKeys[entry.key] = true; - entry = rep.lines.next(entry); + while (entry && entry.key != lastKey) + { + dirtyLineKeys[entry.key] = true; + entry = rep.lines.next(entry); } } - module.recolorLines = function() { - for(var k in dirtyLineKeys) { - recolorLineByKey(k); + module.recolorLines = function() + { + for (var k in dirtyLineKeys) + { + recolorLineByKey(k); } dirtyLineKeys = {}; } @@ -396,286 +522,382 @@ function OUTER(gscope) { return module; })(); - var parenModule = (function() { + var parenModule = (function() + { var module = {}; - module.notifyTick = function() { handleFlashing(false); }; - module.notifyChange = function() { handleFlashing(true); }; - module.shouldNormalizeOnChar = function (c) { - if (parenFlashRep.active) { - // avoid highlight style from carrying on to typed text - return true; + module.notifyTick = function() + { + handleFlashing(false); + }; + module.notifyChange = function() + { + handleFlashing(true); + }; + module.shouldNormalizeOnChar = function(c) + { + if (parenFlashRep.active) + { + // avoid highlight style from carrying on to typed text + return true; } c = String.fromCharCode(c); - return !! (bracketMap[c]); + return !!(bracketMap[c]); } - var parenFlashRep = { active: false, whichChars: null, whichLineKeys: null, expireTime: null }; - var bracketMap = {'(': 1, ')':-1, '[':2, ']':-2, '{':3, '}':-3}; + var parenFlashRep = { + active: false, + whichChars: null, + whichLineKeys: null, + expireTime: null + }; + var bracketMap = { + '(': 1, + ')': -1, + '[': 2, + ']': -2, + '{': 3, + '}': -3 + }; var bracketRegex = /[{}\[\]()]/g; - function handleFlashing(docChanged) { - function getSearchRange(aroundLoc) { - var rng = getVisibleCharRange(); - var d = 100; // minimum radius - var e = 3000; // maximum radius; - if (rng[0] > aroundLoc-d) rng[0] = aroundLoc-d; - if (rng[0] < aroundLoc-e) rng[0] = aroundLoc-e; - if (rng[0] < 0) rng[0] = 0; - if (rng[1] < aroundLoc+d) rng[1] = aroundLoc+d; - if (rng[1] > aroundLoc+e) rng[1] = aroundLoc+e; - if (rng[1] > rep.lines.totalWidth()) rng[1] = rep.lines.totalWidth(); - return rng; + + function handleFlashing(docChanged) + { + function getSearchRange(aroundLoc) + { + var rng = getVisibleCharRange(); + var d = 100; // minimum radius + var e = 3000; // maximum radius; + if (rng[0] > aroundLoc - d) rng[0] = aroundLoc - d; + if (rng[0] < aroundLoc - e) rng[0] = aroundLoc - e; + if (rng[0] < 0) rng[0] = 0; + if (rng[1] < aroundLoc + d) rng[1] = aroundLoc + d; + if (rng[1] > aroundLoc + e) rng[1] = aroundLoc + e; + if (rng[1] > rep.lines.totalWidth()) rng[1] = rep.lines.totalWidth(); + return rng; } - function findMatchingVisibleBracket(startLoc, forwards) { - var rng = getSearchRange(startLoc); - var str = rep.alltext.substring(rng[0], rng[1]); - var bstr = str.replace(bracketRegex, '('); // handy for searching - var loc = startLoc - rng[0]; - var bracketState = []; - var foundParen = false; - var goodParen = false; - function nextLoc() { - if (loc < 0) return; - if (forwards) loc++; else loc--; - if (loc < 0 || loc >= str.length) loc = -1; - if (loc >= 0) { - if (forwards) loc = bstr.indexOf('(', loc); - else loc = bstr.lastIndexOf('(', loc); - } - } - while ((! foundParen) && (loc >= 0)) { - if (getCharType(loc + rng[0]) == "p") { - var b = bracketMap[str.charAt(loc)]; // -1, 1, -2, 2, -3, 3 - var into = forwards; - var typ = b; - if (typ < 0) { into = ! into; typ = -typ; } - if (into) bracketState.push(typ); - else { - var recent = bracketState.pop(); - if (recent != typ) { - foundParen = true; goodParen = false; - } - else if (bracketState.length == 0) { - foundParen = true; goodParen = true; - } - } - } - //console.log(bracketState.toSource()); - if ((! foundParen) && (loc >= 0)) nextLoc(); - } - if (! foundParen) return null; - return {chr: (loc + rng[0]), good: goodParen}; + + function findMatchingVisibleBracket(startLoc, forwards) + { + var rng = getSearchRange(startLoc); + var str = rep.alltext.substring(rng[0], rng[1]); + var bstr = str.replace(bracketRegex, '('); // handy for searching + var loc = startLoc - rng[0]; + var bracketState = []; + var foundParen = false; + var goodParen = false; + + function nextLoc() + { + if (loc < 0) return; + if (forwards) loc++; + else loc--; + if (loc < 0 || loc >= str.length) loc = -1; + if (loc >= 0) + { + if (forwards) loc = bstr.indexOf('(', loc); + else loc = bstr.lastIndexOf('(', loc); + } + } + while ((!foundParen) && (loc >= 0)) + { + if (getCharType(loc + rng[0]) == "p") + { + var b = bracketMap[str.charAt(loc)]; // -1, 1, -2, 2, -3, 3 + var into = forwards; + var typ = b; + if (typ < 0) + { + into = !into; + typ = -typ; + } + if (into) bracketState.push(typ); + else + { + var recent = bracketState.pop(); + if (recent != typ) + { + foundParen = true; + goodParen = false; + } + else if (bracketState.length == 0) + { + foundParen = true; + goodParen = true; + } + } + } + //console.log(bracketState.toSource()); + if ((!foundParen) && (loc >= 0)) nextLoc(); + } + if (!foundParen) return null; + return { + chr: (loc + rng[0]), + good: goodParen + }; } var r = parenFlashRep; var charsToHighlight = null; var linesToUnhighlight = null; - if (r.active && (docChanged || (now() > r.expireTime))) { - linesToUnhighlight = r.whichLineKeys; - r.active = false; + if (r.active && (docChanged || (now() > r.expireTime))) + { + linesToUnhighlight = r.whichLineKeys; + r.active = false; } - if ((! r.active) && docChanged && isCaret() && caretColumn() > 0) { - var caret = caretDocChar(); - if (caret > 0 && getCharType(caret-1) == "p") { - var charBefore = rep.alltext.charAt(caret-1); - if (bracketMap[charBefore]) { - var lookForwards = (bracketMap[charBefore] > 0); - var findResult = findMatchingVisibleBracket(caret-1, lookForwards); - if (findResult) { - var mateLoc = findResult.chr; - var mateGood = findResult.good; - r.active = true; - charsToHighlight = {}; - charsToHighlight[caret-1] = 'flash'; - charsToHighlight[mateLoc] = (mateGood ? 'flash' : 'flashbad'); - r.whichLineKeys = []; - r.whichLineKeys.push(getLineKeyForOffset(caret-1)); - r.whichLineKeys.push(getLineKeyForOffset(mateLoc)); - r.expireTime = now() + 4000; - newlyActive = true; - } - } - } + if ((!r.active) && docChanged && isCaret() && caretColumn() > 0) + { + var caret = caretDocChar(); + if (caret > 0 && getCharType(caret - 1) == "p") + { + var charBefore = rep.alltext.charAt(caret - 1); + if (bracketMap[charBefore]) + { + var lookForwards = (bracketMap[charBefore] > 0); + var findResult = findMatchingVisibleBracket(caret - 1, lookForwards); + if (findResult) + { + var mateLoc = findResult.chr; + var mateGood = findResult.good; + r.active = true; + charsToHighlight = {}; + charsToHighlight[caret - 1] = 'flash'; + charsToHighlight[mateLoc] = (mateGood ? 'flash' : 'flashbad'); + r.whichLineKeys = []; + r.whichLineKeys.push(getLineKeyForOffset(caret - 1)); + r.whichLineKeys.push(getLineKeyForOffset(mateLoc)); + r.expireTime = now() + 4000; + newlyActive = true; + } + } + } } - if (linesToUnhighlight) { - recolorLineByKey(linesToUnhighlight[0]); - recolorLineByKey(linesToUnhighlight[1]); + if (linesToUnhighlight) + { + recolorLineByKey(linesToUnhighlight[0]); + recolorLineByKey(linesToUnhighlight[1]); } - if (r.active && charsToHighlight) { - function f(txt, cls, next, ofst) { - var flashClass = charsToHighlight[ofst]; - if (cls) { - next(txt, cls+" "+flashClass); - } - else next(txt, cls); - } - for(var c in charsToHighlight) { - recolorLinesInRange((+c), (+c)+1, null, f); - } + if (r.active && charsToHighlight) + { + function f(txt, cls, next, ofst) + { + var flashClass = charsToHighlight[ofst]; + if (cls) + { + next(txt, cls + " " + flashClass); + } + else next(txt, cls); + } + for (var c in charsToHighlight) + { + recolorLinesInRange((+c), (+c) + 1, null, f); + } } } return module; })(); - function dispose() { + function dispose() + { disposed = true; if (idleWorkTimer) idleWorkTimer.never(); teardown(); } - function checkALines() { + function checkALines() + { return; // disable for speed - function error() { throw new Error("checkALines"); } - if (rep.alines.length != rep.lines.length()) { + + + function error() + { + throw new Error("checkALines"); + } + if (rep.alines.length != rep.lines.length()) + { error(); } - for(var i=0;i