From ac0fe92185ffa81930dd014bc7e340c7f055c26b Mon Sep 17 00:00:00 2001 From: Andreas Heinisch Date: Wed, 10 Jun 2026 09:43:05 +0200 Subject: [PATCH] tdf#169913 - Add option to suppress typing replaces text selection Change-Id: Iee202a64314be7def38cffd95f4cac7fe083080e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206276 Reviewed-by: Andreas Heinisch Tested-by: Jenkins --- .../schema/org/openoffice/Office/Writer.xcs | 7 ++ sw/inc/viewopt.hxx | 2 + sw/source/ui/config/optpage.cxx | 19 +++++ sw/source/uibase/config/viewopt.cxx | 9 +++ sw/source/uibase/inc/optpage.hxx | 3 + sw/source/uibase/wrtsh/wrtsh1.cxx | 8 +++ sw/uiconfig/swriter/ui/optformataidspage.ui | 71 +++++++++++++++++++ 7 files changed, 119 insertions(+) diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs index 34f5651f3bdd..6303aa1ddcf4 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs @@ -2202,6 +2202,13 @@ true + + + Specifies whether typing replaces the selected text. + + + true + diff --git a/sw/inc/viewopt.hxx b/sw/inc/viewopt.hxx index a06b90915e17..ca9aa8895ea8 100644 --- a/sw/inc/viewopt.hxx +++ b/sw/inc/viewopt.hxx @@ -641,6 +641,8 @@ public: static bool IsAllowDragDropText(); + static bool IsTypingReplacesSelection(); + bool IsPDFExport() const {return bool(m_nCore2Options & ViewOptCoreFlags2::PdfExport); } diff --git a/sw/source/ui/config/optpage.cxx b/sw/source/ui/config/optpage.cxx index 03683681c79d..19ed9bdd567d 100644 --- a/sw/source/ui/config/optpage.cxx +++ b/sw/source/ui/config/optpage.cxx @@ -1749,6 +1749,8 @@ SwShdwCursorOptionsTabPage::SwShdwCursorOptionsTabPage(weld::Container* pPage, w , m_xDragDropFrame(m_xBuilder->weld_frame(u"frmDragDrop"_ustr)) , m_xDragDropCB(m_xBuilder->weld_check_button(u"allowdragdrop"_ustr)) , m_xDragDropImg(m_xBuilder->weld_widget(u"lockallowdragdrop"_ustr)) + , m_xTypingReplacesSelectionCB(m_xBuilder->weld_check_button(u"typingreplacesselection"_ustr)) + , m_xTypingReplacesSelectionImg(m_xBuilder->weld_widget(u"locktypingreplacesselection"_ustr)) , m_xTextBoundariesCB(m_xBuilder->weld_check_button(u"cbTextBoundaries"_ustr)) , m_xSectionBoundariesCB(m_xBuilder->weld_check_button(u"cbSectionBoundaries"_ustr)) , m_xTableBoundariesCB(m_xBuilder->weld_check_button(u"cbTableBoundaries"_ustr)) @@ -1881,6 +1883,15 @@ bool SwShdwCursorOptionsTabPage::FillItemSet( SfxItemSet* rSet ) xChanges->commit(); } + if (m_xTypingReplacesSelectionCB->get_state_changed_from_saved()) + { + std::shared_ptr xChanges( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::Cursor::Option::TypingReplacesSelection::set( + m_xTypingReplacesSelectionCB->get_active(), xChanges); + xChanges->commit(); + } + SwFmtAidsAutoComplItem aFmtAidsAutoComplOpt; aFmtAidsAutoComplOpt.SetEncloseWithCharactersOn(m_xEncloseWithCharactersCB->get_active()); if (const SwFmtAidsAutoComplItem* pFmtAidsAutoComplItem @@ -1973,6 +1984,14 @@ void SwShdwCursorOptionsTabPage::Reset( const SfxItemSet* rSet ) m_xDragDropImg->set_visible(bReadOnly); m_xDragDropCB->save_state(); + const bool bTypingReplacesSelection + = officecfg::Office::Writer::Cursor::Option::TypingReplacesSelection::get(); + m_xTypingReplacesSelectionCB->set_active(bTypingReplacesSelection); + bReadOnly = officecfg::Office::Writer::Cursor::Option::TypingReplacesSelection::isReadOnly(); + m_xTypingReplacesSelectionCB->set_sensitive(!bReadOnly); + m_xTypingReplacesSelectionImg->set_visible(bReadOnly); + m_xTypingReplacesSelectionCB->save_state(); + const SwDocDisplayItem* pDocDisplayAttr = rSet->GetItemIfSet( FN_PARAM_DOCDISP, false ); if(pDocDisplayAttr) { diff --git a/sw/source/uibase/config/viewopt.cxx b/sw/source/uibase/config/viewopt.cxx index ea4a3c22e59b..7645b2596e39 100644 --- a/sw/source/uibase/config/viewopt.cxx +++ b/sw/source/uibase/config/viewopt.cxx @@ -602,6 +602,15 @@ bool SwViewOption::IsAllowDragDropText() return gAllowDragDrop.get(); } +bool SwViewOption::IsTypingReplacesSelection() +{ + if (comphelper::IsFuzzing()) + return true; + static comphelper::ConfigurationListenerProperty gTypingReplacesSelection( + getWCOptionListener(), u"TypingReplacesSelection"_ustr); + return gTypingReplacesSelection.get(); +} + void SwViewOption::SyncLayoutRelatedViewOptions(const SwViewOption& rOpt) { SetFieldName(rOpt.IsFieldName()); diff --git a/sw/source/uibase/inc/optpage.hxx b/sw/source/uibase/inc/optpage.hxx index 9a4db8ae2c17..a8fa7ec51621 100644 --- a/sw/source/uibase/inc/optpage.hxx +++ b/sw/source/uibase/inc/optpage.hxx @@ -346,6 +346,9 @@ class SwShdwCursorOptionsTabPage final : public SfxTabPage std::unique_ptr m_xDragDropCB; std::unique_ptr m_xDragDropImg; + std::unique_ptr m_xTypingReplacesSelectionCB; + std::unique_ptr m_xTypingReplacesSelectionImg; + std::unique_ptr m_xTextBoundariesCB; std::unique_ptr m_xSectionBoundariesCB; std::unique_ptr m_xTableBoundariesCB; diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 64dfc94f5cc5..a3731af8070b 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -249,6 +249,14 @@ void SwWrtShell::Insert( const OUString &rStr ) bCallIns = m_bIns /*|| bHasSel*/; bool bDeleted = false; + // tdf#169913 - insert at cursor position without overwriting the selection + if (bHasSel && !SwViewOption::IsTypingReplacesSelection()) + { + NormalizePam(false); + ClearMark(); + bHasSel = false; + } + if( bHasSel || ( !m_bIns && IsInHiddenRange(/*bSelect=*/true) ) ) { // Only here parenthesizing, because the normal diff --git a/sw/uiconfig/swriter/ui/optformataidspage.ui b/sw/uiconfig/swriter/ui/optformataidspage.ui index a15a1e9ec9db..1965cef64321 100644 --- a/sw/uiconfig/swriter/ui/optformataidspage.ui +++ b/sw/uiconfig/swriter/ui/optformataidspage.ui @@ -904,6 +904,77 @@ 3 + + + True + False + start + 0 + none + + + + True + False + 12 + 6 + 6 + + + Typing replaces selection + True + True + False + True + True + + + Specifies whether typing replaces the selected text. + + + + + 1 + 0 + + + + + False + True + center + center + res/lock.png + + + Specifies whether typing replaces the selected text. + + + + + 0 + 0 + + + + + + + True + False + Typing + + + + + + + + False + True + 4 + + 1