Add entry history browsing to UI
This commit is contained in:
+47
-2
@@ -13,6 +13,9 @@ import (
|
||||
)
|
||||
|
||||
func (u *ui) loadSelectedEntryIntoEditor() {
|
||||
u.selectedHistoryIndex = -1
|
||||
u.historyIndex.SetText("")
|
||||
|
||||
item, ok := u.selectedEntry()
|
||||
if !ok {
|
||||
u.entryID.SetText("")
|
||||
@@ -44,6 +47,33 @@ func (u *ui) loadSelectedEntryIntoEditor() {
|
||||
u.exportAttachmentPath.SetText("")
|
||||
}
|
||||
|
||||
func (u *ui) visibleHistory() []vault.Entry {
|
||||
item, ok := u.selectedEntry()
|
||||
if !ok || len(item.History) == 0 {
|
||||
return nil
|
||||
}
|
||||
return append([]vault.Entry(nil), item.History...)
|
||||
}
|
||||
|
||||
func (u *ui) selectedHistoryEntry() (vault.Entry, bool) {
|
||||
history := u.visibleHistory()
|
||||
if u.selectedHistoryIndex < 0 || u.selectedHistoryIndex >= len(history) {
|
||||
return vault.Entry{}, false
|
||||
}
|
||||
return history[u.selectedHistoryIndex], true
|
||||
}
|
||||
|
||||
func (u *ui) selectHistoryVersion(index int) error {
|
||||
history := u.visibleHistory()
|
||||
if index < 0 || index >= len(history) {
|
||||
return fmt.Errorf("history index %d out of range", index)
|
||||
}
|
||||
|
||||
u.selectedHistoryIndex = index
|
||||
u.historyIndex.SetText(strconv.Itoa(index))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ui) saveEntryAction() error {
|
||||
entry, err := u.editorEntry()
|
||||
if err != nil {
|
||||
@@ -223,9 +253,9 @@ func (u *ui) removeAttachmentAction() error {
|
||||
}
|
||||
|
||||
func (u *ui) restoreSelectedHistoryAction() error {
|
||||
index, err := strconv.Atoi(strings.TrimSpace(u.historyIndex.Text()))
|
||||
index, err := u.selectedHistoryVersionIndex()
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid history index: %w", err)
|
||||
return err
|
||||
}
|
||||
if err := u.state.RestoreSelectedEntryVersion(index); err != nil {
|
||||
return err
|
||||
@@ -235,6 +265,21 @@ func (u *ui) restoreSelectedHistoryAction() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ui) selectedHistoryVersionIndex() (int, error) {
|
||||
text := strings.TrimSpace(u.historyIndex.Text())
|
||||
if text != "" {
|
||||
index, err := strconv.Atoi(text)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("invalid history index: %w", err)
|
||||
}
|
||||
return index, nil
|
||||
}
|
||||
if u.selectedHistoryIndex >= 0 {
|
||||
return u.selectedHistoryIndex, nil
|
||||
}
|
||||
return 0, fmt.Errorf("no history version selected")
|
||||
}
|
||||
|
||||
func (u *ui) copySelectedFieldAction(target clipboard.Target) error {
|
||||
model, err := u.state.Session.Current()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user