Gim/internal/action/window.go
2026-02-26 12:14:59 -07:00

57 lines
980 B
Go

package action
// TODO: No more global settings, window-wide settings
type WinOptions struct {
// Number bool
// Wrap bool
// Relnumber bool
}
type Window struct {
Id int
Number int // Ignored for now, will be used when splits come into play
Buffer *Buffer
Cursor Position
Anchor Position
ScrollY int
Width int
Height int
// Folds // TODO
// Options WinOptions
}
// Not great, but maybe the best way
var CurrentWindowId int = 1000
func NewEmptyWindow(lines []string, w, h int) *Window {
win := &Window{
Id: CurrentWindowId,
Number: 1, // Ignored for now
Buffer: NewEmptyBuffer(lines),
Cursor: Position{Line: 0, Col: 0},
Anchor: Position{Line: 0, Col: 0},
ScrollY: 0,
Width: w,
Height: h,
}
// Increment
CurrentWindowId++
return win
}
func (w *Window) ClampCursorX() {
lineLen := len(w.Buffer.Lines[w.Cursor.Line])
if lineLen == 0 {
w.Cursor.Col = 0
} else if w.Cursor.Col >= lineLen {
w.Cursor.Col = lineLen
}
}