From 57246b14777ed09edd7999bd0f9d1b86bedd5e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 20 Jan 2014 00:47:30 +0100 Subject: [PATCH] TextDocumentLayout: Fixed invalidating * Add new ParagraphLayouts for new Paragraphs in the TextDocument. * Actually mark layout invalid, so that height changes in paragraphs are accounted for and newly added paragraphs are positioned. --- .../textview/TextDocumentLayout.cpp | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/apps/haiku-depot/textview/TextDocumentLayout.cpp b/src/apps/haiku-depot/textview/TextDocumentLayout.cpp index cc98029e76..cd7b1d7905 100644 --- a/src/apps/haiku-depot/textview/TextDocumentLayout.cpp +++ b/src/apps/haiku-depot/textview/TextDocumentLayout.cpp @@ -64,27 +64,42 @@ TextDocumentLayout::SetTextDocument(const TextDocumentRef& document) void TextDocumentLayout::Invalidate() { - InvalidateParagraphs(0, fParagraphLayouts.CountItems()); + if (fDocument.Get() != NULL) + InvalidateParagraphs(0, fDocument->Paragraphs().CountItems()); } void TextDocumentLayout::InvalidateParagraphs(int32 start, int32 count) { - if (start < 0 || fDocument.Get() == NULL) + if (start < 0 || count == 0 || fDocument.Get() == NULL) return; + fLayoutValid = false; + const ParagraphList& paragraphs = fDocument->Paragraphs(); while (count > 0) { - if (start >= fParagraphLayouts.CountItems()) + if (start >= paragraphs.CountItems()) break; - const Paragraph& paragraph = paragraphs.ItemAtFast(start); - const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(start); - info.layout->SetParagraph(paragraph); + if (start >= fParagraphLayouts.CountItems()) { + ParagraphLayoutRef layout(new(std::nothrow) ParagraphLayout( + paragraph), true); + if (layout.Get() == NULL + || !fParagraphLayouts.Add(ParagraphLayoutInfo(0.0f, layout))) { + fprintf(stderr, "TextDocumentLayout::InvalidateParagraphs() - " + "out of memory\n"); + return; + } + } else { + const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast( + start); + info.layout->SetParagraph(paragraph); + } start++; + count--; } }