summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2021-11-24 16:59:00 +0100
committerHubert Hirtz <hubert@hirtz.pm>2021-11-24 17:34:21 +0100
commitb813210eb6b7a50607985a14f969e33914ae0956 (patch)
treec110cb7cf453ef49ab57a9c8c41baf988a492e66 /ui
parentShow the current channel topic at the top of the timeline (diff)
Add support for draft/event-playback
- Refactor formatting lines into a function - Store event times in the event - Refactor merging lines into a function - Always merge lines from the history, now that we will add mergeable lines with CHATHISTORY Successfully tested locally.
Diffstat (limited to 'ui')
-rw-r--r--ui/buffers.go53
1 files changed, 31 insertions, 22 deletions
diff --git a/ui/buffers.go b/ui/buffers.go
index 9a20abe..d277491 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -39,6 +39,21 @@ type Line struct {
newLines []int
}
+func (l *Line) IsZero() bool {
+ return l.Body.string == ""
+}
+
+func (l *Line) Merge(line Line) {
+ newBody := new(StyledStringBuilder)
+ newBody.Grow(len(l.Body.string) + 2 + len(line.Body.string))
+ newBody.WriteStyledString(l.Body)
+ newBody.WriteString(" ")
+ newBody.WriteStyledString(line.Body)
+ l.Body = newBody.StyledString()
+ l.computeSplitPoints()
+ l.width = 0
+}
+
func (l *Line) computeSplitPoints() {
if l.splitPoints == nil {
l.splitPoints = []point{}
@@ -307,14 +322,7 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)
if line.Mergeable && n != 0 && b.lines[n-1].Mergeable {
l := &b.lines[n-1]
- newBody := new(StyledStringBuilder)
- newBody.Grow(len(l.Body.string) + 2 + len(line.Body.string))
- newBody.WriteStyledString(l.Body)
- newBody.WriteString(" ")
- newBody.WriteStyledString(line.Body)
- l.Body = newBody.StyledString()
- l.computeSplitPoints()
- l.width = 0
+ l.Merge(line)
// TODO change b.scrollAmt if it's not 0 and bs.current is idx.
} else {
line.computeSplitPoints()
@@ -340,21 +348,22 @@ func (bs *BufferList) AddLines(netID, title string, before, after []Line) {
b := &bs.list[idx]
- for i := 0; i < len(before); i++ {
- before[i].Body = before[i].Body.ParseURLs()
- before[i].computeSplitPoints()
- }
- for i := 0; i < len(after); i++ {
- after[i].Body = after[i].Body.ParseURLs()
- after[i].computeSplitPoints()
- }
-
- if len(before) != 0 {
- b.lines = append(before, b.lines...)
- }
- if len(after) != 0 {
- b.lines = append(b.lines, after...)
+ lines := make([]Line, 0, len(before)+len(b.lines)+len(after))
+ for _, buf := range []*[]Line{&before, &b.lines, &after} {
+ for _, line := range *buf {
+ if line.Mergeable && len(lines) > 0 && lines[len(lines)-1].Mergeable {
+ l := &lines[len(lines)-1]
+ l.Merge(line)
+ } else {
+ if buf != &b.lines {
+ line.Body = line.Body.ParseURLs()
+ line.computeSplitPoints()
+ }
+ lines = append(lines, line)
+ }
+ }
}
+ b.lines = lines
}
func (bs *BufferList) SetTopic(netID, title string, topic string) {