diff --git a/cmd/gim/main.go b/cmd/gim/main.go index 32a8e63..664b95f 100644 --- a/cmd/gim/main.go +++ b/cmd/gim/main.go @@ -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() } diff --git a/internal/editor/helpers_test.go b/internal/editor/helpers_test.go index 384a49c..ef44d8a 100644 --- a/internal/editor/helpers_test.go +++ b/internal/editor/helpers_test.go @@ -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) diff --git a/internal/editor/model.go b/internal/editor/model.go index dc11b95..bb6b917 100644 --- a/internal/editor/model.go +++ b/internal/editor/model.go @@ -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{