Merge pull request #992 from gedion/develop

Added hooks and made some ace functions available to editorInfo Object
This commit is contained in:
John McLear 2012-09-14 04:51:17 -07:00
commit e9e3ea305b
3 changed files with 85 additions and 12 deletions

View File

@ -200,6 +200,11 @@ function Ace2Inner(){
var authorInfos = {}; // presence of key determines if author is present in doc var authorInfos = {}; // presence of key determines if author is present in doc
function getAuthorInfos(){
return authorInfos;
};
editorInfo.ace_getAuthorInfos= getAuthorInfos;
function setAuthorInfo(author, info) function setAuthorInfo(author, info)
{ {
if ((typeof author) != "string") if ((typeof author) != "string")
@ -884,6 +889,13 @@ function Ace2Inner(){
editorInfo.ace_setEditable = setEditable; editorInfo.ace_setEditable = setEditable;
editorInfo.ace_execCommand = execCommand; editorInfo.ace_execCommand = execCommand;
editorInfo.ace_replaceRange = replaceRange; 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) editorInfo.ace_callWithAce = function(fn, callStack, normalize)
{ {
@ -1685,11 +1697,27 @@ function Ace2Inner(){
if (selection && !selStart) if (selection && !selStart)
{ {
//if (domChanges) dmesg("selection not collected"); //if (domChanges) dmesg("selection not collected");
selStart = getLineAndCharForPoint(selection.startPoint); var selStartFromHook = hooks.callAll('aceStartLineAndCharForPoint', {
callstack: currentCallStack,
editorInfo: editorInfo,
rep: rep,
root:root,
point:selection.startPoint,
documentAttributeManager: documentAttributeManager
});
selStart = (selStartFromHook==null||selStartFromHook.length==0)?getLineAndCharForPoint(selection.startPoint):selStartFromHook;
} }
if (selection && !selEnd) if (selection && !selEnd)
{ {
selEnd = getLineAndCharForPoint(selection.endPoint); var selEndFromHook = hooks.callAll('aceEndLineAndCharForPoint', {
callstack: currentCallStack,
editorInfo: editorInfo,
rep: rep,
root:root,
point:selection.endPoint,
documentAttributeManager: documentAttributeManager
});
selEnd = (selEndFromHook==null||selEndFromHook.length==0)?getLineAndCharForPoint(selection.endPoint):selEndFromHook;
} }
// selection from content collection can, in various ways, extend past final // selection from content collection can, in various ways, extend past final
@ -1844,16 +1872,19 @@ function Ace2Inner(){
{ {
return rep.selStart[0]; return rep.selStart[0];
} }
editorInfo.ace_caretLine = caretLine;
function caretColumn() function caretColumn()
{ {
return rep.selStart[1]; return rep.selStart[1];
} }
editorInfo.ace_caretColumn = caretColumn;
function caretDocChar() function caretDocChar()
{ {
return rep.lines.offsetOfIndex(caretLine()) + caretColumn(); return rep.lines.offsetOfIndex(caretLine()) + caretColumn();
} }
editorInfo.ace_caretDocChar = caretDocChar;
function handleReturnIndentation() function handleReturnIndentation()
{ {
@ -3446,6 +3477,7 @@ function Ace2Inner(){
{ {
return !!REGEX_WORDCHAR.exec(c); return !!REGEX_WORDCHAR.exec(c);
} }
editorInfo.ace_isWordChar = isWordChar;
function isSpaceChar(c) function isSpaceChar(c)
{ {
@ -3554,7 +3586,15 @@ function Ace2Inner(){
if (!stopped) if (!stopped)
{ {
if (isTypeForSpecialKey && keyCode == 8) 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, // "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. // or else deleting a blank line can take two delete presses.

View File

@ -375,6 +375,19 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
if (dom.isNodeText(node)) if (dom.isNodeText(node))
{ {
var txt = dom.nodeValue(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 = (typeof(txtFromHook)=='object'&&txtFromHook.length==0)?dom.nodeValue(node):txtFromHook[0];
var rest = ''; var rest = '';
var x = 0; // offset into original text var x = 0; // offset into original text
if (txt.length == 0) if (txt.length == 0)
@ -386,7 +399,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
if (endPoint && node == endPoint.node) if (endPoint && node == endPoint.node)
{ {
selEnd = _pointHere(0, state); selEnd = _pointHere(0, state);
} }
} }
while (txt.length > 0) while (txt.length > 0)
{ {
@ -442,7 +455,20 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
var tname = (dom.nodeTagName(node) || "").toLowerCase(); var tname = (dom.nodeTagName(node) || "").toLowerCase();
if (tname == "br") if (tname == "br")
{ {
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
});
var startNewLine= (typeof(induceLineBreak)=='object'&&induceLineBreak.length==0)?true:induceLineBreak[0];
if(startNewLine){
cc.startNewLine(state);
}
} }
else if (tname == "script" || tname == "style") else if (tname == "script" || tname == "style")
{ {

View File

@ -146,9 +146,16 @@ linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFun
return function(txt, cls) 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) while (txt.length > 0)
{ {
if (leftInAuthor <= 0) if (leftInAuthor <= 0 || disableAuthors)
{ {
// prevent infinite loop if something funny's going on // prevent infinite loop if something funny's going on
return nextAfterAuthorColors(txt, cls); return nextAfterAuthorColors(txt, cls);