mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-22 14:20:35 +08:00
Preserve wxRichTextCtrl append style stack
AppendText() moves the insertion point to the end before writing, which refreshes the default style from the caret position. If a Begin*() style is active, this could replace the explicit append style with the style at the end of the existing text. Save and restore the active default style when the rich text style stack is non-empty, and cover appending text under a different text colour. Fixes #10936. Closes #27037.
This commit is contained in:
@@ -3381,8 +3381,14 @@ void wxRichTextCtrl::DoWriteText(const wxString& value, int flags)
|
||||
|
||||
void wxRichTextCtrl::AppendText(const wxString& text)
|
||||
{
|
||||
const bool hasStyleStack = GetBuffer().GetStyleStackSize() > 0;
|
||||
const wxRichTextAttr defaultStyle = GetDefaultStyleEx();
|
||||
|
||||
SetInsertionPointEnd();
|
||||
|
||||
if ( hasStyleStack )
|
||||
SetDefaultStyle(defaultStyle);
|
||||
|
||||
WriteText(text);
|
||||
}
|
||||
|
||||
|
||||
@@ -699,6 +699,27 @@ TEST_CASE_METHOD(RichTextCtrlTestCase, "RichTextCtrl::TextColour",
|
||||
CHECK(colour.GetTextColour() == m_rich->GetBasicStyle().GetTextColour());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(RichTextCtrlTestCase, "RichTextCtrl::AppendTextStyle",
|
||||
"[richtextctrl]")
|
||||
{
|
||||
m_rich->BeginTextColour(*wxRED);
|
||||
m_rich->WriteText("red");
|
||||
m_rich->EndTextColour();
|
||||
|
||||
m_rich->BeginTextColour(*wxBLUE);
|
||||
m_rich->AppendText("blue");
|
||||
m_rich->EndTextColour();
|
||||
|
||||
wxTextAttr colour;
|
||||
m_rich->GetStyle(1, colour);
|
||||
|
||||
CHECK(colour.GetTextColour() == *wxRED);
|
||||
|
||||
m_rich->GetStyle(5, colour);
|
||||
|
||||
CHECK(colour.GetTextColour() == *wxBLUE);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(RichTextCtrlTestCase, "RichTextCtrl::NumberedBullet",
|
||||
"[richtextctrl]")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user