mirror of
https://github.com/sst/opencode.git
synced 2025-08-04 13:30:52 +00:00
fix(tui): insert newline correctly positioned
This commit is contained in:
parent
261e76e0a3
commit
40b1dd7ef2
2 changed files with 10 additions and 7 deletions
|
@ -214,8 +214,7 @@ func (m *editorComponent) Paste() (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
func (m *editorComponent) Newline() (tea.Model, tea.Cmd) {
|
||||
value := m.textarea.Value()
|
||||
m.textarea.SetValue(value + "\n")
|
||||
m.textarea.Newline()
|
||||
return m, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -553,6 +553,14 @@ func (m Model) Line() int {
|
|||
return m.row
|
||||
}
|
||||
|
||||
func (m *Model) Newline() {
|
||||
if m.MaxHeight > 0 && len(m.value) >= m.MaxHeight {
|
||||
return
|
||||
}
|
||||
m.col = clamp(m.col, 0, len(m.value[m.row]))
|
||||
m.splitLine(m.row, m.col)
|
||||
}
|
||||
|
||||
// CursorDown moves the cursor down by one line.
|
||||
// Returns whether or not the cursor blink should be reset.
|
||||
func (m *Model) CursorDown() {
|
||||
|
@ -1113,11 +1121,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||
}
|
||||
m.deleteWordRight()
|
||||
case key.Matches(msg, m.KeyMap.InsertNewline):
|
||||
if m.MaxHeight > 0 && len(m.value) >= m.MaxHeight {
|
||||
return m, nil
|
||||
}
|
||||
m.col = clamp(m.col, 0, len(m.value[m.row]))
|
||||
m.splitLine(m.row, m.col)
|
||||
m.Newline()
|
||||
case key.Matches(msg, m.KeyMap.LineEnd):
|
||||
m.CursorEnd()
|
||||
case key.Matches(msg, m.KeyMap.LineStart):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue