mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 09:01:14 +00:00
Merge branch 'fix/slash-menu-trigger-clean'
This commit is contained in:
commit
e13d97f765
2 changed files with 22 additions and 6 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Slash command menu now only triggers when the editor input is otherwise empty ([#904](https://github.com/badlogic/pi-mono/issues/904))
|
||||
|
||||
## [0.49.3] - 2026-01-22
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -984,7 +984,7 @@ export class Editor implements Component, Focusable {
|
|||
const currentLine = this.state.lines[this.state.cursorLine] || "";
|
||||
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
|
||||
// Check if we're in a slash command (with or without space for arguments)
|
||||
if (textBeforeCursor.trimStart().startsWith("/")) {
|
||||
if (this.isInSlashCommandContext(textBeforeCursor)) {
|
||||
this.tryTriggerAutocomplete();
|
||||
}
|
||||
// Check if we're in an @ file reference context
|
||||
|
|
@ -1169,7 +1169,7 @@ export class Editor implements Component, Focusable {
|
|||
const currentLine = this.state.lines[this.state.cursorLine] || "";
|
||||
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
|
||||
// Slash command context
|
||||
if (textBeforeCursor.trimStart().startsWith("/")) {
|
||||
if (this.isInSlashCommandContext(textBeforeCursor)) {
|
||||
this.tryTriggerAutocomplete();
|
||||
}
|
||||
// @ file reference context
|
||||
|
|
@ -1388,7 +1388,7 @@ export class Editor implements Component, Focusable {
|
|||
const currentLine = this.state.lines[this.state.cursorLine] || "";
|
||||
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
|
||||
// Slash command context
|
||||
if (textBeforeCursor.trimStart().startsWith("/")) {
|
||||
if (this.isInSlashCommandContext(textBeforeCursor)) {
|
||||
this.tryTriggerAutocomplete();
|
||||
}
|
||||
// @ file reference context
|
||||
|
|
@ -1802,15 +1802,27 @@ export class Editor implements Component, Focusable {
|
|||
}
|
||||
}
|
||||
|
||||
// Slash menu only allowed when all other lines are empty (no mixed content)
|
||||
private isSlashMenuAllowed(): boolean {
|
||||
for (let i = 0; i < this.state.lines.length; i++) {
|
||||
if (i === this.state.cursorLine) continue;
|
||||
if (this.state.lines[i].trim() !== "") return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper method to check if cursor is at start of message (for slash command detection)
|
||||
private isAtStartOfMessage(): boolean {
|
||||
if (!this.isSlashMenuAllowed()) return false;
|
||||
const currentLine = this.state.lines[this.state.cursorLine] || "";
|
||||
const beforeCursor = currentLine.slice(0, this.state.cursorCol);
|
||||
|
||||
// At start if line is empty, only contains whitespace, or is just "/"
|
||||
return beforeCursor.trim() === "" || beforeCursor.trim() === "/";
|
||||
}
|
||||
|
||||
private isInSlashCommandContext(textBeforeCursor: string): boolean {
|
||||
return this.isSlashMenuAllowed() && textBeforeCursor.trimStart().startsWith("/");
|
||||
}
|
||||
|
||||
// Autocomplete methods
|
||||
private tryTriggerAutocomplete(explicitTab: boolean = false): void {
|
||||
if (!this.autocompleteProvider) return;
|
||||
|
|
@ -1848,7 +1860,7 @@ export class Editor implements Component, Focusable {
|
|||
const beforeCursor = currentLine.slice(0, this.state.cursorCol);
|
||||
|
||||
// Check if we're in a slash command context
|
||||
if (beforeCursor.trimStart().startsWith("/") && !beforeCursor.trimStart().includes(" ")) {
|
||||
if (this.isInSlashCommandContext(beforeCursor) && !beforeCursor.trimStart().includes(" ")) {
|
||||
this.handleSlashCommandCompletion();
|
||||
} else {
|
||||
this.forceFileAutocomplete();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue