From a2c8d2124071d668bd3799c166004263d46fcc6a Mon Sep 17 00:00:00 2001 From: Gedion Date: Sat, 8 Sep 2012 12:03:13 -0500 Subject: [PATCH 1/6] added hooks to contentcollector.js --- src/static/js/contentcollector.js | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index b27dfc5e0..bb814212b 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -375,6 +375,17 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class if (dom.isNodeText(node)) { var txt = dom.nodeValue(node); + var tname = dom.nodeAttr(node.parentNode,"name"); + var txtFromHook = hooks.callAll('collectContentLineText', { + cc: this, + state: state, + tname: tname, + node:node, + text:txt, + styl: null, + cls: null + }); + var txt = txtFromHook||txt; var rest = ''; var x = 0; // offset into original text if (txt.length == 0) @@ -441,8 +452,32 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class { var tname = (dom.nodeTagName(node) || "").toLowerCase(); if (tname == "br") + /* + *Called from: src/static/js/contentcollector.js + * + * cc - the contentcollector object + * state - the current state of the change being made + * tname - the tag name of this node currently being processed + * + * This hook is provided to allow Whether the br tag should induce a new magic domline or not. + * The return value should be either true(break the line) or values. + * + */ { cc.startNewLine(state); + this.breakLine = true; + var tvalue = dom.nodeAttr(node, 'value'); + var induceLineBreak = hooks.callAll('collectContentLineBreak', { + cc: this, + state: state, + tname: tname, + tvalue:tvalue, + styl: null, + cls: null + }); + if(induceLineBreak){ + cc.startNewLine(state); + } } else if (tname == "script" || tname == "style") { From 6d1cba225978f76619659eb28e174e3f945d834f Mon Sep 17 00:00:00 2001 From: Gedion Date: Sat, 8 Sep 2012 12:11:04 -0500 Subject: [PATCH 2/6] added hooks to contentcollector.js --- src/static/js/contentcollector.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index bb814212b..a1860cbad 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -376,6 +376,18 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class { var txt = dom.nodeValue(node); var tname = dom.nodeAttr(node.parentNode,"name"); + /* + * Called from: src/static/js/contentcollector.js + * + * Context - + * cc - the contentcollector object + * state - the current state of the change being made + * tname - the tag name of this node currently being processed + * text - the text for that line + * This hook allows you to validate/manipulate the text before it sent to the server side. + * The return value should the validate/manipulated text. + * + */ var txtFromHook = hooks.callAll('collectContentLineText', { cc: this, state: state, @@ -453,14 +465,15 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class var tname = (dom.nodeTagName(node) || "").toLowerCase(); if (tname == "br") /* - *Called from: src/static/js/contentcollector.js + * Called from: src/static/js/contentcollector.js * + * Context - * cc - the contentcollector object * state - the current state of the change being made * tname - the tag name of this node currently being processed * * This hook is provided to allow Whether the br tag should induce a new magic domline or not. - * The return value should be either true(break the line) or values. + * The return value should be either true(break the line) or false. * */ { From c37c48cd12c82bbebf06e6f8d9090196b9533638 Mon Sep 17 00:00:00 2001 From: Gedion Date: Sat, 8 Sep 2012 13:45:33 -0500 Subject: [PATCH 3/6] added hooks and made some functions available to editor info object in ace --- src/static/js/ace2_inner.js | 99 ++++++++++++++++++++++++++++--- src/static/js/contentcollector.js | 26 ++++---- 2 files changed, 104 insertions(+), 21 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 07580faa5..c262deb4c 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -200,6 +200,11 @@ function Ace2Inner(){ var authorInfos = {}; // presence of key determines if author is present in doc + function getAuthorInfos(){ + return authorInfos; + }; + editorInfo.ace_getAuthorInfos= getAuthorInfos; + function setAuthorInfo(author, info) { if ((typeof author) != "string") @@ -884,7 +889,14 @@ function Ace2Inner(){ editorInfo.ace_setEditable = setEditable; editorInfo.ace_execCommand = execCommand; editorInfo.ace_replaceRange = replaceRange; - + editorInfo.ace_getAuthorInfos= getAuthorInfos; + editorInfo.ace_performDocumentReplaceRange = performDocumentReplaceRange; + editorInfo.ace_performDocumentReplaceCharRange = performDocumentReplaceCharRange; + editorInfo.ace_renumberList = renumberList; + editorInfo.ace_doReturnKey = doReturnKey; + editorInfo.ace_isBlockElement = isBlockElement; + editorInfo.ace_getLineListType = getLineListType; + editorInfo.ace_callWithAce = function(fn, callStack, normalize) { var wrapper = function() @@ -1686,11 +1698,55 @@ function Ace2Inner(){ if (selection && !selStart) { //if (domChanges) dmesg("selection not collected"); - selStart = getLineAndCharForPoint(selection.startPoint); + /* + * Called from: src/static/js/ace2_inner.js + * + * Context - + * callstack - a bunch of information about the current action + * editorInfo - information about the user who is making the change + * rep - information about where the change is being made + * root - the span element of the current line + * point - the starting element where the cursor currently resides + * documentAttributeManager - information about attributes in the document + * This hook is provided to allow a plugin to turn DOM node selection into [line,char] selection. + * The return value should be an array of [line,char] + * + */ + var selStartFromHook = hooks.callAll('aceStartLineAndCharForPoint', { + callstack: currentCallStack, + editorInfo: editorInfo, + rep: rep, + root:root, + point:selection.startPoint, + documentAttributeManager: documentAttributeManager + }); + selStart = selStartFromHook || getLineAndCharForPoint(selection.startPoint); } if (selection && !selEnd) { - selEnd = getLineAndCharForPoint(selection.endPoint); + /* + * Called from: src/static/js/ace2_inner.js + * + * Context - + * callstack - a bunch of information about the current action + * editorInfo - information about the user who is making the change + * rep - information about where the change is being made + * root - the span element of the current line + * point - the ending element where the cursor currently resides + * documentAttributeManager - information about attributes in the document + * This hook is provided to allow a plugin to turn DOM node selection into [line,char] selection. + * The return value should be an array of [line,char] + * + */ + var selEndFromHook = hooks.callAll('aceEndLineAndCharForPoint', { + callstack: currentCallStack, + editorInfo: editorInfo, + rep: rep, + root:root, + point:selection.endPoint, + documentAttributeManager: documentAttributeManager + }); + selEnd = selEndFromHook || getLineAndCharForPoint(selection.endPoint); } // selection from content collection can, in various ways, extend past final @@ -1845,17 +1901,20 @@ function Ace2Inner(){ { return rep.selStart[0]; } - + editorInfo.ace_caretLine = caretLine; + function caretColumn() { return rep.selStart[1]; } - + editorInfo.ace_caretColumn = caretColumn; + function caretDocChar() { return rep.lines.offsetOfIndex(caretLine()) + caretColumn(); } - + editorInfo.ace_caretDocChar = caretDocChar; + function handleReturnIndentation() { // on return, indent to level of previous line @@ -3447,7 +3506,8 @@ function Ace2Inner(){ { return !!REGEX_WORDCHAR.exec(c); } - + editorInfo.ace_isWordChar = isWordChar; + function isSpaceChar(c) { return !!REGEX_SPACE.exec(c); @@ -3555,7 +3615,30 @@ function Ace2Inner(){ if (!stopped) { - if (isTypeForSpecialKey && keyCode == 8) + /* + * Called from: src/static/js/ace2_inner.js + * + * Context - + * callstack - a bunch of information about the current action + * editorInfo - information about the user who is making the change + * rep - information about where the change is being made + * documentAttributeManager - information about attributes in the document + * evt - the fired event + * + * This hook is provided to allow a plugin to handle key events. + * The return value should true if you have handled the event. + * + */ + editorInfo.specialHandled = null; + specialHandled = hooks.callAll('aceKeyEvent', { + callstack: currentCallStack, + editorInfo: editorInfo, + rep: rep, + documentAttributeManager: documentAttributeManager, + evt:evt + }); + + if ((!specialHandled) && isTypeForSpecialKey && keyCode == 8) { // "delete" key; in mozilla, if we're at the beginning of a line, normalize now, // or else deleting a blank line can take two delete presses. diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index a1860cbad..27d2940ab 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -376,18 +376,18 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class { var txt = dom.nodeValue(node); var tname = dom.nodeAttr(node.parentNode,"name"); - /* - * Called from: src/static/js/contentcollector.js - * - * Context - - * cc - the contentcollector object - * state - the current state of the change being made - * tname - the tag name of this node currently being processed - * text - the text for that line - * This hook allows you to validate/manipulate the text before it sent to the server side. - * The return value should the validate/manipulated text. - * - */ + /* + * Called from: src/static/js/contentcollector.js + * + * Context - + * cc - the contentcollector object + * state - the current state of the change being made + * tname - the tag name of this node currently being processed + * text - the text for that line + * This hook allows you to validate/manipulate the text before it sent to the server side. + * The return value should be the validated/manipulated text. + * + */ var txtFromHook = hooks.callAll('collectContentLineText', { cc: this, state: state, @@ -472,7 +472,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class * state - the current state of the change being made * tname - the tag name of this node currently being processed * - * This hook is provided to allow Whether the br tag should induce a new magic domline or not. + * This hook is provided to allow whether the br tag should induce a new magic domline or not. * The return value should be either true(break the line) or false. * */ From 9be69ef2582dfc2c1b050041d4586cbd90d20e2c Mon Sep 17 00:00:00 2001 From: Gedion Date: Tue, 11 Sep 2012 16:21:14 -0500 Subject: [PATCH 4/6] fixed plugins --- src/static/js/ace2_inner.js | 13 ++++++------- src/static/js/contentcollector.js | 14 ++++++++------ src/static/js/linestylefilter.js | 9 ++++++++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index c262deb4c..4251d8786 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -1719,8 +1719,8 @@ function Ace2Inner(){ root:root, point:selection.startPoint, documentAttributeManager: documentAttributeManager - }); - selStart = selStartFromHook || getLineAndCharForPoint(selection.startPoint); + }); + selStart = (selStartFromHook==null||selStartFromHook.length==0)?getLineAndCharForPoint(selection.startPoint):selStartFromHook; } if (selection && !selEnd) { @@ -1746,7 +1746,7 @@ function Ace2Inner(){ point:selection.endPoint, documentAttributeManager: documentAttributeManager }); - selEnd = selEndFromHook || getLineAndCharForPoint(selection.endPoint); + selEnd = (selEndFromHook==null||selEndFromHook.length==0)?getLineAndCharForPoint(selection.endPoint):selEndFromHook; } // selection from content collection can, in various ways, extend past final @@ -3628,16 +3628,15 @@ function Ace2Inner(){ * This hook is provided to allow a plugin to handle key events. * The return value should true if you have handled the event. * - */ - editorInfo.specialHandled = null; - specialHandled = hooks.callAll('aceKeyEvent', { + */ + var specialHandledInHook = hooks.callAll('aceKeyEvent', { callstack: currentCallStack, editorInfo: editorInfo, rep: rep, documentAttributeManager: documentAttributeManager, evt:evt }); - + specialHandled = (specialHandledInHook&&specialHandledInHook.length>0)?specialHandledInHook[0]:specialHandled; if ((!specialHandled) && isTypeForSpecialKey && keyCode == 8) { // "delete" key; in mozilla, if we're at the beginning of a line, normalize now, diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 27d2940ab..1f1f5f202 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -388,6 +388,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class * The return value should be the validated/manipulated text. * */ + //top.console.log(' nodevalue ',txt); var txtFromHook = hooks.callAll('collectContentLineText', { cc: this, state: state, @@ -397,7 +398,8 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class styl: null, cls: null }); - var txt = txtFromHook||txt; + var txt = (typeof(txtFromHook)=='object'&&txtFromHook.length==0)?dom.nodeValue(node):txtFromHook[0]; + var rest = ''; var x = 0; // offset into original text if (txt.length == 0) @@ -409,7 +411,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class if (endPoint && node == endPoint.node) { selEnd = _pointHere(0, state); - } + } } while (txt.length > 0) { @@ -476,8 +478,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class * The return value should be either true(break the line) or false. * */ - { - cc.startNewLine(state); + { this.breakLine = true; var tvalue = dom.nodeAttr(node, 'value'); var induceLineBreak = hooks.callAll('collectContentLineBreak', { @@ -487,8 +488,9 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class tvalue:tvalue, styl: null, cls: null - }); - if(induceLineBreak){ + }); + var startNewLine= (typeof(induceLineBreak)=='object'&&induceLineBreak.length==0)?true:induceLineBreak[0]; + if(startNewLine){ cc.startNewLine(state); } } diff --git a/src/static/js/linestylefilter.js b/src/static/js/linestylefilter.js index 1cbfac29c..7da27b1df 100644 --- a/src/static/js/linestylefilter.js +++ b/src/static/js/linestylefilter.js @@ -146,9 +146,16 @@ linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFun return function(txt, cls) { + + var disableAuthColorForThisLine = hooks.callAll("disableAuthorColorsForThisLine", { + linestylefilter: linestylefilter, + text: txt, + class: cls + }, " ", " ", ""); + var disableAuthors = (disableAuthColorForThisLine==null||disableAuthColorForThisLine.length==0)?false:disableAuthColorForThisLine[0]; while (txt.length > 0) { - if (leftInAuthor <= 0) + if (leftInAuthor <= 0 || disableAuthors) { // prevent infinite loop if something funny's going on return nextAfterAuthorColors(txt, cls); From 3364eb131e93b83c3cd889011e648a2a91778a61 Mon Sep 17 00:00:00 2001 From: Gedion Date: Tue, 11 Sep 2012 17:02:53 -0500 Subject: [PATCH 5/6] fixed comments --- src/static/js/ace2_inner.js | 44 +------------------------------ src/static/js/contentcollector.js | 26 +----------------- 2 files changed, 2 insertions(+), 68 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 4251d8786..9028dfcbe 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -1698,20 +1698,6 @@ function Ace2Inner(){ if (selection && !selStart) { //if (domChanges) dmesg("selection not collected"); - /* - * Called from: src/static/js/ace2_inner.js - * - * Context - - * callstack - a bunch of information about the current action - * editorInfo - information about the user who is making the change - * rep - information about where the change is being made - * root - the span element of the current line - * point - the starting element where the cursor currently resides - * documentAttributeManager - information about attributes in the document - * This hook is provided to allow a plugin to turn DOM node selection into [line,char] selection. - * The return value should be an array of [line,char] - * - */ var selStartFromHook = hooks.callAll('aceStartLineAndCharForPoint', { callstack: currentCallStack, editorInfo: editorInfo, @@ -1724,20 +1710,6 @@ function Ace2Inner(){ } if (selection && !selEnd) { - /* - * Called from: src/static/js/ace2_inner.js - * - * Context - - * callstack - a bunch of information about the current action - * editorInfo - information about the user who is making the change - * rep - information about where the change is being made - * root - the span element of the current line - * point - the ending element where the cursor currently resides - * documentAttributeManager - information about attributes in the document - * This hook is provided to allow a plugin to turn DOM node selection into [line,char] selection. - * The return value should be an array of [line,char] - * - */ var selEndFromHook = hooks.callAll('aceEndLineAndCharForPoint', { callstack: currentCallStack, editorInfo: editorInfo, @@ -3615,20 +3587,6 @@ function Ace2Inner(){ if (!stopped) { - /* - * Called from: src/static/js/ace2_inner.js - * - * Context - - * callstack - a bunch of information about the current action - * editorInfo - information about the user who is making the change - * rep - information about where the change is being made - * documentAttributeManager - information about attributes in the document - * evt - the fired event - * - * This hook is provided to allow a plugin to handle key events. - * The return value should true if you have handled the event. - * - */ var specialHandledInHook = hooks.callAll('aceKeyEvent', { callstack: currentCallStack, editorInfo: editorInfo, @@ -3636,7 +3594,7 @@ function Ace2Inner(){ documentAttributeManager: documentAttributeManager, evt:evt }); - specialHandled = (specialHandledInHook&&specialHandledInHook.length>0)?specialHandledInHook[0]:specialHandled; + specialHandled = (specialHandledInHook&&specialHandledInHook.length>0)?specialHandledInHook[0]:specialHandled; if ((!specialHandled) && isTypeForSpecialKey && keyCode == 8) { // "delete" key; in mozilla, if we're at the beginning of a line, normalize now, diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 1f1f5f202..c1687489c 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -376,19 +376,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class { var txt = dom.nodeValue(node); var tname = dom.nodeAttr(node.parentNode,"name"); - /* - * Called from: src/static/js/contentcollector.js - * - * Context - - * cc - the contentcollector object - * state - the current state of the change being made - * tname - the tag name of this node currently being processed - * text - the text for that line - * This hook allows you to validate/manipulate the text before it sent to the server side. - * The return value should be the validated/manipulated text. - * - */ - //top.console.log(' nodevalue ',txt); + var txtFromHook = hooks.callAll('collectContentLineText', { cc: this, state: state, @@ -466,18 +454,6 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class { var tname = (dom.nodeTagName(node) || "").toLowerCase(); if (tname == "br") - /* - * Called from: src/static/js/contentcollector.js - * - * Context - - * cc - the contentcollector object - * state - the current state of the change being made - * tname - the tag name of this node currently being processed - * - * This hook is provided to allow whether the br tag should induce a new magic domline or not. - * The return value should be either true(break the line) or false. - * - */ { this.breakLine = true; var tvalue = dom.nodeAttr(node, 'value'); From a25feed1c2750c52e9aa43661b44fe2fb1aa53b5 Mon Sep 17 00:00:00 2001 From: Gedion Date: Tue, 11 Sep 2012 17:49:58 -0500 Subject: [PATCH 6/6] fixed indentation --- src/static/js/linestylefilter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/linestylefilter.js b/src/static/js/linestylefilter.js index 7da27b1df..4231d26b6 100644 --- a/src/static/js/linestylefilter.js +++ b/src/static/js/linestylefilter.js @@ -147,7 +147,7 @@ linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFun return function(txt, cls) { - var disableAuthColorForThisLine = hooks.callAll("disableAuthorColorsForThisLine", { + var disableAuthColorForThisLine = hooks.callAll("disableAuthorColorsForThisLine", { linestylefilter: linestylefilter, text: txt, class: cls