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 /sw | |
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 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter4.cxx | 23 | ||||
-rw-r--r-- | sw/source/core/txtnode/txtedt.cxx | 8 |
2 files changed, 30 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index 4ee3cfff78b0..c1635b64ffad 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -230,6 +230,27 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf49033) CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(*pDoc, *pCursor, TF::UPPERCASE_LOWERCASE)); + /* -- Test behavior when there is a selection that does not begin at a word boundary: "et" -- */ + for (int i = 0; i < 2; i++) + pCursor->Move(fnMoveBackward); + pCursor->SetMark(); + for (int i = 0; i < 2; i++) + pCursor->Move(fnMoveForward); + pWrtShell->GetSelectedText(currentSelectedText); + CPPUNIT_ASSERT_EQUAL(OUString("et"), currentSelectedText); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mEt joe Smith. Time Passed."), + lcl_translitTest(*pDoc, *pCursor, TF::SENTENCE_CASE)); + pDoc->GetIDocumentUndoRedo().Undo(); + CPPUNIT_ASSERT_EQUAL(OUString("et"), currentSelectedText); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mEt joe Smith. Time Passed."), + lcl_translitTest(*pDoc, *pCursor, TF::TITLE_CASE)); + pDoc->GetIDocumentUndoRedo().Undo(); + CPPUNIT_ASSERT_EQUAL(OUString("et"), currentSelectedText); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mET joe Smith. Time Passed."), + lcl_translitTest(*pDoc, *pCursor, TF::LOWERCASE_UPPERCASE)); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), + lcl_translitTest(*pDoc, *pCursor, TF::UPPERCASE_LOWERCASE)); + /* -- Test behavior when there is a selection that crosses a word boundary -- */ for (int i = 0; i < 7; i++) pCursor->Move(fnMoveBackward); @@ -241,7 +262,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf49033) CPPUNIT_ASSERT_EQUAL(OUString("nes met joe Sm"), currentSelectedText); CPPUNIT_ASSERT_EQUAL(OUString("Mary JoNes met joe smith. Time Passed."), lcl_translitTest(*pDoc, *pCursor, 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(*pDoc, *pCursor, TF::TITLE_CASE)); CPPUNIT_ASSERT_EQUAL(OUString("Mary JoNES MET JOE SMith. Time Passed."), lcl_translitTest(*pDoc, *pCursor, TF::LOWERCASE_UPPERCASE)); diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index f68518148749..1ed69cb78265 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -1756,6 +1756,11 @@ void SwTextNode::TransliterateText( nWordType); } + // prevent going outside of the user's selection, which may + // start in the middle of a word + aSttBndry.startPos = std::max(aSttBndry.startPos, selStart); + aEndBndry.startPos = std::max(aSttBndry.startPos, aEndBndry.startPos); + Boundary aCurWordBndry( aSttBndry ); while (aCurWordBndry.startPos <= aEndBndry.startPos) { @@ -1784,6 +1789,9 @@ void SwTextNode::TransliterateText( GetText(), nStt, g_pBreakIt->GetLocale(GetLang(nStt, 1)), nWordType); + + /* Selection may end in the middle of a word */ + aCurWordBndry.endPos = std::min(aCurWordBndry.endPos, selEnd); } } else if (rTrans.getType() == TransliterationFlags::SENTENCE_CASE) |