sw/qa/core/crsr/crsr.cxx | 23 +++++++++++++++++++++++ sw/source/core/crsr/pam.cxx | 7 +++++++ 2 files changed, 30 insertions(+)
New commits: commit b138d6c12aaeb0b87dce15ea52dd134cf1abf6ac Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Oct 12 11:44:49 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Oct 12 13:55:45 2022 +0200 tdf#151190 sw content controls: make them read-write in protected sections When the user picked a date in the date picker inside a protected section, then we blocked the deletion of the placeholder, but allowed insertion to the content control, which is inconsistent. The trouble was that SwPaM::HasReadonlySel() detected that the cursor is in a protected section, so deletion failed, leading to an ever growing value of the content control. Fix the problem by handling content controls similar to legacy form fields: if the cursor is inside a content control, then that value is editable, even if we're inside a protected section. This is meant to fix all content control types, not just date pickers. Change-Id: I9eca4c4f71dcfaa61d84414f7727adcd4496735c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141249 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/core/crsr/crsr.cxx b/sw/qa/core/crsr/crsr.cxx index 243abd0e20d1..eba0ac114b47 100644 --- a/sw/qa/core/crsr/crsr.cxx +++ b/sw/qa/core/crsr/crsr.cxx @@ -202,6 +202,29 @@ CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testDropdownContentControl) CPPUNIT_ASSERT(pWrtShell->HasReadonlySel()); } +CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testContentControlProtectedSection) +{ + // Given a document with a date content control in a protected section: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DATE); + pWrtShell->SelAll(); + OUString aSectionName = pWrtShell->GetUniqueSectionName(); + SwSectionData aSection(SectionType::Content, aSectionName); + aSection.SetProtectFlag(true); + pWrtShell->InsertSection(aSection); + + // When entering the content control: + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + // Then make sure that the cursor is read-only: + // Without the accompanying fix in place, this test would have failed, it was not possible to + // pick a date in a protected section (the new value was inserted, but the placeholder was not + // removed). + CPPUNIT_ASSERT(!pWrtShell->HasReadonlySel()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index 9e1e33d8a2b4..9295b09a7480 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -917,6 +917,13 @@ bool SwPaM::HasReadonlySel(bool bFormView, bool const isReplace) const { // Allow editing when the cursor/selection is fully inside of a legacy form field. bRet = !( pA != nullptr && !bAtStartA && !bAtStartB && pA == pB ); + + if (bRet && rDoc.GetEditShell()->CursorInsideContentControl()) + { + // Also allow editing inside content controls in general, similar to form fields. + // Specific types will be disabled below. + bRet = false; + } } if (!bRet)