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

New commits:
commit f97dcfaee43f5b8c2eba4c7c3c2d0b786af38bc1
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Thu Mar 7 17:06:54 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Thu Apr 4 21:44:45 2024 +0200

    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/+/165799

diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index 8d2a6c11d4fc..df9fb6c8ca26 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -1863,14 +1863,15 @@ void Test::testTransliterate()
     int selStart = 12;
     int selEnd = 12;
     ESelection esel(0, selStart, 0, selEnd);
+    ESelection eSentenSel(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));
+    CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."), 
lcl_translitTest(editEng, sText2, eSentenSel, 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."), 
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));
@@ -1880,9 +1881,8 @@ 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."), 
lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
-    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::TITLE_CASE));
+    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));
 
     /* No selection tests. Cursor between the 'h' and the '.' after 'Smith'. */
@@ -1890,7 +1890,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."), 
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));
@@ -1900,7 +1899,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."), 
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));
@@ -1910,7 +1908,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."), 
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));
@@ -1920,7 +1917,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."), 
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));
@@ -1930,7 +1926,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."), 
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));
diff --git a/editeng/source/editeng/impedit.hxx 
b/editeng/source/editeng/impedit.hxx
index e4352f298fd8..0aabebe2ab46 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -702,7 +702,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 40f111b72e73..afb6a07671be 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -1566,7 +1566,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() );
@@ -1588,7 +1588,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 3bf44cdb9174..3c92a7abfede 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -2701,11 +2701,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