mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
Merge pull request #992 from gedion/develop
Added hooks and made some ace functions available to editorInfo Object
This commit is contained in:
commit
e9e3ea305b
3 changed files with 85 additions and 12 deletions
|
@ -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()
|
||||
|
@ -1685,11 +1697,27 @@ function Ace2Inner(){
|
|||
if (selection && !selStart)
|
||||
{
|
||||
//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)
|
||||
{
|
||||
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
|
||||
|
@ -1844,17 +1872,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
|
||||
|
@ -3446,7 +3477,8 @@ function Ace2Inner(){
|
|||
{
|
||||
return !!REGEX_WORDCHAR.exec(c);
|
||||
}
|
||||
|
||||
editorInfo.ace_isWordChar = isWordChar;
|
||||
|
||||
function isSpaceChar(c)
|
||||
{
|
||||
return !!REGEX_SPACE.exec(c);
|
||||
|
@ -3554,7 +3586,15 @@ function Ace2Inner(){
|
|||
|
||||
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,
|
||||
// or else deleting a blank line can take two delete presses.
|
||||
|
|
|
@ -375,6 +375,19 @@ 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 = (typeof(txtFromHook)=='object'&&txtFromHook.length==0)?dom.nodeValue(node):txtFromHook[0];
|
||||
|
||||
var rest = '';
|
||||
var x = 0; // offset into original text
|
||||
if (txt.length == 0)
|
||||
|
@ -386,7 +399,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
|
|||
if (endPoint && node == endPoint.node)
|
||||
{
|
||||
selEnd = _pointHere(0, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (txt.length > 0)
|
||||
{
|
||||
|
@ -441,8 +454,21 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
|
|||
{
|
||||
var tname = (dom.nodeTagName(node) || "").toLowerCase();
|
||||
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")
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue