starmath/inc/view.hxx          |   14 --------------
 starmath/source/edit.cxx       |    4 ----
 starmath/source/view.cxx       |   29 +++++++++++++----------------
 uitest/math_tests/start.py     |    3 ++-
 uitest/math_tests/tdf147755.py |    4 ++--
 5 files changed, 17 insertions(+), 37 deletions(-)

New commits:
commit ee187f6ed7873f3ebc1f845a4384a84713be1e9c
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Tue Sep 5 20:24:13 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Tue Sep 5 20:28:34 2023 +0200

    starmath: Always insert using SmCursor when inline editing is enabled
    
    Choosing which code path based on which widget has focus is not a very
    good idea, and leads to unreliable UI tests as each code path inserts
    the text slightly differently (one code path inserts plain text then
    parses the whole equation again, while the other parses the new text
    then inserts the parsed node directly).
    
    Change-Id: Ib2ca942c537e466f6ff100be7f95adaead99f1d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156578
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/starmath/inc/view.hxx b/starmath/inc/view.hxx
index dc42dde2fdc9..4a79b94e4f02 100644
--- a/starmath/inc/view.hxx
+++ b/starmath/inc/view.hxx
@@ -249,11 +249,6 @@ class SmViewShell final : public SfxViewShell
     SmGraphicController maGraphicController;
     OUString maStatusText;
     bool mbPasteState;
-    /** Used to determine whether insertions using SID_INSERTSPECIAL and 
SID_INSERTCOMMANDTEXT
-     * should be inserted into SmEditWindow or directly into the SmDocShell as 
done if the
-     * visual editor was last to have focus.
-     */
-    bool mbInsertIntoEditWindow;
 
     DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper*, void );
     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint 
) override;
@@ -337,15 +332,6 @@ public:
     void Impl_Print( OutputDevice &rOutDev, const SmPrintUIOptions 
&rPrintUIOptions,
             tools::Rectangle aOutRect );
 
-    /** Set bInsertIntoEditWindow so we know where to insert
-     *
-     * This method is called whenever SmGraphicWidget or SmEditWindow gets 
focus,
-     * so that when text is inserted from catalog or elsewhere we know whether 
to
-     * insert for the visual editor, or the text editor.
-     */
-    void SetInsertIntoEditWindow(bool bEditWindowHadFocusLast){
-        mbInsertIntoEditWindow = bEditWindowHadFocusLast;
-    }
     static bool IsInlineEditEnabled();
 
     // Opens the main help page for the Math module
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index 4cb4f6532f64..90cb6cd5498a 100644
--- a/starmath/source/edit.cxx
+++ b/starmath/source/edit.cxx
@@ -556,10 +556,6 @@ void SmEditTextWindow::GetFocus()
     EditEngine *pEditEngine = GetEditEngine();
     if (pEditEngine)
         pEditEngine->SetStatusEventHdl(LINK(this, SmEditTextWindow, 
EditStatusHdl));
-
-    //Let SmViewShell know we got focus
-    if (mrEditWindow.GetView() && SmViewShell::IsInlineEditEnabled())
-        mrEditWindow.GetView()->SetInsertIntoEditWindow(true);
 }
 
 void SmEditTextWindow::LoseFocus()
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 22ca4e575d3b..eacab22901ad 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -424,8 +424,6 @@ void SmGraphicWidget::GetFocus()
         return;
     if (SmEditWindow* pEdit = GetView().GetEditWindow())
         pEdit->Flush();
-    //Let view shell know what insertions should be done in visual editor
-    GetView().SetInsertIntoEditWindow(false);
     SetIsCursorVisible(true);
     ShowLine(true);
     CaretBlinkStart();
@@ -1784,7 +1782,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
 
 
         case SID_CUT:
