Now we can load them in via JSON files at launch time. They are embded in the final exe though...
167 lines
6.4 KiB
Go
167 lines
6.4 KiB
Go
package action
|
|
|
|
import (
|
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
|
"git.gophernest.net/azpect/TextEditor/internal/theme"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
// MockModel is a shared test implementation of the Model interface.
|
|
// Used by test files across multiple packages to avoid duplication.
|
|
// All fields are exported to allow direct manipulation in tests.
|
|
type MockModel struct {
|
|
WindowsList []*core.Window
|
|
ActiveWindowVal *core.Window
|
|
BuffersList []*core.Buffer
|
|
SettingsVal core.EditorSettings
|
|
ModeVal core.Mode
|
|
RegistersMap map[rune]core.Register
|
|
InsertKeysList []string
|
|
CommandVal string
|
|
CommandCursorVal int
|
|
CommandOutputVal *core.CommandOutput
|
|
CommandHistoryList []string
|
|
CommandHistoryCur int
|
|
LastFindVal core.LastFindCommand
|
|
CurrentThemeName string
|
|
ThemesMap map[string]theme.EditorTheme
|
|
LastChangeKeysList []string
|
|
}
|
|
|
|
// NewMockModel creates a mock with an empty buffer and 24x80 window.
|
|
func NewMockModel() *MockModel {
|
|
buf := core.NewBufferBuilder().
|
|
WithLines([]string{""}).
|
|
Build()
|
|
|
|
win := core.NewWindowBuilder().
|
|
WithBuffer(&buf).
|
|
WithHeight(24).
|
|
WithWidth(80).
|
|
Build()
|
|
|
|
return &MockModel{
|
|
WindowsList: []*core.Window{&win},
|
|
ActiveWindowVal: &win,
|
|
BuffersList: []*core.Buffer{&buf},
|
|
SettingsVal: core.NewDefaultSettings(),
|
|
ModeVal: core.NormalMode,
|
|
RegistersMap: core.DefaultRegisters(),
|
|
CurrentThemeName: "default",
|
|
ThemesMap: map[string]theme.EditorTheme{"default": {}},
|
|
}
|
|
}
|
|
|
|
// NewMockModelWithBuffer creates a mock with a custom buffer.
|
|
func NewMockModelWithBuffer(buf *core.Buffer) *MockModel {
|
|
win := core.NewWindowBuilder().
|
|
WithBuffer(buf).
|
|
WithHeight(24).
|
|
WithWidth(80).
|
|
Build()
|
|
|
|
return &MockModel{
|
|
WindowsList: []*core.Window{&win},
|
|
ActiveWindowVal: &win,
|
|
BuffersList: []*core.Buffer{buf},
|
|
SettingsVal: core.NewDefaultSettings(),
|
|
ModeVal: core.NormalMode,
|
|
RegistersMap: core.DefaultRegisters(),
|
|
CurrentThemeName: "default",
|
|
ThemesMap: map[string]theme.EditorTheme{"default": {}},
|
|
}
|
|
}
|
|
|
|
// NewMockModelWithWindow creates a mock with a custom window.
|
|
func NewMockModelWithWindow(win *core.Window) *MockModel {
|
|
return &MockModel{
|
|
WindowsList: []*core.Window{win},
|
|
ActiveWindowVal: win,
|
|
BuffersList: []*core.Buffer{win.Buffer},
|
|
SettingsVal: core.NewDefaultSettings(),
|
|
ModeVal: core.NormalMode,
|
|
RegistersMap: core.DefaultRegisters(),
|
|
CurrentThemeName: "default",
|
|
ThemesMap: map[string]theme.EditorTheme{"default": {}},
|
|
}
|
|
}
|
|
|
|
// ==================================================
|
|
// Model Interface Implementation
|
|
// ==================================================
|
|
|
|
// Core Data Access
|
|
func (m *MockModel) Windows() []*core.Window { return m.WindowsList }
|
|
func (m *MockModel) ActiveWindow() *core.Window { return m.ActiveWindowVal }
|
|
func (m *MockModel) Buffers() []*core.Buffer { return m.BuffersList }
|
|
func (m *MockModel) SetBuffers(bufs []*core.Buffer) { m.BuffersList = bufs }
|
|
func (m *MockModel) ActiveBuffer() *core.Buffer { return m.ActiveWindowVal.Buffer }
|
|
|
|
// Insert Mode State
|
|
func (m *MockModel) InsertKeys() []string { return m.InsertKeysList }
|
|
func (m *MockModel) SetInsertKeys(keys []string) { m.InsertKeysList = keys }
|
|
func (m *MockModel) SetInsertRecording(count int, a Action) {}
|
|
func (m *MockModel) ExitInsertMode() {}
|
|
func (m *MockModel) SetLastFind(char string, forward, inclusive bool) {
|
|
m.LastFindVal = core.LastFindCommand{Char: char, Forward: forward, Inclusive: inclusive}
|
|
}
|
|
func (m *MockModel) GetLastFind() *core.LastFindCommand { return &m.LastFindVal }
|
|
|
|
// Command Mode State
|
|
func (m *MockModel) Command() string { return m.CommandVal }
|
|
func (m *MockModel) SetCommand(cmd string) { m.CommandVal = cmd }
|
|
func (m *MockModel) CommandCursor() int { return m.CommandCursorVal }
|
|
func (m *MockModel) SetCommandCursor(cur int) { m.CommandCursorVal = cur }
|
|
func (m *MockModel) CommandOutput() *core.CommandOutput { return m.CommandOutputVal }
|
|
func (m *MockModel) SetCommandOutput(out *core.CommandOutput) { m.CommandOutputVal = out }
|
|
func (m *MockModel) CommandHistory() []string { return m.CommandHistoryList }
|
|
func (m *MockModel) SetCommandHistory(history []string) { m.CommandHistoryList = history }
|
|
func (m *MockModel) CommandHistoryCursor() int { return m.CommandHistoryCur }
|
|
func (m *MockModel) SetCommandHistoryCursor(cur int) { m.CommandHistoryCur = cur }
|
|
|
|
// Editor-wide State
|
|
func (m *MockModel) Mode() core.Mode { return m.ModeVal }
|
|
func (m *MockModel) SetMode(mode core.Mode) { m.ModeVal = mode }
|
|
func (m *MockModel) Settings() core.EditorSettings { return m.SettingsVal }
|
|
func (m *MockModel) SetSettings(s core.EditorSettings) { m.SettingsVal = s }
|
|
func (m *MockModel) Theme() (string, theme.EditorTheme) {
|
|
if m.ThemesMap != nil {
|
|
if t, ok := m.ThemesMap[m.CurrentThemeName]; ok {
|
|
return m.CurrentThemeName, t
|
|
}
|
|
if t, ok := m.ThemesMap["default"]; ok {
|
|
return "default", t
|
|
}
|
|
}
|
|
|
|
return m.CurrentThemeName, theme.EditorTheme{}
|
|
}
|
|
func (m *MockModel) SetTheme(name string) { m.CurrentThemeName = name }
|
|
func (m *MockModel) Themes() map[string]theme.EditorTheme {
|
|
if m.ThemesMap == nil {
|
|
m.ThemesMap = map[string]theme.EditorTheme{}
|
|
}
|
|
return m.ThemesMap
|
|
}
|
|
func (m *MockModel) SetThemes(t map[string]theme.EditorTheme) { m.ThemesMap = t }
|
|
|
|
// Registers
|
|
func (m *MockModel) Registers() map[rune]core.Register { return m.RegistersMap }
|
|
func (m *MockModel) GetRegister(name rune) (core.Register, bool) {
|
|
reg, ok := m.RegistersMap[name]
|
|
return reg, ok
|
|
}
|
|
func (m *MockModel) SetRegister(name rune, t core.RegisterType, cnt []string) error {
|
|
m.RegistersMap[name] = core.Register{Type: t, Content: cnt}
|
|
return nil
|
|
}
|
|
func (m *MockModel) UpdateDefaultRegister(t core.RegisterType, cnt []string) {
|
|
m.RegistersMap['"'] = core.Register{Type: t, Content: cnt}
|
|
}
|
|
|
|
// Dot operator
|
|
func (m *MockModel) SetLastChangeKeys(keys []string) { m.LastChangeKeysList = keys }
|
|
func (m *MockModel) LastChangeKeys() []string { return m.LastChangeKeysList }
|
|
func (m *MockModel) ClearLastChangeKeys() { m.LastChangeKeysList = []string{} }
|
|
func (m *MockModel) HandleKey(key string) tea.Cmd { return nil }
|