feat: fix Ctrl+J newline in TUI
This commit is contained in:
+20
-13
@@ -161,21 +161,25 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
vpWidth := msg.Width - 4 // Account for viewportStyle padding and border
|
vpWidth := msg.Width - 4 // Account for viewportStyle padding and border
|
||||||
vpHeight := msg.Height - headerHeight - inputHeight - 2
|
vpHeight := msg.Height - headerHeight - inputHeight - 2
|
||||||
|
|
||||||
r, _ := glamour.NewTermRenderer(
|
if vpWidth > 0 && vpHeight > 0 {
|
||||||
glamour.WithAutoStyle(),
|
r, err := glamour.NewTermRenderer(
|
||||||
glamour.WithWordWrap(vpWidth-2),
|
glamour.WithStandardStyle("dark"),
|
||||||
)
|
glamour.WithWordWrap(vpWidth-2),
|
||||||
m.renderer = r
|
)
|
||||||
|
if err == nil {
|
||||||
|
m.renderer = r
|
||||||
|
}
|
||||||
|
|
||||||
if !m.ready {
|
if !m.ready {
|
||||||
m.viewport = viewport.New(vpWidth, vpHeight)
|
m.viewport = viewport.New(vpWidth, vpHeight)
|
||||||
m.ready = true
|
m.ready = true
|
||||||
} else {
|
} else {
|
||||||
m.viewport.Width = vpWidth
|
m.viewport.Width = vpWidth
|
||||||
m.viewport.Height = vpHeight
|
m.viewport.Height = vpHeight
|
||||||
|
}
|
||||||
|
m.updateViewportContent()
|
||||||
|
m.viewport.GotoBottom()
|
||||||
}
|
}
|
||||||
m.updateViewportContent()
|
|
||||||
m.viewport.GotoBottom()
|
|
||||||
|
|
||||||
m.textarea.SetWidth(msg.Width - 4)
|
m.textarea.SetWidth(msg.Width - 4)
|
||||||
|
|
||||||
@@ -189,6 +193,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case tea.KeyPgDown, tea.KeyCtrlD:
|
case tea.KeyPgDown, tea.KeyCtrlD:
|
||||||
m.viewport.HalfViewDown()
|
m.viewport.HalfViewDown()
|
||||||
return m, nil
|
return m, nil
|
||||||
|
case tea.KeyCtrlJ:
|
||||||
|
m.textarea.InsertString("\n")
|
||||||
|
return m, nil
|
||||||
case tea.KeyEnter:
|
case tea.KeyEnter:
|
||||||
v := m.textarea.Value()
|
v := m.textarea.Value()
|
||||||
if strings.TrimSpace(v) == "" || m.isThinking {
|
if strings.TrimSpace(v) == "" || m.isThinking {
|
||||||
|
|||||||
Reference in New Issue
Block a user