|
@@ -51,7 +51,7 @@ type appModel struct {
|
|
|
editor chat.EditorComponent
|
|
editor chat.EditorComponent
|
|
|
messages chat.MessagesComponent
|
|
messages chat.MessagesComponent
|
|
|
completions dialog.CompletionDialog
|
|
completions dialog.CompletionDialog
|
|
|
- completionManager *completions.CompletionManager
|
|
|
|
|
|
|
+ commandProvider dialog.CompletionProvider
|
|
|
showCompletionDialog bool
|
|
showCompletionDialog bool
|
|
|
leaderBinding *key.Binding
|
|
leaderBinding *key.Binding
|
|
|
isLeaderSequence bool
|
|
isLeaderSequence bool
|
|
@@ -105,6 +105,7 @@ var BUGGED_SCROLL_KEYS = map[string]bool{
|
|
|
"m": true,
|
|
"m": true,
|
|
|
"[": true,
|
|
"[": true,
|
|
|
";": true,
|
|
";": true,
|
|
|
|
|
+ "<": true,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func isScrollRelatedInput(keyString string) bool {
|
|
func isScrollRelatedInput(keyString string) bool {
|
|
@@ -134,6 +135,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
switch msg := msg.(type) {
|
|
switch msg := msg.(type) {
|
|
|
case tea.KeyPressMsg:
|
|
case tea.KeyPressMsg:
|
|
|
keyString := msg.String()
|
|
keyString := msg.String()
|
|
|
|
|
+
|
|
|
if time.Since(a.lastScroll) < time.Millisecond*100 && (BUGGED_SCROLL_KEYS[keyString] || isScrollRelatedInput(keyString)) {
|
|
if time.Since(a.lastScroll) < time.Millisecond*100 && (BUGGED_SCROLL_KEYS[keyString] || isScrollRelatedInput(keyString)) {
|
|
|
return a, nil
|
|
return a, nil
|
|
|
}
|
|
}
|
|
@@ -174,37 +176,16 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 3. Handle completions trigger
|
|
// 3. Handle completions trigger
|
|
|
- if keyString == "/" && !a.showCompletionDialog {
|
|
|
|
|
|
|
+ if keyString == "/" &&
|
|
|
|
|
+ !a.showCompletionDialog &&
|
|
|
|
|
+ a.editor.Value() == "" {
|
|
|
a.showCompletionDialog = true
|
|
a.showCompletionDialog = true
|
|
|
|
|
|
|
|
- initialValue := "/"
|
|
|
|
|
- currentInput := a.editor.Value()
|
|
|
|
|
-
|
|
|
|
|
- // if the input doesn't end with a space,
|
|
|
|
|
- // then we want to include the last word
|
|
|
|
|
- // (ie, `packages/`)
|
|
|
|
|
- if !strings.HasSuffix(currentInput, " ") {
|
|
|
|
|
- words := strings.Split(a.editor.Value(), " ")
|
|
|
|
|
- if len(words) > 0 {
|
|
|
|
|
- lastWord := words[len(words)-1]
|
|
|
|
|
- lastWord = strings.TrimSpace(lastWord)
|
|
|
|
|
- initialValue = lastWord + "/"
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- updated, cmd := a.completions.Update(
|
|
|
|
|
- app.CompletionDialogTriggeredMsg{
|
|
|
|
|
- InitialValue: initialValue,
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- a.completions = updated.(dialog.CompletionDialog)
|
|
|
|
|
- cmds = append(cmds, cmd)
|
|
|
|
|
-
|
|
|
|
|
- updated, cmd = a.editor.Update(msg)
|
|
|
|
|
|
|
+ updated, cmd := a.editor.Update(msg)
|
|
|
a.editor = updated.(chat.EditorComponent)
|
|
a.editor = updated.(chat.EditorComponent)
|
|
|
cmds = append(cmds, cmd)
|
|
cmds = append(cmds, cmd)
|
|
|
|
|
|
|
|
- updated, cmd = a.updateCompletions(msg)
|
|
|
|
|
|
|
+ updated, cmd = a.completions.Update(msg)
|
|
|
a.completions = updated.(dialog.CompletionDialog)
|
|
a.completions = updated.(dialog.CompletionDialog)
|
|
|
cmds = append(cmds, cmd)
|
|
cmds = append(cmds, cmd)
|
|
|
|
|
|
|
@@ -214,7 +195,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
if a.showCompletionDialog {
|
|
if a.showCompletionDialog {
|
|
|
switch keyString {
|
|
switch keyString {
|
|
|
case "tab", "enter", "esc", "ctrl+c":
|
|
case "tab", "enter", "esc", "ctrl+c":
|
|
|
- updated, cmd := a.updateCompletions(msg)
|
|
|
|
|
|
|
+ updated, cmd := a.completions.Update(msg)
|
|
|
a.completions = updated.(dialog.CompletionDialog)
|
|
a.completions = updated.(dialog.CompletionDialog)
|
|
|
cmds = append(cmds, cmd)
|
|
cmds = append(cmds, cmd)
|
|
|
return a, tea.Batch(cmds...)
|
|
return a, tea.Batch(cmds...)
|
|
@@ -224,7 +205,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
a.editor = updated.(chat.EditorComponent)
|
|
a.editor = updated.(chat.EditorComponent)
|
|
|
cmds = append(cmds, cmd)
|
|
cmds = append(cmds, cmd)
|
|
|
|
|
|
|
|
- updated, cmd = a.updateCompletions(msg)
|
|
|
|
|
|
|
+ updated, cmd = a.completions.Update(msg)
|
|
|
a.completions = updated.(dialog.CompletionDialog)
|
|
a.completions = updated.(dialog.CompletionDialog)
|
|
|
cmds = append(cmds, cmd)
|
|
cmds = append(cmds, cmd)
|
|
|
|
|
|
|
@@ -971,22 +952,12 @@ func (a appModel) executeCommand(command commands.Command) (tea.Model, tea.Cmd)
|
|
|
return a, tea.Batch(cmds...)
|
|
return a, tea.Batch(cmds...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (a appModel) updateCompletions(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
|
- currentInput := a.editor.Value()
|
|
|
|
|
- if currentInput != "" {
|
|
|
|
|
- provider := a.completionManager.GetProvider(currentInput)
|
|
|
|
|
- a.completions.SetProvider(provider)
|
|
|
|
|
- }
|
|
|
|
|
- return a.completions.Update(msg)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func NewModel(app *app.App) tea.Model {
|
|
func NewModel(app *app.App) tea.Model {
|
|
|
- completionManager := completions.NewCompletionManager(app)
|
|
|
|
|
- initialProvider := completionManager.DefaultProvider()
|
|
|
|
|
|
|
+ commandProvider := completions.NewCommandCompletionProvider(app)
|
|
|
|
|
|
|
|
messages := chat.NewMessagesComponent(app)
|
|
messages := chat.NewMessagesComponent(app)
|
|
|
editor := chat.NewEditorComponent(app)
|
|
editor := chat.NewEditorComponent(app)
|
|
|
- completions := dialog.NewCompletionDialogComponent(initialProvider)
|
|
|
|
|
|
|
+ completions := dialog.NewCompletionDialogComponent(commandProvider)
|
|
|
|
|
|
|
|
var leaderBinding *key.Binding
|
|
var leaderBinding *key.Binding
|
|
|
if app.Config.Keybinds.Leader != "" {
|
|
if app.Config.Keybinds.Leader != "" {
|
|
@@ -1000,7 +971,7 @@ func NewModel(app *app.App) tea.Model {
|
|
|
editor: editor,
|
|
editor: editor,
|
|
|
messages: messages,
|
|
messages: messages,
|
|
|
completions: completions,
|
|
completions: completions,
|
|
|
- completionManager: completionManager,
|
|
|
|
|
|
|
+ commandProvider: commandProvider,
|
|
|
leaderBinding: leaderBinding,
|
|
leaderBinding: leaderBinding,
|
|
|
isLeaderSequence: false,
|
|
isLeaderSequence: false,
|
|
|
showCompletionDialog: false,
|
|
showCompletionDialog: false,
|