diff --git a/src/apps/mail/Content.cpp b/src/apps/mail/Content.cpp index bf41d56cdc..249e0d11c1 100644 --- a/src/apps/mail/Content.cpp +++ b/src/apps/mail/Content.cpp @@ -3121,6 +3121,7 @@ TTextView::AddQuote(int32 start, int32 finish) int32 lineStart; GoToLine(CurrentLine()); GetSelection(&lineStart, &lineStart); + lineStart = LineStart(lineStart); // make sure that we're changing the whole last line, too int32 lineEnd = finish > lineStart ? finish - 1 : finish; @@ -3198,6 +3199,7 @@ TTextView::RemoveQuote(int32 start, int32 finish) GoToLine(CurrentLine()); int32 lineStart; GetSelection(&lineStart, &lineStart); + lineStart = LineStart(lineStart); // make sure that we're changing the whole last line, too int32 lineEnd = finish > lineStart ? finish - 1 : finish; @@ -3280,6 +3282,39 @@ TTextView::RemoveQuote(int32 start, int32 finish) } +int32 +TTextView::LineStart(int32 offset) +{ + if (offset <= 0) + return 0; + + while (offset > 0) { + offset = PreviousByte(offset); + if (ByteAt(offset) == B_ENTER) + return offset + 1; + } + + return offset; +} + + +int32 +TTextView::PreviousByte(int32 offset) const +{ + if (offset <= 0) + return 0; + + int32 count = 6; + + for (--offset; offset > 0 && count; --offset, --count) { + if ((ByteAt(offset) & 0xC0) != 0x80) + break; + } + + return count ? offset : 0; +} + + void TTextView::Undo(BClipboard */*clipboard*/) { @@ -3374,4 +3409,3 @@ TTextView::Redo() fUndoBuffer.On(); } } - diff --git a/src/apps/mail/Content.h b/src/apps/mail/Content.h index 703e986e88..2465801406 100644 --- a/src/apps/mail/Content.h +++ b/src/apps/mail/Content.h @@ -208,6 +208,9 @@ class TTextView : public BTextView { void ContentChanged(void); + int32 LineStart(int32 offset); + int32 PreviousByte(int32 offset) const; + class Reader; friend class TTextView::Reader;