sw/inc/crsrsh.hxx                             |    2 +-
 sw/qa/core/edit/data/delete-sel-normalize.odt |binary
 sw/qa/core/edit/edit.cxx                      |   25 +++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

New commits:
commit 261999bc552516a7dae0f96895259485e9ac77a2
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Mar 27 15:41:50 2024 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Mar 27 18:03:19 2024 +0100

    tdf#109272 sw: add form filling testcase
    
    Open the document, press tab to switch to a field, start typing, nothing
    shows up.
    
    Looking at the doc model dump, it turns out we inserted characters
    between the field start and the field separator dummy characters,
    instead of the field separator and the field end ones, which is quite
    bad.
    
    Turns out that in the meantime commit
    c80606bb23fd42e41710d70a96b7ffaf948384a6 (tdf#109272: make sure that
    Delete / Backspace move cursor correctly, 2024-01-18) fixed this, kind
    of by accident: the comment says the motivation there was change
    tracking.
    
    Add a testcase to to make sure this now continues to work.
    
    Change-Id: I1a300d8064f7c2a30aafeefc6cb5612bfcd9a06a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165368
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index e330974a7dcc..5b0031882487 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -734,7 +734,7 @@ public:
 
     bool GotoFormatContentControl(const SwFormatContentControl& 
rContentControl);
 
-    void GotoFormControl(bool bNext);
+    SW_DLLPUBLIC void GotoFormControl(bool bNext);
 
     static SwTextField* GetTextFieldAtPos(
         const SwPosition* pPos,
diff --git a/sw/qa/core/edit/data/delete-sel-normalize.odt 
b/sw/qa/core/edit/data/delete-sel-normalize.odt
new file mode 100644
index 000000000000..d7113204ba80
Binary files /dev/null and b/sw/qa/core/edit/data/delete-sel-normalize.odt 
differ
diff --git a/sw/qa/core/edit/edit.cxx b/sw/qa/core/edit/edit.cxx
index 444887fbb0df..fa8fefa910c1 100644
--- a/sw/qa/core/edit/edit.cxx
+++ b/sw/qa/core/edit/edit.cxx
@@ -56,6 +56,31 @@ CPPUNIT_TEST_FIXTURE(Test, testAutocorrect)
     emulateTyping(*pTextDoc, u"But not now - with ");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testDeleteSelNormalize)
+{
+    // Given a read-only document with a fillable form, the placeholder text 
is selected:
+    createSwDoc("delete-sel-normalize.odt");
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+    pWrtShell->GotoFormControl(/*bNext=*/true);
+
+    // When you press 'delete' to type some content instead:
+    pWrtShell->DelRight();
+
+    // Then make sure the position after the delete is correct:
+    SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint();
+    // The full text is "key <field start><field separator><field end>", so 
this marks the position
+    // after the field separator but before the field end.
+    sal_Int32 nExpectedCharPos = strlen("key **");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 6
+    // - Actual  : 5
+    // so we started to type between the field start and the field separator, 
nothing was visible on
+    // the screen.
+    CPPUNIT_ASSERT_EQUAL(nExpectedCharPos, rCursor.nContent.GetIndex());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to