diff options
author | Michael Warner <michael.warner.ut+libreoffice@gmail.com> | 2021-10-02 09:34:34 -0400 |
---|---|---|
committer | Heiko Tietze <heiko.tietze@documentfoundation.org> | 2022-02-01 11:16:27 +0100 |
commit | de5aa409353c839483df21d47254fd2a508ab7d9 (patch) | |
tree | eeb8829c7b191a6595438c1c64407b347a54d239 /editeng | |
parent | bace2e0a80b939f7b1c666cf669ae99bc8758f05 (diff) |
tdf#144851 Honor Selection When Applying Title Case Format
Prevents Title Case formmating from occuring outside of a
user's selection. This is relevant if the user has started
or ended a selection in the middle of a word.
Change-Id: I39d8f2445acf5d9bb225bf8e3b36e2eb3b518857
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124102
Tested-by: Jenkins
Tested-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/qa/unit/core-test.cxx | 12 | ||||
-rw-r--r-- | editeng/source/editeng/impedit4.cxx | 11 |
2 files changed, 22 insertions, 1 deletions
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index 896fa59810eb..f3500e01ce26 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -1820,13 +1820,23 @@ void Test::testTransliterate() 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)); + /* Test behavior when there is a selection that does not begin at a word boundary: "et" */ + selStart = 12; + 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)); + /* Test behavior when there is a selection that crosses a word boundary: "nes met joe Sm" */ selStart = 7; selEnd = 21; esel = ESelection(0, selStart, 0, selEnd); CPPUNIT_ASSERT_EQUAL(OUString("nes met joe Sm"), 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::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/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 3012504bb028..1228924dc634 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -2738,6 +2738,14 @@ EditSelection ImpEditEngine::TransliterateText( const EditSelection& rSelection, nWordType); } + // prevent going outside of the user's selection, which may + // start or end in the middle of a word + if (nNode == nStartNode) { + aSttBndry.startPos = std::max(aSttBndry.startPos, aSel.Min().GetIndex()); + aSttBndry.endPos = std::min(aSttBndry.endPos, aSel.Max().GetIndex()); + aEndBndry.startPos = std::max(aEndBndry.startPos, aSttBndry.startPos); + aEndBndry.endPos = std::min(aEndBndry.endPos, aSel.Max().GetIndex()); + } i18n::Boundary aCurWordBndry( aSttBndry ); while (aCurWordBndry.endPos && aCurWordBndry.startPos <= aEndBndry.startPos) { @@ -2768,6 +2776,9 @@ EditSelection ImpEditEngine::TransliterateText( const EditSelection& rSelection, aCurWordBndry = _xBI->nextWord(aNodeStr, nCurrentStart, GetLocale( EditPaM( pNode, nCurrentStart + 1 ) ), nWordType); + + /* Selection may end in the middle of a word */ + aCurWordBndry.endPos = std::min(aCurWordBndry.endPos, aSel.Max().GetIndex()); } DBG_ASSERT( nCurrentEnd >= aEndBndry.endPos, "failed to reach end of transliteration" ); } |