-            if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+            if (IsInlineEditEnabled())
             {
                 GetDoc()->GetCursor().Cut();
                 GetGraphicWidget().GrabFocus();
@@ -1794,7 +1792,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
             break;
 
         case SID_COPY:
-            if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+            if (IsInlineEditEnabled())
             {
                 GetDoc()->GetCursor().Copy();
                 GetGraphicWidget().GrabFocus();
@@ -1814,7 +1812,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
 
         case SID_PASTE:
             {
-                if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+                if (IsInlineEditEnabled())
                 {
                     GetDoc()->GetCursor().Paste();
                     GetGraphicWidget().GrabFocus();
@@ -1847,7 +1845,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
             break;
 
         case SID_DELETE:
-            if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+            if (IsInlineEditEnabled())
             {
                 if (!GetDoc()->GetCursor().HasSelection())
                 {
@@ -1872,15 +1870,15 @@ void SmViewShell::Execute(SfxRequest& rReq)
         {
             const SfxStringItem& rItem = 
rReq.GetArgs()->Get(SID_INSERTCOMMANDTEXT);
 
-            if (pWin && (mbInsertIntoEditWindow || !IsInlineEditEnabled()))
-            {
-                pWin->InsertText(rItem.GetValue());
-            }
-            if (IsInlineEditEnabled() && (GetDoc() && !mbInsertIntoEditWindow))
+            if (IsInlineEditEnabled())
             {
                 GetDoc()->GetCursor().InsertCommandText(rItem.GetValue());
                 GetGraphicWidget().GrabFocus();
             }
+            else if (pWin)
+            {
+                pWin->InsertText(rItem.GetValue());
+            }
             break;
 
         }
@@ -1889,10 +1887,10 @@ void SmViewShell::Execute(SfxRequest& rReq)
         {
             const SfxStringItem& rItem = 
rReq.GetArgs()->Get(SID_INSERTSPECIAL);
 
-            if (pWin && (mbInsertIntoEditWindow || !IsInlineEditEnabled()))
-                pWin->InsertText(rItem.GetValue());
-            if (IsInlineEditEnabled() && (GetDoc() && !mbInsertIntoEditWindow))
+            if (IsInlineEditEnabled())
                 GetDoc()->GetCursor().InsertSpecial(rItem.GetValue());
+            else if (pWin)
+                pWin->InsertText(rItem.GetValue());
             break;
         }
 
@@ -2142,7 +2140,7 @@ void SmViewShell::GetState(SfxItemSet &rSet)
         case SID_CUT:
         case SID_COPY:
         case SID_DELETE:
-            if (IsInlineEditEnabled() && !mbInsertIntoEditWindow)
+            if (IsInlineEditEnabled())
             {
                 if (!GetDoc()->GetCursor().HasSelection())
                     rSet.DisableItem(nWh);
@@ -2308,7 +2306,6 @@ SmViewShell::SmViewShell(SfxViewFrame& rFrame_, 
SfxViewShell *)
     , mxGraphicWindow(VclPtr<SmGraphicWindow>::Create(*this))
     , maGraphicController(mxGraphicWindow->GetGraphicWidget(), SID_GRAPHIC_SM, 
rFrame_.GetBindings())
     , mbPasteState(false)
-    , mbInsertIntoEditWindow(false)
 {
     SetStatusText(OUString());
     SetWindow(mxGraphicWindow.get());
diff --git a/uitest/math_tests/start.py b/uitest/math_tests/start.py
index 6b3278acf907..7504387a16f7 100644
--- a/uitest/math_tests/start.py
+++ b/uitest/math_tests/start.py
@@ -57,10 +57,11 @@ class SimpleMathTest(UITestCase):
             xElement.executeAction("DOUBLECLICK", tuple())
 
             xEditView = xMathDoc.getChild("editview")
+            xEditView.executeAction("TYPE", mkPropertyValues({"KEYCODE":"F4"}))
             type_text(xEditView, "1")
             xEditView.executeAction("TYPE", mkPropertyValues({"KEYCODE":"F4"}))
             type_text(xEditView, "2")
 
-            self.assertEqual("1 <> 2 ", get_state_as_dict(xEditView)["Text"])
+            self.assertEqual("{ 1 <> 2 }", 
get_state_as_dict(xEditView)["Text"])
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/math_tests/tdf147755.py b/uitest/math_tests/tdf147755.py
index 4ee9bc169507..755efbe6b51d 100644
--- a/uitest/math_tests/tdf147755.py
+++ b/uitest/math_tests/tdf147755.py
@@ -26,7 +26,7 @@ class Tdf147755(UITestCase):
             xEditView = xMathDoc.getChild("editview")
 
             # Without the fix in place, this test would have failed with
-            # AssertionError: '%ALPHA ' != ''
-            self.assertEqual("%ALPHA ", get_state_as_dict(xEditView)["Text"])
+            # AssertionError: '%ALPHA' != ''
+            self.assertEqual("%ALPHA", get_state_as_dict(xEditView)["Text"])
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:

Reply via email to