mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-04-07 14:09:12 +08:00
[de][bu] Implement ability to get part of the Current Sentence via plugin method
This commit is contained in:
@ -212,6 +212,27 @@ $(function () {
|
||||
PluginsApi.pluginMethod_ReplaceCurrentWord("654", "beforeCursor");
|
||||
assert.strictEqual(AscTest.GetParagraphText(p), "654123 text", "Replace the part of the word before cursor");
|
||||
|
||||
|
||||
AscTest.ClearDocument();
|
||||
p = MoveToNewParagraph();
|
||||
AscTest.EnterText("The quick brown fox jumps over the lazy dog. The five boxing wizards jump quickly. Eat more of those fresh french loafs and drink a tea!");
|
||||
AscTest.MoveCursorToParagraph(p, true);
|
||||
AscTest.MoveCursorRight(false, false, 16);
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("entirely"), "The quick brown fox jumps over the lazy dog.", "Check current sentence");
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("afterCursor"), "fox jumps over the lazy dog.", "Check the right part of the current sentence");
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("beforeCursor"), "The quick brown ", "Check the left part of the current sentence");
|
||||
|
||||
AscTest.MoveCursorRight(false, false, 28);
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("entirely"), "The five boxing wizards jump quickly.", "Check current sentence");
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("afterCursor"), "The five boxing wizards jump quickly.", "Check the right part of the current sentence");
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("beforeCursor"), "", "Check the left part of the current sentence");
|
||||
|
||||
AscTest.MoveCursorToParagraph(p, false);
|
||||
AscTest.MoveCursorLeft(false, false, 1);
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("entirely"), "Eat more of those fresh french loafs and drink a tea!", "Check current sentence");
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("afterCursor"), "!", "Check the right part of the current sentence");
|
||||
assert.strictEqual(PluginsApi.pluginMethod_GetCurrentSentence("beforeCursor"), "Eat more of those fresh french loafs and drink a tea", "Check the left part of the current sentence");
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
@ -17515,11 +17515,15 @@ Paragraph.prototype.GetCurrentSentence = function(nDirection)
|
||||
{
|
||||
startPos = oInfo.Start;
|
||||
endPos = this.Get_ParaContentPos(false, false);
|
||||
if (endPos.Compare(startPos) < 0)
|
||||
endPos = startPos.Copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
startPos = this.Get_ParaContentPos(false, false);
|
||||
endPos = oInfo.End;
|
||||
if (startPos.Compare(oInfo.Start) < 0)
|
||||
startPos = oInfo.Start;
|
||||
}
|
||||
|
||||
this.Selection.Use = true;
|
||||
|
||||
@ -1183,22 +1183,7 @@
|
||||
if (!logicDocument)
|
||||
return "";
|
||||
|
||||
let direction = 0;
|
||||
switch (AscBuilder.GetStringParameter(type, "entirely"))
|
||||
{
|
||||
case "beforeCursor":
|
||||
direction = -1;
|
||||
break;
|
||||
case "afterCursor":
|
||||
direction = 1;
|
||||
break;
|
||||
case "entirely":
|
||||
default:
|
||||
direction = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return logicDocument.GetCurrentWord(direction);
|
||||
return logicDocument.GetCurrentWord(private_GetTextDirection(type));
|
||||
};
|
||||
/**
|
||||
* Get the current word
|
||||
@ -1219,39 +1204,25 @@
|
||||
if (!logicDocument || null === _replaceString)
|
||||
return;
|
||||
|
||||
let direction = 0;
|
||||
switch (AscBuilder.GetStringParameter(type, "entirely"))
|
||||
{
|
||||
case "beforeCursor":
|
||||
direction = -1;
|
||||
break;
|
||||
case "afterCursor":
|
||||
direction = 1;
|
||||
break;
|
||||
case "entirely":
|
||||
default:
|
||||
direction = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
logicDocument.ReplaceCurrentWord(direction, _replaceString);
|
||||
logicDocument.ReplaceCurrentWord(private_GetTextDirection(type), _replaceString);
|
||||
};
|
||||
/**
|
||||
* Get the current sentence
|
||||
* @memberof Api
|
||||
* @typeofeditors ["CDE"]
|
||||
* @alias GetCurrentSentence
|
||||
* @param {TextPartType} [type="entirely"]
|
||||
* @since 7.4.0
|
||||
* @example
|
||||
* window.Asc.plugin.executeMethod("GetCurrentSentence");
|
||||
*/
|
||||
window["asc_docs_api"].prototype["pluginMethod_GetCurrentSentence"] = function()
|
||||
window["asc_docs_api"].prototype["pluginMethod_GetCurrentSentence"] = function(type)
|
||||
{
|
||||
let logicDocument = this.private_GetLogicDocument();
|
||||
if (!logicDocument)
|
||||
return "";
|
||||
|
||||
return logicDocument.GetCurrentSentence();
|
||||
return logicDocument.GetCurrentSentence(private_GetTextDirection(type));
|
||||
};
|
||||
|
||||
function private_ReadContentControlCommonPr(commonPr)
|
||||
@ -1278,5 +1249,23 @@
|
||||
|
||||
return resultPr;
|
||||
}
|
||||
|
||||
function private_GetTextDirection(type)
|
||||
{
|
||||
let direction = 0;
|
||||
switch (AscBuilder.GetStringParameter(type, "entirely"))
|
||||
{
|
||||
case "beforeCursor":
|
||||
direction = -1;
|
||||
break;
|
||||
case "afterCursor":
|
||||
direction = 1;
|
||||
break;
|
||||
case "entirely":
|
||||
default:
|
||||
direction = 0;
|
||||
break;
|
||||
}
|
||||
return direction;
|
||||
}
|
||||
|
||||
})(window);
|
||||
|
||||
Reference in New Issue
Block a user