mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
wip
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
+23
-8
@@ -94,7 +94,7 @@ var DefaultKeyMap = KeyMap{
|
||||
LowercaseWordForward: key.NewBinding(key.WithKeys("alt+l"), key.WithHelp("alt+l", "lowercase word forward")),
|
||||
UppercaseWordForward: key.NewBinding(key.WithKeys("alt+u"), key.WithHelp("alt+u", "uppercase word forward")),
|
||||
|
||||
AcceptSuggestion: key.NewBinding(key.WithKeys("tab")),
|
||||
AcceptSuggestion: key.NewBinding(key.WithKeys("tab", "ctrl+y")),
|
||||
NextSuggestion: key.NewBinding(key.WithKeys("down", "ctrl+n")),
|
||||
PrevSuggestion: key.NewBinding(key.WithKeys("up", "ctrl+p")),
|
||||
|
||||
@@ -996,7 +996,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
keyMsg, ok := msg.(tea.KeyMsg)
|
||||
if ok && key.Matches(keyMsg, m.KeyMap.AcceptSuggestion) {
|
||||
if m.canAcceptSuggestion() {
|
||||
m.value = append(m.value, m.matchedSuggestions[m.currentSuggestionIndex][len(m.value):]...)
|
||||
m.value = m.matchedSuggestions[m.currentSuggestionIndex]
|
||||
m.CursorEnd()
|
||||
}
|
||||
}
|
||||
@@ -1137,7 +1137,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
return m, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
func (m Model) ghostTextView(offset int) string {
|
||||
func (m Model) suggestionView(offset int) string {
|
||||
if !m.canAcceptSuggestion() {
|
||||
return ""
|
||||
}
|
||||
@@ -1147,8 +1147,15 @@ func (m Model) ghostTextView(offset int) string {
|
||||
if len(value) >= len(suggestion) {
|
||||
return ""
|
||||
}
|
||||
str := suggestion[len(m.Value())+offset:]
|
||||
return m.style.Placeholder.Inline(true).Render(str)
|
||||
|
||||
var lines []string
|
||||
for _, line := range strings.Split(suggestion[len(m.Value())+offset:], "\n") {
|
||||
lines = append(lines, m.style.Placeholder.Inline(true).Render(line))
|
||||
}
|
||||
if len(lines) > m.Height() {
|
||||
m.SetHeight(len(lines) + 1)
|
||||
}
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
// View renders the text area in its current state.
|
||||
@@ -1231,16 +1238,23 @@ func (m Model) View() string {
|
||||
ln = m.SyntaxHighlighter(ln)
|
||||
}
|
||||
s.WriteString(ln)
|
||||
|
||||
if m.col >= len(line) && lineInfo.CharOffset >= m.width {
|
||||
m.Cursor.SetChar(" ")
|
||||
s.WriteString(m.Cursor.View())
|
||||
s.WriteString(m.ghostTextView(0))
|
||||
// XXX: suggestions
|
||||
// XXX: suggestions?
|
||||
} else {
|
||||
m.Cursor.SetChar(string(wrappedLine[lineInfo.ColumnOffset]))
|
||||
if m.canAcceptSuggestion() && len(m.matchedSuggestions) > 0 {
|
||||
suggestion := m.matchedSuggestions[m.currentSuggestionIndex][m.row:]
|
||||
m.Cursor.TextStyle = m.style.Placeholder
|
||||
if len(suggestion) > m.row && len(suggestion[m.row]) > m.col {
|
||||
m.Cursor.SetChar(string(suggestion[m.row][m.col]))
|
||||
}
|
||||
}
|
||||
s.WriteString(style.Render(m.Cursor.View()))
|
||||
s.WriteString(style.Render(string(wrappedLine[lineInfo.ColumnOffset+1:])))
|
||||
s.WriteString(m.ghostTextView(1))
|
||||
s.WriteString(m.suggestionView(1))
|
||||
// XXX: suggestions
|
||||
}
|
||||
} else {
|
||||
@@ -1494,6 +1508,7 @@ func (m *Model) updateSuggestions() {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: this should be better
|
||||
matches := [][][]rune{}
|
||||
for _, s := range m.suggestions {
|
||||
suggestion := linesToString(s)
|
||||
|
||||
Reference in New Issue
Block a user