From db0e24ccc268d0a9c7575d660a9397e53747894b Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 10 Apr 2019 21:06:19 +0300 Subject: Use already parsed events for replies if possible --- ui/messages/html/blockquote.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ui/messages/html/blockquote.go') diff --git a/ui/messages/html/blockquote.go b/ui/messages/html/blockquote.go index 30ce52e..17799a2 100644 --- a/ui/messages/html/blockquote.go +++ b/ui/messages/html/blockquote.go @@ -18,6 +18,7 @@ package html import ( "fmt" + "strings" "maunium.net/go/mauview" ) @@ -37,6 +38,10 @@ func NewBlockquoteEntity(children []Entity) *BlockquoteEntity { }} } +func (be *BlockquoteEntity) Clone() Entity { + return &BlockquoteEntity{BaseEntity: be.BaseEntity.Clone().(*BaseEntity)} +} + func (be *BlockquoteEntity) Draw(screen mauview.Screen) { be.BaseEntity.Draw(screen) for y := 0; y < be.height; y++ { @@ -44,6 +49,33 @@ func (be *BlockquoteEntity) Draw(screen mauview.Screen) { } } +func (be *BlockquoteEntity) PlainText() string { + if len(be.Children) == 0 { + return "" + } + var buf strings.Builder + newlined := false + for i, child := range be.Children { + if i != 0 && child.IsBlock() && !newlined { + buf.WriteRune('\n') + } + newlined = false + for i, row := range strings.Split(child.PlainText(), "\n") { + if i != 0 { + buf.WriteRune('\n') + } + buf.WriteRune('>') + buf.WriteRune(' ') + buf.WriteString(row) + } + if child.IsBlock() { + buf.WriteRune('\n') + newlined = true + } + } + return strings.TrimSpace(buf.String()) +} + func (be *BlockquoteEntity) String() string { return fmt.Sprintf("&html.BlockquoteEntity{%s},\n", be.BaseEntity) } -- cgit v1.2.3