summaryrefslogtreecommitdiff
path: root/internal/client/ui/core/chat
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-12-16 18:19:18 +0200
committerKyren223 <Kyren223@proton.me>2024-12-16 18:19:18 +0200
commit2b0812ae7e2b2bd57b2c0d2d873f728da7a78437 (patch)
treec425988ab21d0e641e22b521dc1039fd9081830e /internal/client/ui/core/chat
parent91992de3c09c2bd88a995bac6822e3c3678b08dc (diff)
Added capability for chat to be "locked" into viminput, which solves the
issue of H/L, they can now be typed normally, pressing "i" to go into locked mode and "q" (in normal mode) to leave it
Diffstat (limited to 'internal/client/ui/core/chat')
-rw-r--r--internal/client/ui/core/chat/chat.go41
1 files changed, 35 insertions, 6 deletions
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
+}