Removed the duplicated model creation methods.

This commit is contained in:
Hayden Hargreaves 2026-02-10 11:06:51 -07:00
parent 2438da08d4
commit c62bbc89ee
3 changed files with 9 additions and 22 deletions

View File

@ -1,15 +1,16 @@
package main
import (
"git.gophernest.net/azpect/TextEditor/internal/action"
"git.gophernest.net/azpect/TextEditor/internal/editor"
tea "github.com/charmbracelet/bubbletea"
)
func main() {
// TODO: Not how this should work, of course
lines := []string{"Hello world", "line 2", "line 3", "line 4", "line 5"}
tea.NewProgram(
editor.NewModel(lines),
editor.NewModel(lines, action.Position{Line: 0, Col: 0}),
tea.WithAltScreen(),
).Run()
}

View File

@ -4,9 +4,9 @@ import (
"testing"
"time"
"git.gophernest.net/azpect/TextEditor/internal/action"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/exp/teatest"
"git.gophernest.net/azpect/TextEditor/internal/action"
)
// sendKeys sends a sequence of keys to the test model
@ -32,20 +32,20 @@ func sendKeys(tm *teatest.TestModel, keys ...string) {
// newTestModel creates a test model with default content
func newTestModel(t *testing.T) *teatest.TestModel {
lines := []string{"line 1", "line 2", "line 3", "line 4", "line 5", "line 6"}
return teatest.NewTestModel(t, NewModel(lines), teatest.WithInitialTermSize(80, 24))
return teatest.NewTestModel(t, NewModel(lines, action.Position{Col: 0, Line: 0}), teatest.WithInitialTermSize(80, 24))
}
func newTestModelWithLines(t *testing.T, lines []string) *teatest.TestModel {
return teatest.NewTestModel(t, NewModel(lines), teatest.WithInitialTermSize(80, 24))
return teatest.NewTestModel(t, NewModel(lines, action.Position{Col: 0, Line: 0}), teatest.WithInitialTermSize(80, 24))
}
func newTestModelWithCursorPos(t *testing.T, pos action.Position) *teatest.TestModel {
lines := []string{"line 1", "line 2", "line 3", "line 4", "line 5", "line 6"}
return teatest.NewTestModel(t, NewModelWithPos(lines, pos), teatest.WithInitialTermSize(80, 24))
return teatest.NewTestModel(t, NewModel(lines, pos), teatest.WithInitialTermSize(80, 24))
}
func newTestModelWithCursorPosAndLines(t *testing.T, lines []string, pos action.Position) *teatest.TestModel {
return teatest.NewTestModel(t, NewModelWithPos(lines, pos), teatest.WithInitialTermSize(80, 24))
return teatest.NewTestModel(t, NewModel(lines, pos), teatest.WithInitialTermSize(80, 24))
}
// getFinalModel extracts the final model state (sends ctrl+c to quit first)

View File

@ -27,21 +27,7 @@ type Model struct {
insertAction action.Action
}
func NewModel(lines []string) Model {
return Model{
lines: lines,
cursor: cursor{
x: 0,
y: 0,
},
s_gutter: 5,
mode: action.NormalMode,
command: "",
input: input.NewHandler(),
}
}
func NewModelWithPos(lines []string, pos action.Position) Model {
func NewModel(lines []string, pos action.Position) Model {
return Model{
lines: lines,
cursor: cursor{