mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 19:03:50 +00:00
Implement fuzzy search for model/session selector and improve Input multi-key sequence handling (#122)
* implement fuzzy search and filtering for tui selectors * update changelog and readme * add correct pr to changelog
This commit is contained in:
parent
ca39e899f4
commit
ff047e5ee1
7 changed files with 251 additions and 27 deletions
|
|
@ -113,6 +113,31 @@ export class Input implements Component {
|
|||
return;
|
||||
}
|
||||
|
||||
if (data.charCodeAt(0) === 23) {
|
||||
// Ctrl+W - delete word backwards
|
||||
this.deleteWordBackwards();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data === "\x1b\x7f") {
|
||||
// Option/Alt+Backspace - delete word backwards
|
||||
this.deleteWordBackwards();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.charCodeAt(0) === 21) {
|
||||
// Ctrl+U - delete from cursor to start of line
|
||||
this.value = this.value.slice(this.cursor);
|
||||
this.cursor = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.charCodeAt(0) === 11) {
|
||||
// Ctrl+K - delete from cursor to end of line
|
||||
this.value = this.value.slice(0, this.cursor);
|
||||
return;
|
||||
}
|
||||
|
||||
// Regular character input
|
||||
if (data.length === 1 && data >= " " && data <= "~") {
|
||||
this.value = this.value.slice(0, this.cursor) + data + this.value.slice(this.cursor);
|
||||
|
|
@ -120,6 +145,37 @@ export class Input implements Component {
|
|||
}
|
||||
}
|
||||
|
||||
private deleteWordBackwards(): void {
|
||||
if (this.cursor === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const text = this.value.slice(0, this.cursor);
|
||||
let deleteFrom = this.cursor;
|
||||
|
||||
const isWhitespace = (char: string): boolean => /\s/.test(char);
|
||||
const isPunctuation = (char: string): boolean => /[(){}[\]<>.,;:'"!?+\-=*/\\|&%^$#@~`]/.test(char);
|
||||
|
||||
const charBeforeCursor = text[deleteFrom - 1] ?? "";
|
||||
|
||||
// If immediately on whitespace or punctuation, delete that single boundary char
|
||||
if (isWhitespace(charBeforeCursor) || isPunctuation(charBeforeCursor)) {
|
||||
deleteFrom -= 1;
|
||||
} else {
|
||||
// Otherwise, delete a run of non-boundary characters (the "word")
|
||||
while (deleteFrom > 0) {
|
||||
const ch = text[deleteFrom - 1] ?? "";
|
||||
if (isWhitespace(ch) || isPunctuation(ch)) {
|
||||
break;
|
||||
}
|
||||
deleteFrom -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.value = text.slice(0, deleteFrom) + this.value.slice(this.cursor);
|
||||
this.cursor = deleteFrom;
|
||||
}
|
||||
|
||||
private handlePaste(pastedText: string): void {
|
||||
// Clean the pasted text - remove newlines and carriage returns
|
||||
const cleanText = pastedText.replace(/\r\n/g, "").replace(/\r/g, "").replace(/\n/g, "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue