Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect scrolling when Wrap is set to true #97

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions _examples/wrap_autoscroll.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2014 The gocui Authors. All rights reserved.
glvr182 marked this conversation as resolved.
Show resolved Hide resolved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
"errors"
"fmt"
"log"

"github.com/awesome-gocui/gocui"
)

var tabCount = 0

func main() {
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
defer g.Close()

g.SetManagerFunc(layout)

if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, print); err != nil {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
log.Panicln(err)
}
}

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("main", maxX/2-7, maxY/2-1, maxX/2+7, maxY/2+4, 0); err != nil {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}

if _, err := g.SetCurrentView("main"); err != nil {
return err
}
v.Clear()
v.Autoscroll = true
v.Wrap = true

fmt.Fprintln(v, "Hello world!")
}

return nil
}

func print(g *gocui.Gui, v *gocui.View) error {
tabCount++
if tabCount%10 == 0 {
fmt.Fprintln(v, tabCount, "Hello!")
} else {
fmt.Fprintln(v, tabCount, "Hello Cruel World !")
}
return nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
2 changes: 1 addition & 1 deletion view.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func (v *View) draw() error {
linesToRender := v.viewLines()

if v.Autoscroll && len(linesToRender) > maxY {
v.oy = len(v.lines) - maxY
v.oy = len(linesToRender) - maxY - 1
}

newCache := []cellCache{}
Expand Down