+
+
diff --git a/tests/word/api/api.js b/tests/word/api/api.js
new file mode 100644
index 0000000000..14312f440e
--- /dev/null
+++ b/tests/word/api/api.js
@@ -0,0 +1,71 @@
+/*
+ * (c) Copyright Ascensio System SIA 2010-2019
+ *
+ * This program is a free software product. You can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License (AGPL)
+ * version 3 as published by the Free Software Foundation. In accordance with
+ * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
+ * that Ascensio System SIA expressly excludes the warranty of non-infringement
+ * of any third-party rights.
+ *
+ * This program is distributed WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
+ * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
+ *
+ * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
+ * street, Riga, Latvia, EU, LV-1050.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of the Program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU AGPL version 3.
+ *
+ * Pursuant to Section 7(b) of the License you must retain the original Product
+ * logo when distributing the program. Pursuant to Section 7(e) we decline to
+ * grant you any rights under trademark law for use of our trademarks.
+ *
+ * All the Product's GUI elements, including illustrations and icon sets, as
+ * well as technical writing content are licensed under the terms of the
+ * Creative Commons Attribution-ShareAlike 4.0 International. See the License
+ * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
+ *
+ */
+
+$(function () {
+
+ let logicDocument = AscTest.CreateLogicDocument();
+
+ QUnit.module("Test api for the document editor");
+
+
+ QUnit.test("Test AddText/RemoveSelection", function (assert)
+ {
+ AscTest.ClearDocument();
+
+ let p = new AscWord.CParagraph(AscTest.DrawingDocument);
+ logicDocument.AddToContent(0, p);
+
+ logicDocument.SelectAll();
+ assert.strictEqual(logicDocument.GetSelectedText(), "", "Check empty selection");
+
+ logicDocument.AddText("Hello World!");
+
+ logicDocument.SelectAll();
+ assert.strictEqual(logicDocument.GetSelectedText(false, {NewLineParagraph : true}), "Hello World!\r\n", "Add text 'Hello World!'");
+
+ let p2 = new AscWord.CParagraph(AscTest.DrawingDocument);
+ logicDocument.AddToContent(1, p2);
+
+ logicDocument.RemoveSelection();
+ p2.SetThisElementCurrent();
+ p2.MoveCursorToStartPos();
+
+ logicDocument.AddText("Second paragraph");
+
+ logicDocument.SelectAll();
+ assert.strictEqual(logicDocument.GetSelectedText(false, {NewLineParagraph : true}), "Hello World!\r\nSecond paragraph\r\n", "Add text to the second paragraph");
+
+ logicDocument.AddText("Test");
+ logicDocument.SelectAll();
+ assert.strictEqual(logicDocument.GetSelectedText(false, {NewLineParagraph : true}), "Test\r\n", "Replace all with adding text 'Test'");
+ });
+});
diff --git a/tests/word/common/document.js b/tests/word/common/document.js
index f0f8777b40..dec2c0a1d1 100644
--- a/tests/word/common/document.js
+++ b/tests/word/common/document.js
@@ -132,6 +132,13 @@
logicDocument.RecalculateFromStart(false);
}
+ function ClearDocument()
+ {
+ if (!logicDocument)
+ return;
+
+ logicDocument.RemoveFromContent(0, logicDocument.GetElementsCount(), false);
+ }
//--------------------------------------------------------export----------------------------------------------------
AscTest.CreateLogicDocument = CreateLogicDocument;
AscTest.SetFillingFormMode = SetFillingFormMode;
@@ -141,6 +148,7 @@
AscTest.MoveCursorRight = MoveCursorRight;
AscTest.Recalculate = Recalculate;
AscTest.ClickMouseButton = ClickMouseButton;
+ AscTest.ClearDocument = ClearDocument;
AscTest.KeyCode = KeyCode;
})(window);
diff --git a/word/api.js b/word/api.js
index 98372b5560..75872368dd 100644
--- a/word/api.js
+++ b/word/api.js
@@ -11511,6 +11511,22 @@ background-repeat: no-repeat;\
return oLogicDocument.GetFirstLetterAutoCorrectExceptions();
};
+ asc_docs_api.prototype.asc_RemoveSelection = function()
+ {
+ let oLogicDocument = this.private_GetLogicDocument();
+ if (!oLogicDocument)
+ return "";
+
+ return oLogicDocument.RemoveSelection();
+ };
+ asc_docs_api.prototype.asc_AddText = function(sText)
+ {
+ let oLogicDocument = this.private_GetLogicDocument();
+ if (!oLogicDocument)
+ return "";
+
+ return oLogicDocument.AddText(sText);
+ };
asc_docs_api.prototype.asc_GetCurrentWord = function(nDirection)
{
var oLogicDocument = this.private_GetLogicDocument();
@@ -13313,6 +13329,8 @@ background-repeat: no-repeat;\
asc_docs_api.prototype['asc_SetFirstLetterAutoCorrectExceptions'] = asc_docs_api.prototype.asc_SetFirstLetterAutoCorrectExceptions;
asc_docs_api.prototype['asc_GetFirstLetterAutoCorrectExceptions'] = asc_docs_api.prototype.asc_GetFirstLetterAutoCorrectExceptions;
+ asc_docs_api.prototype['asc_RemoveSelection'] = asc_docs_api.prototype.asc_RemoveSelection;
+ asc_docs_api.prototype['asc_AddText'] = asc_docs_api.prototype.asc_AddText;
asc_docs_api.prototype['asc_GetCurrentWord'] = asc_docs_api.prototype.asc_GetCurrentWord;
asc_docs_api.prototype['asc_ReplaceCurrentWord'] = asc_docs_api.prototype.asc_ReplaceCurrentWord;
asc_docs_api.prototype['asc_GetSelectedText'] = asc_docs_api.prototype.asc_GetSelectedText;