sc/qa/uitest/calc_tests8/tdf132026.py |   44 ++++++++++++++++++++++++++++++++++
 sc/qa/uitest/data/tdf132026.ods       |binary
 sc/source/ui/view/tabvwsha.cxx        |   12 ++++++---
 3 files changed, 53 insertions(+), 3 deletions(-)

New commits:
commit 0450c7177f61ba5be15f7b4175b9fb5e89f850ae
Author:     Baole Fang <baole.f...@gmail.com>
AuthorDate: Sun May 28 10:28:24 2023 -0400
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Jun 2 20:02:39 2023 +0200

    tdf#132026: Fix selection in text cell
    
    Change-Id: Ic2bf869efa198cba83d1b781b419c3a9e0e606f3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152356
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/qa/uitest/calc_tests8/tdf132026.py 
b/sc/qa/uitest/calc_tests8/tdf132026.py
new file mode 100644
index 000000000000..abd3a86e720b
--- /dev/null
+++ b/sc/qa/uitest/calc_tests8/tdf132026.py
@@ -0,0 +1,44 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_url_for_data_file
+from libreoffice.calc.document import get_cell_by_position
+from libreoffice.uno.propertyvalue import mkPropertyValues
+
+class tdf132026(UITestCase):
+
+    def test_tdf132026(self):
+        with self.ui_test.load_file(get_url_for_data_file("tdf132026.ods")) as 
calc_doc:
+            MainWindow = self.xUITest.getTopFocusWindow()
+            grid_window = MainWindow.getChild("grid_window")
+
+            chars=["=","+","-"]
+            directions=["UP","DOWN","LEFT","RIGHT"]
+
+            # format general, should select cell
+            for c in chars:
+                sign=-1 if c=="-" else 1
+                for i,direction in enumerate(directions):
+                    grid_window.executeAction("SELECT", 
mkPropertyValues({"CELL": "B2"}))
+                    grid_window.executeAction("TYPE", 
mkPropertyValues({"TEXT": c}))
+                    grid_window.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": direction}))
+                    grid_window.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "RETURN"}))
+                    self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 
1).getString(), str(sign*(i+1)))
+
+            # format text, shouldn't select cell
+            for c in chars:
+                for direction in directions:
+                    grid_window.executeAction("SELECT", 
mkPropertyValues({"CELL": "E2"}))
+                    grid_window.executeAction("TYPE", 
mkPropertyValues({"TEXT": c}))
+                    grid_window.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": direction}))
+                    grid_window.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "RETURN"}))
+                    self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 
1).getString(), c)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/uitest/data/tdf132026.ods b/sc/qa/uitest/data/tdf132026.ods
new file mode 100644
index 000000000000..03c6c654fdc5
Binary files /dev/null and b/sc/qa/uitest/data/tdf132026.ods differ
diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx
index 4021f1937f91..f1305672a096 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -640,13 +640,19 @@ bool ScTabViewShell::IsRefInputMode() const
             ScInputHandler* pHdl = pScMod->GetInputHdl();
             if ( pHdl )
             {
+                const ScViewData& rViewData = GetViewData();
+                ScDocument& rDoc = rViewData.GetDocument();
+                const ScAddress aPos( rViewData.GetCurPos() );
+                const sal_uInt32 nIndex = rDoc.GetAttr(aPos, ATTR_VALUE_FORMAT 
)->GetValue();
+                const SvNumFormatType nType = 
rDoc.GetFormatTable()->GetType(nIndex);
+                if (nType == SvNumFormatType::TEXT)
+                {
+                    return false;
+                }
                 OUString aString = pHdl->GetEditString();
                 if ( !pHdl->GetSelIsRef() && aString.getLength() > 1 &&
                      ( aString[0] == '+' || aString[0] == '-' ) )
                 {
-                    const ScViewData& rViewData = GetViewData();
-                    ScDocument& rDoc = rViewData.GetDocument();
-                    const ScAddress aPos( rViewData.GetCurPos() );
                     ScCompiler aComp( rDoc, aPos, rDoc.GetGrammar() );
                     aComp.SetCloseBrackets( false );
                     std::unique_ptr<ScTokenArray> 
pArr(aComp.CompileString(aString));

Reply via email to