editeng/qa/unit/core-test.cxx       |   21 +++++----------------
 editeng/source/editeng/impedit.hxx  |    2 +-
 editeng/source/editeng/impedit2.cxx |    4 ++--
 editeng/source/editeng/impedit4.cxx |    6 +-----
 4 files changed, 9 insertions(+), 24 deletions(-)

New commits:
commit d512a1dcc0aed6796ad698800d1d9eb416503881
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Thu Mar 7 17:06:54 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Tue Mar 12 17:08:17 2024 +0100

    tdf#63259 Cycle case should work on end of words
    
    Now words are selected if the cursor is positioned at the end of
    the word. SENTENCE_CASE does not force sentence selection anymore.
    
    Change-Id: I672352b2c18bb695004fd4eb0f20ae5fd7a0ac53
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164546
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164712
    Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index 6fe616b1a034..9e988d429dad 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -1992,15 +1992,16 @@ void Test::testTransliterate()
     int selStart = 12;
     int selEnd = 12;
     ESelection esel(0, selStart, 0, selEnd);
+    ESelection eSentenceSel(0, 0, 0, 25);
 
     /* DocumentContentOperationsManager checks if the cursor is inside of a 
word before transliterating,
      * but Edit Engine has no such check. Therefore, behavior is different 
between these two when the
      * cursor is on a word boundary. */
 
-    /* No selection tests. Cursor between the ' ' and 'm' before 'met'. */
+    /* No selection tests. Cursor between the ' ' and 'm' before 'met' - 
except in SENTENCE_CASE where the complete sentence is selected.*/
     CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."),
-                         lcl_translitTest(editEng, sText2, esel, 
TF::SENTENCE_CASE));
+                         lcl_translitTest(editEng, sText2, eSentenceSel, 
TF::SENTENCE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::TITLE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."),
@@ -2013,11 +2014,9 @@ void Test::testTransliterate()
     selEnd = 14;
     esel = ESelection(0, selStart, 0, selEnd);
     CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."),
-                         lcl_translitTest(editEng, sText2, esel, 
TF::SENTENCE_CASE));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."),
+    CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::TITLE_CASE));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."),
+    CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::LOWERCASE_UPPERCASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::UPPERCASE_LOWERCASE));
@@ -2027,8 +2026,6 @@ void Test::testTransliterate()
     selEnd = 24;
     esel = ESelection(0, selStart, 0, selEnd);
     CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."),
-                         lcl_translitTest(editEng, sText2, esel, 
TF::SENTENCE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::TITLE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."),
@@ -2041,8 +2038,6 @@ void Test::testTransliterate()
     selEnd = 12;
     esel = ESelection(0, selStart, 0, selEnd);
     CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."),
-                         lcl_translitTest(editEng, sText2, esel, 
TF::SENTENCE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::TITLE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."),
@@ -2055,8 +2050,6 @@ void Test::testTransliterate()
     selEnd = 14;
     esel = ESelection(0, selStart, 0, selEnd);
     CPPUNIT_ASSERT_EQUAL(OUString("met"), editEng.GetText(esel));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."),
-                         lcl_translitTest(editEng, sText2, esel, 
TF::SENTENCE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::TITLE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."),
@@ -2069,8 +2062,6 @@ void Test::testTransliterate()
     selEnd = 14;
     esel = ESelection(0, selStart, 0, selEnd);
     CPPUNIT_ASSERT_EQUAL(OUString("et"), editEng.GetText(esel));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mEt joe Smith. Time Passed."),
-                         lcl_translitTest(editEng, sText2, esel, 
TF::SENTENCE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mEt joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::TITLE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mET joe Smith. Time Passed."),
@@ -2083,8 +2074,6 @@ void Test::testTransliterate()
     selEnd = 13;
     esel = ESelection(0, selStart, 0, selEnd);
     CPPUNIT_ASSERT_EQUAL(OUString("me"), editEng.GetText(esel));
-    CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."),
-                         lcl_translitTest(editEng, sText2, esel, 
TF::SENTENCE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."),
                          lcl_translitTest(editEng, sText2, esel, 
TF::TITLE_CASE));
     CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MEt joe Smith. Time Passed."),
diff --git a/editeng/source/editeng/impedit.hxx 
b/editeng/source/editeng/impedit.hxx
index 503e79bde400..13740c4da25d 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -701,7 +701,7 @@ private:
     EditPaM             WordRight( const EditPaM& rPaM, sal_Int16 nWordType = 
css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
     EditPaM             StartOfWord( const EditPaM& rPaM );
     EditPaM             EndOfWord( const EditPaM& rPaM );
-    EditSelection       SelectWord( const EditSelection& rCurSelection, 
sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, bool 
bAcceptStartOfWord = true );
+    EditSelection       SelectWord( const EditSelection& rCurSelection, 
sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, bool 
bAcceptStartOfWord = true, bool bAcceptEndOfWord = false );
     EditSelection       SelectSentence( const EditSelection& rCurSel ) const;
     EditPaM             CursorVisualLeftRight( EditView const * pEditView, 
const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode, bool bToLeft );
     EditPaM             CursorVisualStartEnd( EditView const * pEditView, 
const EditPaM& rPaM, bool bStart );
diff --git a/editeng/source/editeng/impedit2.cxx 
b/editeng/source/editeng/impedit2.cxx
index 7d65a940cd7a..b911240e5274 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -1574,7 +1574,7 @@ EditPaM ImpEditEngine::EndOfWord( const EditPaM& rPaM )
     return aNewPaM;
 }
 
-EditSelection ImpEditEngine::SelectWord( const EditSelection& rCurSel, 
sal_Int16 nWordType, bool bAcceptStartOfWord )
+EditSelection ImpEditEngine::SelectWord( const EditSelection& rCurSel, 
sal_Int16 nWordType, bool bAcceptStartOfWord, bool bAcceptEndOfWord )
 {
     EditSelection aNewSel( rCurSel );
     EditPaM aPaM( rCurSel.Max() );
@@ -1596,7 +1596,7 @@ EditSelection ImpEditEngine::SelectWord( const 
EditSelection& rCurSel, sal_Int16
             aPaM.GetNode()->GetString(), aPaM.GetIndex(), aLocale, nWordType, 
true);
 
         // don't select when cursor at end of word
-        if ( ( aBoundary.endPos > aPaM.GetIndex() ) &&
+        if ( ( aBoundary.endPos > aPaM.GetIndex() || ( bAcceptEndOfWord && 
aBoundary.endPos == aPaM.GetIndex() ) ) &&
              ( ( aBoundary.startPos < aPaM.GetIndex() ) || ( 
bAcceptStartOfWord && ( aBoundary.startPos == aPaM.GetIndex() ) ) ) )
         {
             aNewSel.Min().SetIndex( aBoundary.startPos );
diff --git a/editeng/source/editeng/impedit4.cxx 
b/editeng/source/editeng/impedit4.cxx
index 34d26b1a899a..0baa91957bce 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -2682,11 +2682,7 @@ EditSelection ImpEditEngine::TransliterateText( const 
EditSelection& rSelection,
 
     if ( !aSel.HasRange() )
     {
-        /* Cursor is inside of a word */
-        if (nTransliterationMode == TransliterationFlags::SENTENCE_CASE)
-            aSel = SelectSentence( aSel );
-        else
-            aSel = SelectWord( aSel );
+        aSel = SelectWord( aSel, 
css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, true, true );
     }
 
     // tdf#107176: if there's still no range, just return aSel

Reply via email to