fix: added gutter fix and basic scroll
All checks were successful
Run Test Suite / test (push) Successful in 15s

Scrolling is pretty useless, but nice touch
This commit is contained in:
Hayden Hargreaves 2026-04-05 00:16:19 -07:00
parent a5ff18e1de
commit 58082afdd2
3 changed files with 86 additions and 67 deletions

View File

@ -23,11 +23,13 @@ func main() {
prog = program.NewProgramBuilder().
EmptyProgram().
WithOpt(tea.WithAltScreen()).
WithOpt(tea.WithMouseCellMotion()).
Build()
} else {
prog = program.NewProgramBuilder().
FileProgram(args[0]).
WithOpt(tea.WithAltScreen()).
WithOpt(tea.WithMouseCellMotion()).
Build()
}

View File

@ -2,6 +2,7 @@ package editor
import (
"git.gophernest.net/azpect/TextEditor/internal/core"
"git.gophernest.net/azpect/TextEditor/internal/motion"
tea "github.com/charmbracelet/bubbletea"
)
@ -49,6 +50,17 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.windows[i].Width = msg.Width
}
// TODO: This is not great, totally temporary. But I don't like vim's handling, so this is up to me
case tea.MouseMsg:
switch msg.Button {
case tea.MouseButtonWheelUp:
scrollAction := motion.ScrollUpPage{Divisor: 4} // Quarter page
cmd = scrollAction.Execute(m)
case tea.MouseButtonWheelDown:
scrollAction := motion.ScrollDownPage{Divisor: 4} // Quarter page
cmd = scrollAction.Execute(m)
}
case tea.KeyMsg:
// TODO: This needs to be removed, but for now its required for the tests.
// Ctrl+C always quits regardless of mode

View File

@ -2,6 +2,7 @@ package editor
import (
"fmt"
"strconv"
"strings"
"git.gophernest.net/azpect/TextEditor/internal/core"
@ -22,6 +23,10 @@ func (m Model) View() string {
styles := m.Styles()
options := win.Options
// Adjust gutter to fit line len
maxLineLen := len(strconv.Itoa(win.Buffer.LineCount()))
options.GutterSize = max(options.GutterSize, maxLineLen+2)
// Draw window
view := viewWindow(win, styles, options, m.Mode())