diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index e143eb0..89471d8 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -9,8 +9,9 @@ import ( ) type Model struct { - vi viminput.Model - focus bool + vi viminput.Model + focus bool + locked bool } func New() Model { @@ -32,7 +33,9 @@ func New() Model { // vi.Focus() return Model{ - vi: vi, + vi: vi, + focus: false, + locked: false, } } @@ -48,9 +51,31 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { if !m.focus { return m, nil } - var cmd tea.Cmd - m.vi, cmd = m.vi.Update(msg) - return m, cmd + + if m.locked { + InNormal := m.vi.Mode() == viminput.NormalMode + if key, ok := msg.(tea.KeyMsg); ok && InNormal { + if key.String() == "q" { + m.locked = false + return m, nil + } + } + + var cmd tea.Cmd + m.vi, cmd = m.vi.Update(msg) + return m, cmd + } + + switch msg := msg.(type) { + case tea.KeyMsg: + key := msg.String() + switch key { + case "i": + m.locked = true + } + } + + return m, nil } func (m *Model) Focus() { @@ -62,3 +87,7 @@ func (m *Model) Blur() { m.focus = false m.vi.Blur() } + +func (m Model) Locked() bool { + return m.locked +} diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index dd29106..5d87294 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -265,15 +265,17 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { return cmd } - left := msg.String() == "H" - right := msg.String() == "L" - direction := 0 - if left { - direction = -1 - } else if right { - direction = 1 + if m.focus != FocusChat || !m.chat.Locked() { + left := msg.String() == "H" + right := msg.String() == "L" + direction := 0 + if left { + direction = -1 + } else if right { + direction = 1 + } + m.move(direction) } - m.move(direction) } } diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go index e4886a4..c562574 100644 --- a/internal/client/ui/viminput/viminput.go +++ b/internal/client/ui/viminput/viminput.go @@ -1738,3 +1738,7 @@ func (m *Model) handleVisualLineModeKeys(key tea.KeyMsg) { } } } + +func (m Model) Mode() int { + return m.mode +}