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
This commit is contained in:
2024-12-16 18:19:18 +02:00
parent 91992de3c0
commit 2b0812ae7e
3 changed files with 49 additions and 14 deletions

View File

@@ -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
}

View File

@@ -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)
}
}

View File

@@ -1738,3 +1738,7 @@ func (m *Model) handleVisualLineModeKeys(key tea.KeyMsg) {
}
}
}
func (m Model) Mode() int {
return m.mode
}