From 6ea16d0b9c578a77334bc14fb95af0f773df750c Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 18 Jun 2020 12:23:42 -0400 Subject: [PATCH] Add command to sync scrollable area with renderer This is necessary for initial paints, and probably for resizes. --- renderer.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/renderer.go b/renderer.go index e121be9..4fc872e 100644 --- a/renderer.go +++ b/renderer.go @@ -259,6 +259,10 @@ func (r *renderer) handleMessages(msg Msg) { case clearIgnoredLinesMsg: r.clearIgnoredLines() + case syncScrollAreaMsg: + r.setIgnoredLines(msg.topBoundary, msg.bottomBoundary) + r.insertTop(msg.lines, msg.topBoundary, msg.bottomBoundary) + case scrollUpMsg: r.insertTop(msg.lines, msg.topBoundary, msg.bottomBoundary) @@ -309,8 +313,6 @@ func ClearIgnoredLines() Msg { return clearIgnoredLinesMsg{} } -// scrollDownMsg is experiemental. There are no guarantees about it persisting -// in a future API. It's exposed for high performance scrolling. type scrollUpMsg struct { lines []string topBoundary int @@ -327,8 +329,6 @@ func ScrollUp(newLines []string, topBoundary, bottomBoundary int) Cmd { } } -// scrollDownMsg is experiemental. There are no guarantees about it persisting -// in a future API. It's exposed for high performance scrolling. type scrollDownMsg struct { lines []string topBoundary int @@ -344,3 +344,19 @@ func ScrollDown(newLines []string, topBoundary, bottomBoundary int) Cmd { } } } + +type syncScrollAreaMsg struct { + lines []string + topBoundary int + bottomBoundary int +} + +func SyncScrollArea(lines []string, topBoundary int, bottomBoundary int) Cmd { + return func() Msg { + return syncScrollAreaMsg{ + lines: lines, + topBoundary: topBoundary, + bottomBoundary: bottomBoundary, + } + } +}