feat: updated cache implementation and fixed bugs

This commit is contained in:
David Allen 2025-06-20 14:14:38 -06:00
parent 17dbfa2b3b
commit e71f33878e
Signed by: towk
GPG key ID: 0430CDBE22619155
7 changed files with 550 additions and 97 deletions

60
internal/cache/state.go vendored Normal file
View file

@ -0,0 +1,60 @@
package cache
type editorState interface{}
type selecting struct{}
type editting struct{}
type Editor struct {
state editorState
}
// transition between state
func NewEditor() Editor {
return Editor{state: selecting{}}
}
func (e *Editor) StartEditting() editting {
e.state = editting{}
return e.state.(editting)
}
func (e *Editor) StopEditting() selecting {
e.state = selecting{}
return e.state.(selecting)
}
func (s editting) FinishEditting(e *Editor) selecting {
e.state = selecting{}
return e.state.(selecting)
}
func (e *Editor) GetState() editorState {
return e.state
}
func (e *Editor) GetStateString() string {
switch e.state.(type) {
case selecting:
return "selecting"
case editting:
return "editting"
}
return ""
}
func (e *Editor) IsEditting() bool {
return e.GetStateString() == "editting"
}
func (e *Editor) IsSelecting() bool {
return e.GetStateString() == "selecting"
}
func test() {
editor := NewEditor()
editting := editor.StartEditting()
// ...later on...
editting.FinishEditting(&editor)
}