sw/source/uibase/uiview/viewsrch.cxx | 62 ++++++++++++++++------------------- 1 file changed, 29 insertions(+), 33 deletions(-)
New commits: commit 78ca6a8b55fbe557b1fde54aad4a393879c3d4ec Author: Bojidar Marinov <[email protected]> AuthorDate: Sat Jul 12 16:59:59 2025 +0300 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Oct 9 08:26:13 2025 +0200 tdf#77786 Replace format: Replace current found string and not next one Move the check for an empty replacement string with replacement attributes from SwView::ExecSearch (case REPLACE) to SwView::Replace. Change-Id: I24bcd485967230cae31e42197ebb7f5d40f8bf6d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187774 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx index 1d70837aa7ce..45f963e5a9c9 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -304,43 +304,34 @@ void SwView::ExecSearch(SfxRequest& rReq) case SvxSearchCmd::REPLACE: { - // 1) Replace selection (Not if only attributes should be replaced) -//JP 27.04.95: Why? -// what if you only want to assign attributes to the found?? + // 1) Replace selection - SvxSearchCmd nCmd = SvxSearchCmd::FIND; - if( !s_pSrchItem->GetReplaceString().isEmpty() || - !s_xReplaceList ) + // Prevent, that the replaced string will be found again + // if the replacement string is containing the search string. + bool bBack = s_pSrchItem->GetBackward(); + if (bBack) + m_pWrtShell->Push(); + OUString aReplace( s_pSrchItem->GetReplaceString() ); + i18nutil::SearchOptions2 aTmp( s_pSrchItem->GetSearchOptions() ); + std::optional<OUString> xBackRef = sw::ReplaceBackReferences(aTmp, + m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout()); + if( xBackRef ) + s_pSrchItem->SetReplaceString( *xBackRef ); + Replace(); + if( xBackRef ) { - // Prevent, that the replaced string will be found again - // if the replacement string is containing the search string. - bool bBack = s_pSrchItem->GetBackward(); - if (bBack) - m_pWrtShell->Push(); - OUString aReplace( s_pSrchItem->GetReplaceString() ); - i18nutil::SearchOptions2 aTmp( s_pSrchItem->GetSearchOptions() ); - std::optional<OUString> xBackRef = sw::ReplaceBackReferences(aTmp, - m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout()); - if( xBackRef ) - s_pSrchItem->SetReplaceString( *xBackRef ); - Replace(); - if( xBackRef ) - { - s_pSrchItem->SetReplaceString( aReplace ); - } - if (bBack) - { - m_pWrtShell->Pop(); - m_pWrtShell->SwapPam(); - } + s_pSrchItem->SetReplaceString( aReplace ); + } + if (bBack) + { + m_pWrtShell->Pop(); + m_pWrtShell->SwapPam(); } - else if( s_xReplaceList ) - nCmd = SvxSearchCmd::REPLACE; // 2) Search further (without replacing!) SvxSearchCmd nOldCmd = s_pSrchItem->GetCommand(); - s_pSrchItem->SetCommand( nCmd ); + s_pSrchItem->SetCommand( SvxSearchCmd::FIND ); bool bRet = SearchAndWrap(bQuiet); if( bRet ) Scroll( m_pWrtShell->GetCharRect().SVRect()); @@ -724,9 +715,14 @@ void SwView::Replace() if( bReqReplace ) { - - bool bReplaced = m_pWrtShell->SwEditShell::Replace( s_pSrchItem->GetReplaceString(), - s_pSrchItem->GetRegExp()); + bool bReplaced = true; + // Replace selection (Not if only attributes should be replaced) + if (!s_pSrchItem->GetReplaceString().isEmpty() || !s_xReplaceList) + { + bReplaced = m_pWrtShell->SwEditShell::Replace( s_pSrchItem->GetReplaceString(), + s_pSrchItem->GetRegExp() ); + } + // Replace attributes if( bReplaced && s_xReplaceList && s_xReplaceList->Count() && m_pWrtShell->HasSelection() ) { SfxItemSet aReplSet( m_pWrtShell->GetAttrPool(),
