GetCurrentWord

function GetCurrentWord(sWordPart: "undefined" | before | after = null): string

Description

Returns the current word or part of the current word

Parameters

sWordPart"undefined" | before | afterdefault: null

Specifies the desired part of the current word

Returns

string

Try It

let oDocument = Api.GetDocument();
let oPara1 = oDocument.GetElement(0);
oPara1.AddText("The quick brown ");
let oRun = oPara1.AddText("fox");
oPara1.AddText(" jumps over the lazy dog");

oRun.MoveCursorToPos(1);

let oPara2 = Api.CreateParagraph();
oPara2.AddText("The current word is " + oDocument.GetCurrentWord());
oDocument.Push(oPara2);

oPara2 = Api.CreateParagraph();
oPara2.AddText("The part of the word after cursor is " + oDocument.GetCurrentWord("after"));
oDocument.Push(oPara2);

oPara2 = Api.CreateParagraph();
oPara2.AddText("The part of the word before cursor is " + oDocument.GetCurrentWord("before"));
oDocument.Push(oPara2);


Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).