From b75cb83397e32fc3bc8ead40f34efadafda6fb70 Mon Sep 17 00:00:00 2001 From: Nomeji Date: Thu, 23 Jun 2022 12:05:32 +0200 Subject: Scroll to the channel when changing the horizontal channel Previously, when running CTRL+N or CTRL+P to go to the next or previous channel, with the horizontal channel mode, the selected channel could appear offscreen. This patch ensures that we scroll just enough to make the newly selected chan visible. Thanks to Nomeji for his hard work on this. Adapted slightly to refactor existing code to use the newly created width computation routine. --- ui/ui.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ui/ui.go') diff --git a/ui/ui.go b/ui/ui.go index 77757cb..9e4af88 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -452,6 +452,22 @@ func (ui *UI) Draw(members []irc.Member) { ui.screen.Show() } +func (ui *UI) HorizontalBufferScrollTo() { + w, _ := ui.screen.Size() + screenWidth := w - ui.memberWidth + if ui.bs.current < ui.channelOffset { + ui.channelOffset = ui.bs.current + return + } + + leftMost := ui.bs.GetLeftMost(screenWidth) + + if ui.channelOffset >= leftMost { + return + } + ui.channelOffset = leftMost +} + func (ui *UI) drawStatusBar(x0, y, width int) { clearArea(ui.screen, x0, y, width, 1) -- cgit v1.2.3