From 6f173f11f30d88c6ba762ac8fe34f8e0cf321f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 26 Jan 2014 15:17:52 +0100 Subject: [PATCH] TextDocument: Don't leave empty paragraphs when inserting line-breaks. Instead, add one empty TextSpan. This commit resolves the last of the very obvious problems when editing. More subtle ones may still surface. --- src/apps/haiku-depot/textview/TextDocument.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/apps/haiku-depot/textview/TextDocument.cpp b/src/apps/haiku-depot/textview/TextDocument.cpp index 10709e8b59..d1fb07558a 100644 --- a/src/apps/haiku-depot/textview/TextDocument.cpp +++ b/src/apps/haiku-depot/textview/TextDocument.cpp @@ -155,6 +155,14 @@ TextDocument::Insert(int32 textOffset, const BString& text, chunkStart = chunkEnd + 1; } + if (paragraph2.IsEmpty()) { + // Make sure Paragraph has at least one TextSpan, even + // if its empty. + const TextSpanList& spans = paragraph1.TextSpans(); + const TextSpan& span = spans.LastItem(); + paragraph2.Append(TextSpan("", span.Style())); + } + if (!fParagraphs.Add(paragraph2, index)) return B_NO_MEMORY; } else {