MCPcopy
hub / github.com/yorukot/superfile / HandleUpdate

Method HandleUpdate

src/internal/ui/zoxide/model.go:34–88  ·  view source on GitHub ↗
(msg tea.Msg)

Source from the content-addressed store, hash-verified

32}
33
34func (m *Model) HandleUpdate(msg tea.Msg) (common.ModelAction, tea.Cmd) {
35 slog.Debug("zoxide.Model HandleUpdate()", "msg", msg,
36 "msgType", reflect.TypeOf(msg),
37 "textInput", m.textInput.Value(),
38 "cursorBlink", m.textInput.Styles().Cursor.Blink)
39 var action common.ModelAction
40 action = common.NoAction{}
41 var cmd tea.Cmd
42 if !m.IsOpen() {
43 slog.Error("HandleUpdate called on closed zoxide")
44 return action, cmd
45 }
46
47 switch msg := msg.(type) {
48 case tea.KeyPressMsg:
49 // If zoxide is not available, only allow confirm/cancel to close modal
50 if m.zClient == nil {
51 switch {
52 case slices.Contains(common.Hotkeys.ConfirmTyping, msg.String()),
53 slices.Contains(common.Hotkeys.CancelTyping, msg.String()),
54 slices.Contains(common.Hotkeys.Quit, msg.String()):
55 m.Close()
56 }
57 return action, cmd
58 }
59
60 switch {
61 case slices.Contains(common.Hotkeys.ConfirmTyping, msg.String()):
62 action = m.handleConfirm()
63 m.Close()
64 case slices.Contains(common.Hotkeys.CancelTyping, msg.String()):
65 m.Close()
66 // We dont want keys like `j` and `k` to get stuck here
67 // So if its a navigation key, lets specifically ignore
68 // the alphanumeric keys as zoxide panel is in text input
69 // mode by default
70 case slices.Contains(common.Hotkeys.ListUp, msg.String()) && !isKeyAlphaNum(msg):
71 m.navigateUp()
72 case slices.Contains(common.Hotkeys.ListDown, msg.String()) && !isKeyAlphaNum(msg):
73 m.navigateDown()
74 case slices.Contains(common.Hotkeys.OpenZoxide, msg.String()) && m.justOpened:
75 // Ignore the 'z' key that just opened this modal to prevent it from appearing in text input
76 m.justOpened = false
77 default:
78 cmd = m.handleNormalKeyInput(msg)
79 }
80 default:
81 // Non keypress updates like Cursor Blink
82 // Only update text input if zoxide is available
83 if m.zClient != nil {
84 m.textInput, cmd = m.textInput.Update(msg)
85 }
86 }
87 return action, cmd
88}
89
90func (m *Model) handleConfirm() common.ModelAction {
91 // If we have results and a valid selection, navigate to selected result

Callers 2

updateComponentStateMethod · 0.45
TestJKKeyHandlingFunction · 0.45

Calls 10

IsOpenMethod · 0.95
CloseMethod · 0.95
handleConfirmMethod · 0.95
navigateUpMethod · 0.95
navigateDownMethod · 0.95
handleNormalKeyInputMethod · 0.95
isKeyAlphaNumFunction · 0.85
UpdateMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestJKKeyHandlingFunction · 0.36