Don't take the previous paragraph style when deleting paragraph marker

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2008-02-26 17:59:06 +00:00
parent 3f49efdba9
commit 6c0ea5130f
2 changed files with 33 additions and 19 deletions

View File

@@ -197,6 +197,11 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
#define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
#define wxRICHTEXT_INSERT_INTERACTIVE 0x02 #define wxRICHTEXT_INSERT_INTERACTIVE 0x02
// A special flag telling the buffer to keep the first paragraph style
// as-is, when deleting a paragraph marker. In future we might pass a
// flag to InsertFragment and DeleteRange to indicate the appropriate mode.
#define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000
/*! /*!
* wxRichTextFontTable * wxRichTextFontTable
* Manages quick access to a pool of fonts for rendering rich text * Manages quick access to a pool of fonts for rendering rich text

View File

@@ -1176,7 +1176,8 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag
wxRichTextParagraph* firstPara = wxDynamicCast(firstParaNode->GetData(), wxRichTextParagraph); wxRichTextParagraph* firstPara = wxDynamicCast(firstParaNode->GetData(), wxRichTextParagraph);
wxASSERT(firstPara != NULL); wxASSERT(firstPara != NULL);
para->SetAttributes(firstPara->GetAttributes()); if (!(fragment.GetAttributes().GetFlags() & wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE))
para->SetAttributes(firstPara->GetAttributes());
// Save empty paragraph attributes for appending later // Save empty paragraph attributes for appending later
// These are character attributes deliberately set for a new paragraph. Without this, // These are character attributes deliberately set for a new paragraph. Without this,
@@ -1253,7 +1254,9 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag
} }
} }
if (finalPara && finalPara != para) if ((fragment.GetAttributes().GetFlags() & wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE) && firstPara)
finalPara->SetAttributes(firstPara->GetAttributes());
else if (finalPara && finalPara != para)
finalPara->SetAttributes(originalAttr); finalPara->SetAttributes(originalAttr);
return true; return true;
@@ -1455,6 +1458,7 @@ bool wxRichTextParagraphLayoutBox::DeleteRange(const wxRichTextRange& range)
obj->DeleteRange(range); obj->DeleteRange(range);
wxRichTextRange thisRange = obj->GetRange(); wxRichTextRange thisRange = obj->GetRange();
wxTextAttrEx thisAttr = obj->GetAttributes();
// If the whole paragraph is within the range to delete, // If the whole paragraph is within the range to delete,
// delete the whole thing. // delete the whole thing.
@@ -1488,7 +1492,14 @@ bool wxRichTextParagraphLayoutBox::DeleteRange(const wxRichTextRange& range)
wxTextAttrEx nextParaAttr; wxTextAttrEx nextParaAttr;
if (applyFinalParagraphStyle) if (applyFinalParagraphStyle)
nextParaAttr = nextParagraph->GetAttributes(); {
// Special case when deleting the end of a paragraph - use _this_ paragraph's style,
// not the next one.
if (range.GetStart() == range.GetEnd() && range.GetStart() == thisRange.GetEnd())
nextParaAttr = thisAttr;
else
nextParaAttr = nextParagraph->GetAttributes();
}
if (firstPara && nextParagraph && firstPara != nextParagraph) if (firstPara && nextParagraph && firstPara != nextParagraph)
{ {
@@ -4934,17 +4945,19 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int
wxRichTextParagraph* para = GetParagraphAtPosition(pos, false); wxRichTextParagraph* para = GetParagraphAtPosition(pos, false);
long pos1 = pos; long pos1 = pos;
if (p)
newPara->SetAttributes(*p);
if (flags & wxRICHTEXT_INSERT_INTERACTIVE) if (flags & wxRICHTEXT_INSERT_INTERACTIVE)
{ {
if (para && para->GetRange().GetEnd() == pos) if (para && para->GetRange().GetEnd() == pos)
pos1 ++; pos1 ++;
if (newPara->GetAttributes().HasBulletNumber())
newPara->GetAttributes().SetBulletNumber(newPara->GetAttributes().GetBulletNumber()+1);
} }
action->SetPosition(pos); action->SetPosition(pos);
if (p)
newPara->SetAttributes(*p);
// Use the default character style // Use the default character style
// Use the default character style // Use the default character style
if (!GetDefaultStyle().IsDefault() && newPara->GetChildren().GetFirst()) if (!GetDefaultStyle().IsDefault() && newPara->GetChildren().GetFirst())
@@ -5088,22 +5101,18 @@ bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, wxRichT
// Copy the fragment that we'll need to restore in Undo // Copy the fragment that we'll need to restore in Undo
CopyFragment(range, action->GetOldParagraphs()); CopyFragment(range, action->GetOldParagraphs());
// Special case: if there is only one (non-partial) paragraph, // See if we're deleting a paragraph marker, in which case we need to
// we must save the *next* paragraph's style, because that // make a note not to copy the attributes from the 2nd paragraph to the 1st.
// is the style we must apply when inserting the content back if (range.GetStart() == range.GetEnd())
// when undoing the delete. (This is because we're merging the
// paragraph with the previous paragraph and throwing away
// the style, and we need to restore it.)
if (!action->GetOldParagraphs().GetPartialParagraph() && action->GetOldParagraphs().GetChildCount() == 1)
{ {
wxRichTextParagraph* lastPara = GetParagraphAtPosition(range.GetStart()); wxRichTextParagraph* para = GetParagraphAtPosition(range.GetStart());
if (lastPara) if (para && para->GetRange().GetEnd() == range.GetEnd())
{ {
wxRichTextParagraph* nextPara = GetParagraphAtPosition(range.GetEnd()+1); wxRichTextParagraph* nextPara = GetParagraphAtPosition(range.GetStart()+1);
if (nextPara) if (nextPara && nextPara != para)
{ {
wxRichTextParagraph* para = (wxRichTextParagraph*) action->GetOldParagraphs().GetChild(0); action->GetOldParagraphs().GetChildren().GetFirst()->GetData()->SetAttributes(nextPara->GetAttributes());
para->SetAttributes(nextPara->GetAttributes()); action->GetOldParagraphs().GetAttributes().SetFlags(action->GetOldParagraphs().GetAttributes().GetFlags() | wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE);
} }
} }
} }