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(). prog = program.NewProgramBuilder().
EmptyProgram(). EmptyProgram().
WithOpt(tea.WithAltScreen()). WithOpt(tea.WithAltScreen()).
WithOpt(tea.WithMouseCellMotion()).
Build() Build()
} else { } else {
prog = program.NewProgramBuilder(). prog = program.NewProgramBuilder().
FileProgram(args[0]). FileProgram(args[0]).
WithOpt(tea.WithAltScreen()). WithOpt(tea.WithAltScreen()).
WithOpt(tea.WithMouseCellMotion()).
Build() Build()
} }

View File

@ -2,6 +2,7 @@ package editor
import ( import (
"git.gophernest.net/azpect/TextEditor/internal/core" "git.gophernest.net/azpect/TextEditor/internal/core"
"git.gophernest.net/azpect/TextEditor/internal/motion"
tea "github.com/charmbracelet/bubbletea" 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 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: case tea.KeyMsg:
// TODO: This needs to be removed, but for now its required for the tests. // TODO: This needs to be removed, but for now its required for the tests.
// Ctrl+C always quits regardless of mode // Ctrl+C always quits regardless of mode

View File

@ -2,6 +2,7 @@ package editor
import ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"git.gophernest.net/azpect/TextEditor/internal/core" "git.gophernest.net/azpect/TextEditor/internal/core"
@ -22,6 +23,10 @@ func (m Model) View() string {
styles := m.Styles() styles := m.Styles()
options := win.Options 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 // Draw window
view := viewWindow(win, styles, options, m.Mode()) view := viewWindow(win, styles, options, m.Mode())