summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/qa/core/unocore/unocore.cxx12
-rw-r--r--sw/qa/uibase/wrtsh/wrtsh.cxx10
-rw-r--r--sw/source/core/crsr/crstrvl.cxx4
-rw-r--r--sw/source/core/crsr/viscrs.cxx6
-rw-r--r--sw/source/core/txtnode/attrcontentcontrol.cxx4
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx1
-rw-r--r--sw/source/core/txtnode/thints.cxx21
-rw-r--r--sw/source/core/unocore/unocontentcontrol.cxx3
-rw-r--r--sw/source/filter/ascii/ascatr.cxx3
-rw-r--r--sw/source/uibase/wrtsh/wrtsh3.cxx4
10 files changed, 46 insertions, 22 deletions
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index 40fe6c31329b..bfeaea521c6e 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -321,7 +321,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlInsert)
CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlTextPortionEnum)
{
// Given a document with a content control around one or more text portions:
- createSwDoc();
+ SwDoc* pDoc = createSwDoc();
uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XText> xText = xTextDocument->getText();
@@ -363,6 +363,16 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlTextPortionEnum)
// portion.
assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout/SwLinePortion[2]", "type",
"PortionType::ContentControl");
+
+ // Also test the doc model, make sure that there is a dummy character at the start and end, so
+ // the user can explicitly decide if they want to expand the content control or not:
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ OUString aText = pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: ^Atest^A
+ // - Actual : ^Atest
+ // i.e. there was no dummy character at the end.
+ CPPUNIT_ASSERT_EQUAL(OUString("\x0001test\x0001"), aText);
}
CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlCheckbox)
diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index 1e2ef1bb48bd..51a1bbb984fa 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -125,9 +125,8 @@ CPPUNIT_TEST_FIXTURE(Test, testTickCheckboxContentControl)
// Without the accompanying fix in place, this test would have failed:
// - Expected: ☐
// - Actual : ☒
- // i.e. the text node's text was CH_TXTATR_BREAKWORD + "Ballot Box with X", not just
- // CH_TXTATR_BREAKWORD + "Ballot Box".
- CPPUNIT_ASSERT_EQUAL(OUString(u"\x0001☐"), pTextNode->GetText());
+ // i.e. the text node's text was "Ballot Box with X", not just "Ballot Box".
+ CPPUNIT_ASSERT_EQUAL(OUString(u"☐"), pTextNode->GetExpandText(pWrtShell->GetLayout()));
}
CPPUNIT_TEST_FIXTURE(Test, testInsertContentControl)
@@ -214,9 +213,8 @@ CPPUNIT_TEST_FIXTURE(Test, testSelectDropdownContentControl)
// Without the accompanying fix in place, this test would have failed:
// - Expected: red
// - Actual : choose an item
- // i.e. the document text was unchanged instead of CH_TXTATR_BREAKWORD + display text of the
- // first list item.
- CPPUNIT_ASSERT_EQUAL(OUString(u"\x0001red"), pTextNode->GetText());
+ // i.e. the document text was unchanged instead of display text of the first list item.
+ CPPUNIT_ASSERT_EQUAL(OUString("red"), pTextNode->GetExpandText(pWrtShell->GetLayout()));
}
}
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 8e8c472ada4b..4efaab1637a4 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -879,7 +879,9 @@ bool SwCursorShell::GotoFormatContentControl(const SwFormatContentControl& rCont
sal_Int32 nStart = pTextContentControl->GetStart() + 1;
pCursor->GetPoint()->nContent.Assign(pTextNode, nStart);
pCursor->GetMark()->nNode = *pTextNode;
- pCursor->GetMark()->nContent.Assign(pTextNode, *(pTextContentControl->End()));
+ // Don't select the CH_TXTATR_BREAKWORD itself at the end.
+ sal_Int32 nEnd = *pTextContentControl->End() - 1;
+ pCursor->GetMark()->nContent.Assign(pTextNode, nEnd);
// Assume that once the placeholder is selected, the content is no longer the placeholder.
pContentControl->SetShowingPlaceHolder(false);
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index bc55c09653c7..953c20f59a57 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -648,10 +648,10 @@ void SwSelPaintRects::HighlightContentControl()
SwTextContentControl* pCurContentControlAtCursor = nullptr;
if (pTextNode)
{
- // SwTextNode::EXPAND because the LHS of the dummy character doesn't count, the RHS of
- // the start of the LHS of the end counts.
+ // SwTextNode::PARENT because this way we highlight when the user will type inside the
+ // content control, not outside of it.
SwTextAttr* pAttr = pTextNode->GetTextAttrAt(
- pStart->nContent.GetIndex(), RES_TXTATR_CONTENTCONTROL, SwTextNode::EXPAND);
+ pStart->nContent.GetIndex(), RES_TXTATR_CONTENTCONTROL, SwTextNode::PARENT);
if (pAttr)
{
pCurContentControlAtCursor = static_txtattr_cast<SwTextContentControl*>(pAttr);
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx
index c28e686ce6fb..8704221a9a3b 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -318,10 +318,6 @@ SwTextContentControl::SwTextContentControl(SwFormatContentControl& rAttr, sal_In
{
rAttr.SetTextAttr(this);
SetHasDummyChar(true);
-
- // If the user types at the end of the content control, expand the text attr to the right.
- SetLockExpandFlag(false);
- SetDontExpand(false);
}
SwTextContentControl::~SwTextContentControl()
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 6c1e03c76233..97d65e48fbf0 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -3412,6 +3412,7 @@ OUString SwTextNode::GetExpandText(SwRootFrame const*const pLayout,
// remove dummy characters of Input Fields
comphelper::string::remove(aText, CH_TXT_ATR_INPUTFIELDSTART);
comphelper::string::remove(aText, CH_TXT_ATR_INPUTFIELDEND);
+ comphelper::string::remove(aText, CH_TXTATR_BREAKWORD);
if( bWithNum )
{
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index f465b65a2e39..75f04356e476 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1569,11 +1569,30 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, const SetAttrMode nMode )
}
// adjust end of hint to account for inserted CH_TXTATR
- const sal_Int32 * const pEnd(pAttr->GetEnd());
+ const sal_Int32* pEnd(pAttr->GetEnd());
if (pEnd)
{
pAttr->SetEnd(*pEnd + 1);
}
+
+ if (pAttr->Which() == RES_TXTATR_CONTENTCONTROL)
+ {
+ // Content controls have a dummy character at their end as well.
+ SwIndex aEndIdx(this, *pAttr->GetEnd());
+ OUString aEnd
+ = InsertText(OUString(GetCharOfTextAttr(*pAttr)), aEndIdx, nInsertFlags);
+ if (aEnd.isEmpty())
+ {
+ DestroyAttr(pAttr);
+ return false;
+ }
+
+ pEnd = pAttr->GetEnd();
+ if (pEnd)
+ {
+ pAttr->SetEnd(*pEnd + 1);
+ }
+ }
}
}
diff --git a/sw/source/core/unocore/unocontentcontrol.cxx b/sw/source/core/unocore/unocontentcontrol.cxx
index ae3973fc8c4f..a7aba99f2e2e 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -316,7 +316,8 @@ bool SwXContentControl::SetContentRange(SwTextNode*& rpNode, sal_Int32& rStart,
{
// rStart points at the first position within the content control.
rStart = pTextAttr->GetStart() + 1;
- rEnd = *pTextAttr->End();
+ // rEnd points at the last position within the content control.
+ rEnd = *pTextAttr->End() - 1;
return true;
}
}
diff --git a/sw/source/filter/ascii/ascatr.cxx b/sw/source/filter/ascii/ascatr.cxx
index 805f3ba48bc1..cc2c1eaac79f 100644
--- a/sw/source/filter/ascii/ascatr.cxx
+++ b/sw/source/filter/ascii/ascatr.cxx
@@ -342,7 +342,7 @@ static Writer& OutASC_SwTextNode( Writer& rWrt, SwContentNode& rNode )
if ( !bExportSoftHyphens )
aOutStr = aOutStr.replaceAll(OUStringChar(CHAR_SOFTHYPHEN), "");
- // all INWORD/BREAKWORD should be already removed by OutAttr
+ // all INWORD should be already removed by OutAttr
// but the field-marks are not attributes so filter those
static sal_Unicode const forbidden [] = {
CH_TXT_ATR_INPUTFIELDSTART,
@@ -351,6 +351,7 @@ static Writer& OutASC_SwTextNode( Writer& rWrt, SwContentNode& rNode )
CH_TXT_ATR_FIELDSTART,
CH_TXT_ATR_FIELDSEP,
CH_TXT_ATR_FIELDEND,
+ CH_TXTATR_BREAKWORD,
0
};
aOutStr = comphelper::string::removeAny(aOutStr, forbidden);
diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx b/sw/source/uibase/wrtsh/wrtsh3.cxx
index aa0badb54e61..573ea4a9752d 100644
--- a/sw/source/uibase/wrtsh/wrtsh3.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh3.cxx
@@ -140,10 +140,6 @@ bool SwWrtShell::GotoContentControl(const SwFormatContentControl& rContentContro
GetIDocumentUndoRedo().StartUndo(SwUndoId::REPLACE, &aRewriter);
// Update the content.
- SwTextContentControl* pTextContentControl
- = const_cast<SwFormatContentControl&>(rContentControl).GetTextAttr();
- // If the content control is at the end of the line, then expand is false by default.
- pTextContentControl->SetDontExpand(false);
DelLeft();
pContentControl->SetSelectedListItem(std::nullopt);
Insert(aNewState);