Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2024-10-11 11:32:29 -04:00
committed by Christian Rocha
parent 874d67721b
commit ab7ca0eb5a
+16
View File
@@ -1137,6 +1137,20 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}
func (m Model) ghostTextView(offset int) string {
if !m.canAcceptSuggestion() {
return ""
}
value := linesToString(m.value)
suggestion := linesToString(m.matchedSuggestions[m.currentSuggestionIndex])
if len(value) >= len(suggestion) {
return ""
}
str := suggestion[len(m.Value())+offset:]
return m.style.Placeholder.Inline(true).Render(str)
}
// View renders the text area in its current state.
func (m Model) View() string {
if m.Value() == "" && m.row == 0 && m.col == 0 && m.Placeholder != "" {
@@ -1220,11 +1234,13 @@ func (m Model) View() string {
if m.col >= len(line) && lineInfo.CharOffset >= m.width {
m.Cursor.SetChar(" ")
s.WriteString(m.Cursor.View())
s.WriteString(m.ghostTextView(0))
// XXX: suggestions
} else {
m.Cursor.SetChar(string(wrappedLine[lineInfo.ColumnOffset]))
s.WriteString(style.Render(m.Cursor.View()))
s.WriteString(style.Render(string(wrappedLine[lineInfo.ColumnOffset+1:])))
s.WriteString(m.ghostTextView(1))
// XXX: suggestions
}
} else {