mirror of
https://github.com/sst/opencode.git
synced 2025-07-22 15:25:00 +00:00
feat(tui): more ways to quit
This commit is contained in:
parent
93c779cf48
commit
f7dd48e60d
4 changed files with 8 additions and 10 deletions
|
@ -336,7 +336,7 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||||
Name: AppExitCommand,
|
Name: AppExitCommand,
|
||||||
Description: "exit the app",
|
Description: "exit the app",
|
||||||
Keybindings: parseBindings("ctrl+c", "<leader>q"),
|
Keybindings: parseBindings("ctrl+c", "<leader>q"),
|
||||||
Trigger: []string{"exit", "quit"},
|
Trigger: []string{"exit", "quit", "q"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
registry := make(CommandRegistry)
|
registry := make(CommandRegistry)
|
||||||
|
|
|
@ -77,7 +77,6 @@ func (c *CommandCompletionProvider) GetChildEntries(
|
||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use fuzzy matching for commands
|
|
||||||
var commandNames []string
|
var commandNames []string
|
||||||
commandMap := make(map[string]CompletionSuggestion)
|
commandMap := make(map[string]CompletionSuggestion)
|
||||||
|
|
||||||
|
@ -86,17 +85,13 @@ func (c *CommandCompletionProvider) GetChildEntries(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
space := space - lipgloss.Width(cmd.PrimaryTrigger())
|
space := space - lipgloss.Width(cmd.PrimaryTrigger())
|
||||||
// Add all triggers as searchable options
|
|
||||||
for _, trigger := range cmd.Trigger {
|
for _, trigger := range cmd.Trigger {
|
||||||
commandNames = append(commandNames, trigger)
|
commandNames = append(commandNames, trigger)
|
||||||
commandMap[trigger] = c.getCommandCompletionItem(cmd, space)
|
commandMap[trigger] = c.getCommandCompletionItem(cmd, space)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find fuzzy matches
|
|
||||||
matches := fuzzy.RankFindFold(query, commandNames)
|
matches := fuzzy.RankFindFold(query, commandNames)
|
||||||
|
|
||||||
// Sort by score (best matches first)
|
|
||||||
sort.Sort(matches)
|
sort.Sort(matches)
|
||||||
|
|
||||||
// Convert matches to completion items, deduplicating by command name
|
// Convert matches to completion items, deduplicating by command name
|
||||||
|
|
|
@ -344,6 +344,12 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) {
|
||||||
if value == "" {
|
if value == "" {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch value {
|
||||||
|
case "exit", "quit", "q", ":q":
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
|
|
||||||
if len(value) > 0 && value[len(value)-1] == '\\' {
|
if len(value) > 0 && value[len(value)-1] == '\\' {
|
||||||
// If the last character is a backslash, remove it and add a newline
|
// If the last character is a backslash, remove it and add a newline
|
||||||
m.textarea.ReplaceRange(len(value)-1, len(value), "")
|
m.textarea.ReplaceRange(len(value)-1, len(value), "")
|
||||||
|
|
|
@ -85,7 +85,7 @@ func (c *completionDialogComponent) getAllCompletions(query string) tea.Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's a query, use fuzzy ranking to sort results
|
// If there's a query, use fuzzy ranking to sort results
|
||||||
if query != "" && len(allItems) > 0 {
|
if query != "" && len(allItems) > 0 && len(c.providers) > 1 {
|
||||||
t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
baseStyle := styles.NewStyle().Background(t.BackgroundElement())
|
baseStyle := styles.NewStyle().Background(t.BackgroundElement())
|
||||||
// Create a slice of display values for fuzzy matching
|
// Create a slice of display values for fuzzy matching
|
||||||
|
@ -94,10 +94,7 @@ func (c *completionDialogComponent) getAllCompletions(query string) tea.Cmd {
|
||||||
displayValues[i] = item.Display(baseStyle)
|
displayValues[i] = item.Display(baseStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fuzzy matches with ranking
|
|
||||||
matches := fuzzy.RankFindFold(query, displayValues)
|
matches := fuzzy.RankFindFold(query, displayValues)
|
||||||
|
|
||||||
// Sort by score (best matches first)
|
|
||||||
sort.Sort(matches)
|
sort.Sort(matches)
|
||||||
|
|
||||||
// Reorder items based on fuzzy ranking
|
// Reorder items based on fuzzy ranking
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue