From 730f619b891516ca3538ff74ec99d63fcfb63212 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Thu, 15 Feb 2024 18:06:48 +0300 Subject: [PATCH] [de] Fix cursor position during composite input --- tests/word/api/textInput.js | 51 ++++++++++++++++++++++++++++++++++- tests/word/common/document.js | 12 ++++++++- tests/word/common/editor.js | 40 ++++++++++++++++++++++++++- word/Editor/Paragraph.js | 2 +- 4 files changed, 101 insertions(+), 4 deletions(-) diff --git a/tests/word/api/textInput.js b/tests/word/api/textInput.js index 3832ea99f3..597acc96ce 100644 --- a/tests/word/api/textInput.js +++ b/tests/word/api/textInput.js @@ -94,6 +94,20 @@ $(function () { AscTest.EnterTextCompositeInput("yz"); AscTest.CorrectEnterText("yz", "x"); assert.strictEqual(GetParagraphText(p), "xx", "Test special case, when added symbols collect to a single grapheme with previous symbols"); + + // Вводим на сингальском 1ෑඒ (1-e-e-t) + p = new AscWord.CParagraph(AscTest.DrawingDocument); + logicDocument.PushToContent(p); + AscTest.MoveCursorToParagraph(p); + AscTest.EnterText("1"); + AscTest.BeginCompositeInput(); + AscTest.ReplaceCompositeInput([]); + AscTest.ReplaceCompositeInput([3536]); + AscTest.ReplaceCompositeInput([3537]); + AscTest.ReplaceCompositeInput([3537, 3474]); + AscTest.EndCompositeInput(); + assert.strictEqual(GetParagraphText(p), "1ෑඒ", "Add text '1ෑඒ'"); + assert.strictEqual(p.IsCursorAtEnd(), true, "Check cursor position"); }); QUnit.test("EnterText/CorrectEnterText/CompositeInput in collaboration", function (assert) { @@ -120,6 +134,42 @@ $(function () { AscTest.EndCollaboration(); }); + QUnit.test("EnterText/CorrectEnterText/CompositeInput with running TextSpeaker", function (assert) + { + AscTest.StartTextSpeaker(); + + AscTest.ClearDocument(); + let p = new AscWord.CParagraph(AscTest.DrawingDocument); + logicDocument.AddToContent(0, p); + + AscTest.EnterText("ABC"); + assert.strictEqual(GetParagraphText(p), "ABC", "Add text 'ABC' in collaboration"); + + AscTest.MoveCursorLeft(); + AscTest.EnterText("111"); + AscTest.CorrectEnterText("11", "23"); + assert.strictEqual(GetParagraphText(p), "AB123C", "Add text '111' and correct it with '123' in collaboration (sync between actions)"); + + AscTest.EnterText("QQQ"); + AscTest.CorrectEnterText("QQ", "RS"); + assert.strictEqual(GetParagraphText(p), "AB123QRSC", "Add text '111' and correct it with '123' in collaboration (no sync between actions)"); + + // Вводим на сингальском 1ෑඒ (1-e-e-t) + p = new AscWord.CParagraph(AscTest.DrawingDocument); + logicDocument.PushToContent(p); + AscTest.MoveCursorToParagraph(p); + AscTest.EnterText("1"); + AscTest.BeginCompositeInput(); + AscTest.ReplaceCompositeInput([]); + AscTest.ReplaceCompositeInput([3536]); + AscTest.ReplaceCompositeInput([3537]); + AscTest.ReplaceCompositeInput([3537, 3474]); + AscTest.EndCompositeInput(); + assert.strictEqual(GetParagraphText(p), "1ෑඒ", "Add text '1ෑඒ'"); + assert.strictEqual(p.IsCursorAtEnd(), true, "Check cursor position"); + + AscTest.StopTextSpeaker(); + }); QUnit.test("Test 'complex script' property on input", function (assert) { function CheckParagraphSplit(p, text, runCS, runText) @@ -220,6 +270,5 @@ $(function () { [true, true], ["3", "ෑඒ"] ); - }); }); diff --git a/tests/word/common/document.js b/tests/word/common/document.js index 614a67376c..1239721c6e 100644 --- a/tests/word/common/document.js +++ b/tests/word/common/document.js @@ -433,10 +433,18 @@ { AscCommon.CollaborativeEditing.End_CollaborationEditing(); } - + function StartTextSpeaker() + { + AscCommon.EditorActionSpeaker.run(); + } + function StopTextSpeaker() + { + AscCommon.EditorActionSpeaker.stop(); + } //--------------------------------------------------------export---------------------------------------------------- AscTest.CreateLogicDocument = CreateLogicDocument; + AscTest.GetLogicDocument = CreateLogicDocument; AscTest.CreateParagraph = CreateParagraph; AscTest.CreateRun = CreateRun; AscTest.CreateTable = CreateTable; @@ -474,6 +482,8 @@ AscTest.SyncCollaboration = SyncCollaboration; AscTest.EndCollaboration = EndCollaboration; AscTest.SelectParagraphRange = SelectParagraphRange; + AscTest.StartTextSpeaker = StartTextSpeaker; + AscTest.StopTextSpeaker = StopTextSpeaker; })(window); diff --git a/tests/word/common/editor.js b/tests/word/common/editor.js index c265f68ba7..d6f7ee230f 100644 --- a/tests/word/common/editor.js +++ b/tests/word/common/editor.js @@ -73,6 +73,7 @@ window['asc_docs_api'] = AscCommon.baseEditorsApi; + let _callbacks = {}; const editor = new AscCommon.baseEditorsApi({}); editor.WordControl = drawingDocument; editor.WordControl.m_oDrawingDocument = drawingDocument; @@ -105,7 +106,44 @@ editor.sync_ColumnsPropsCallback = function(){}; editor.sync_LineNumbersPropsCollback = function(){}; editor.sync_SectionPropsCallback = function(){}; - + editor.sendEvent = function() + { + var name = arguments[0]; + if (_callbacks.hasOwnProperty(name)) + { + for (var i = 0; i < _callbacks[name].length; ++i) + { + _callbacks[name][i].apply(this || window, Array.prototype.slice.call(arguments, 1)); + } + return true; + } + return false; + }; + editor.asc_registerCallback = function(name, callback) + { + if (!_callbacks.hasOwnProperty(name)) + _callbacks[name] = []; + _callbacks[name].push(callback); + }; + editor.asc_unregisterCallback = function(name, callback) + { + if (_callbacks.hasOwnProperty(name)) + { + for (var i = _callbacks[name].length - 1; i >= 0; --i) + { + if (_callbacks[name][i] === callback) + _callbacks[name].splice(i, 1); + } + } + }; + editor.getSelectionState = function() + { + return AscTest.GetLogicDocument().GetSelectionState(); + }; + editor.getSpeechDescription = function() + { + return AscTest.GetLogicDocument().getSpeechDescription(...arguments); + }; //--------------------------------------------------------export---------------------------------------------------- AscTest.DrawingDocument = drawingDocument; AscTest.Editor = editor; diff --git a/word/Editor/Paragraph.js b/word/Editor/Paragraph.js index b15fd9ee00..c69e24721d 100644 --- a/word/Editor/Paragraph.js +++ b/word/Editor/Paragraph.js @@ -13751,7 +13751,7 @@ Paragraph.prototype.SetSelectionState = function(State, StateIndex) this.CurPos.RealY = ParaState.CurPos.RealY; this.CurPos.PagesPos = ParaState.CurPos.PagesPos; - this.Set_ParaContentPos(ParaState.CurPos.ContentPos, true, -1, -1); + this.Set_ParaContentPos(ParaState.CurPos.ContentPos, true, -1, -1, false); this.RemoveSelection();