cursors []*Cursor
curCursor int
StartCursor Loc
+
+ // OptionCallback is called after a buffer option value is changed.
+ // The display module registers its OptionCallback to ensure the buffer window
+ // is properly updated when needed. This is a workaround for the fact that
+ // the buffer module cannot directly call the display's API (it would mean
+ // a circular dependency between packages).
+ OptionCallback func(option string, nativeValue interface{})
}
// NewBufferFromFileAtLoc opens a new buffer with a given cursor location
func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
w := new(BufWindow)
w.View = new(View)
- w.X, w.Y, w.Width, w.Height, w.Buf = x, y, width, height, buf
+ w.X, w.Y, w.Width, w.Height = x, y, width, height
+ w.SetBuffer(buf)
w.active = true
w.sline = NewStatusLine(w)
func (w *BufWindow) SetBuffer(b *buffer.Buffer) {
w.Buf = b
+ b.OptionCallback = func(option string, nativeValue interface{}) {
+ if option == "softwrap" {
+ if nativeValue.(bool) {
+ w.StartCol = 0
+ } else {
+ w.StartLine.Row = 0
+ }
+ w.Relocate()
+ }
+ }
}
func (w *BufWindow) GetView() *View {