[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sw/CppunitTest_sw_core_crsr.mk sw/Module_sw.mk sw/qa sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jul 23 07:53:19 UTC 2020
sw/CppunitTest_sw_core_crsr.mk | 73 ++++++++++++++++++++++++++++++
sw/Module_sw.mk | 1
sw/qa/core/crsr/crsr.cxx | 97 ++++++++++++++++++++++++++++++++++++++++
sw/source/core/crsr/findtxt.cxx | 19 ++++++-
4 files changed, 187 insertions(+), 3 deletions(-)
New commits:
commit f651419fcfa2e4a5059ba41587f1b437fe069109
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jul 22 17:36:17 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Jul 23 09:52:45 2020 +0200
sw: find & replace: fix soft hyphen cleaning
If there is a formatted soft hyphen after the search string, then
replace skipped the replacement, even if there was a match.
Do the same for comments & footnotes, though the primary reported
problem was just soft hyphens.
(The same happened when manually doing find & replace using the Ctrl-H
dialog.)
(cherry picked from commit d8270636a57e7dc68ede51308c380e2098f765d7)
Change-Id: I8437e84dea99ceef98d515beef5893cf954e674f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99268
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/CppunitTest_sw_core_crsr.mk b/sw/CppunitTest_sw_core_crsr.mk
new file mode 100644
index 000000000000..895b3ff63e57
--- /dev/null
+++ b/sw/CppunitTest_sw_core_crsr.mk
@@ -0,0 +1,73 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_crsr))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_crsr))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_crsr, \
+ sw/qa/core/crsr/crsr \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_crsr, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ sfx \
+ svxcore \
+ sw \
+ test \
+ unotest \
+ utl \
+ vcl \
+ svt \
+ tl \
+ svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_crsr,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_crsr,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/source/uibase/inc \
+ -I$(SRCDIR)/sw/qa/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_crsr,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_crsr))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_crsr))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_crsr,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_crsr,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_crsr))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_crsr, \
+ modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_crsr))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 18bb28eea515..0f45dc0cb91e 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -114,6 +114,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_core_objectpositioning \
CppunitTest_sw_core_layout \
CppunitTest_sw_core_unocore \
+ CppunitTest_sw_core_crsr \
))
ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/crsr/crsr.cxx b/sw/qa/core/crsr/crsr.cxx
new file mode 100644
index 000000000000..7f1ace3ae6fb
--- /dev/null
+++ b/sw/qa/core/crsr/crsr.cxx
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <com/sun/star/awt/FontWeight.hpp>
+#include <com/sun/star/text/ControlCharacter.hpp>
+#include <com/sun/star/view/XLineCursor.hpp>
+#include <com/sun/star/frame/DispatchHelper.hpp>
+
+#include <comphelper/propertysequence.hxx>
+#include <svl/srchitem.hxx>
+
+/// Covers sw/source/core/crsr/ fixes.
+class SwCoreCrsrTest : public SwModelTestBase
+{
+};
+
+namespace
+{
+void dispatchCommand(const uno::Reference<lang::XComponent>& xComponent, const OUString& rCommand,
+ const uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+ uno::Reference<frame::XController> xController
+ = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController();
+ CPPUNIT_ASSERT(xController.is());
+ uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFrame.is());
+
+ uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
+ CPPUNIT_ASSERT(xDispatchHelper.is());
+
+ xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
+}
+}
+
+CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testFindReplace)
+{
+ loadURL("private:factory/swriter", nullptr);
+
+ // Given: a document with two "foo" in it, the second followed by a formatted soft hyphen.
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ // Create a document which has 2 lines: first line has foo in it, second line has the same, but
+ // followed by a formatted soft hyphen.
+ xText->insertString(xText->getEnd(), "foo xxx", /*bAbsorb=*/false);
+ xText->insertControlCharacter(xText->getEnd(), text::ControlCharacter::PARAGRAPH_BREAK,
+ /*bAbsorb=*/false);
+ xText->insertString(xText->getEnd(), OUString(u"foo xxx \xad after"), /*bAbsorb=*/false);
+ uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
+ xModel->getCurrentController(), uno::UNO_QUERY);
+ uno::Reference<text::XTextViewCursor> xViewCursor = xTextViewCursorSupplier->getViewCursor();
+ xViewCursor->gotoEnd(/*bExpand=*/false);
+ xViewCursor->goLeft(/*nCount=*/6, /*bExpand=*/false);
+ xViewCursor->goLeft(/*nCount=*/1, /*bExpand=*/true);
+ uno::Reference<beans::XPropertySet> xViewCursorProps(xViewCursor, uno::UNO_QUERY);
+ xViewCursorProps->setPropertyValue("CharWeight", uno::makeAny(awt::FontWeight::BOLD));
+ xViewCursor->gotoStart(/*bExpand=*/false);
+
+ // When: doing search & replace 3 times.
+ uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence({
+ { "SearchItem.SearchString", uno::makeAny(OUString("foo")) },
+ { "SearchItem.ReplaceString", uno::makeAny(OUString("bar")) },
+ { "SearchItem.Command", uno::makeAny(static_cast<sal_Int16>(SvxSearchCmd::REPLACE)) },
+ }));
+ // Find the first foo.
+ dispatchCommand(mxComponent, ".uno:ExecuteSearch", aArgs);
+ // Replace the first foo.
+ dispatchCommand(mxComponent, ".uno:ExecuteSearch", aArgs);
+ // Replace the second foo.
+ dispatchCommand(mxComponent, ".uno:ExecuteSearch", aArgs);
+
+ // Then: the second "foo" should be replaced as well.
+ xViewCursor->gotoEnd(/*bExpand=*/false);
+ uno::Reference<view::XLineCursor> xLineCursor(xViewCursor, uno::UNO_QUERY);
+ xLineCursor->gotoStartOfLine(/*bExpand=*/true);
+ OUString aActual = xViewCursor->getString();
+ CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(3), aActual.getLength());
+ OUString aActualStart = aActual.copy(0, 3);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: bar
+ // - Actual : foo
+ // i.e. the foo on the second line was not replaced.
+ CPPUNIT_ASSERT_EQUAL(OUString("bar"), aActualStart);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index 69695279513e..b0c2563a7e79 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -287,7 +287,10 @@ lcl_CleanStr(const SwTextNode& rNd,
if ( bEmpty && nStart == nCurrent )
{
rArr.push_back( nCurrent );
- --rEnd.GetAnyIndex();
+ if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
+ {
+ --rEnd.GetAnyIndex();
+ }
buf.remove(nCurrent.GetAnyIndex(), 1);
}
else
@@ -303,7 +306,10 @@ lcl_CleanStr(const SwTextNode& rNd,
if( bRemoveCommentAnchors )
{
rArr.push_back( nCurrent );
- --rEnd.GetAnyIndex();
+ if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
+ {
+ --rEnd.GetAnyIndex();
+ }
buf.remove( nCurrent.GetAnyIndex(), 1 );
}
}
@@ -319,7 +325,14 @@ lcl_CleanStr(const SwTextNode& rNd,
if ( bNewSoftHyphen )
{
rArr.push_back( nCurrent );
- --rEnd.GetAnyIndex();
+
+ // If the soft hyphen to be removed is past the end of the range we're searching in,
+ // don't adjust the end.
+ if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
+ {
+ --rEnd.GetAnyIndex();
+ }
+
buf.remove(nCurrent.GetAnyIndex(), 1);
++nSoftHyphen.GetAnyIndex();
}
More information about the Libreoffice-commits
mailing list