Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const AutocompletePane = ({
<div className="flex flex-col gap-1">
<span className="text-[11.5px] font-medium">Keymap</span>
<div className="autocomplete-keymap text-[10.5px]">
<kbd>Tab</kbd> accept · <kbd>Esc</kbd> dismiss · <kbd>{getPlatformModifierKey()}</kbd>+<kbd>\</kbd> trigger
<kbd>Tab</kbd> accept · <kbd>{getPlatformModifierKey()}</kbd>+<kbd>→</kbd> accept word · <kbd>Esc</kbd> dismiss · <kbd>{getPlatformModifierKey()}</kbd>+<kbd>\</kbd> trigger
</div>
</div>
</div>
Expand Down
46 changes: 43 additions & 3 deletions packages/bruno-app/src/utils/codemirror/aiGhostText.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { aiAutocomplete, cancelAiAutocomplete } from 'utils/ai';
* Inline (ghost-text) AI autocomplete for CodeMirror 5 script editors.
*
* Suggestion is rendered as a faded bookmark widget at the cursor:
* Tab accept the whole suggestion
* Esc dismiss
* Cmd/Ctrl+\ manually trigger (and only way to trigger in manual mode)
* Tab accept the whole suggestion
* Cmd/Ctrl+Right accept the next word from the suggestion
* Esc dismiss
* Cmd/Ctrl+\ manually trigger (and only way to trigger in manual mode)
*
* Trigger modes from preferences:
* aggressive -> debounce 100ms (feels keystroke-level but coalesces bursts)
Expand Down Expand Up @@ -266,6 +267,33 @@ const acceptAll = (cm) => {
return true;
};

const nextWord = (text) => {
if (!text) return '';
const m = text.match(/^\s*(\w+|[^\w\s])/);
return m ? m[0] : text;
};

const acceptWord = (cm) => {
const s = getState(cm);
if (!s.suggestion) return false;
const word = nextWord(s.suggestion);
if (!word) return false;
const remainder = s.suggestion.slice(word.length);
const cursor = cm.getCursor();
clearGhost(cm);
cm.replaceRange(word, cursor, cursor, '+ai-autocomplete');
if (remainder) {
showGhost(cm, remainder);
const newCursorIdx = cm.indexFromPos(cm.getCursor());
s.reusePrefix = cm.getValue().slice(0, newCursorIdx);
s.reuseSuggestion = remainder;
} else {
s.reusePrefix = null;
s.reuseSuggestion = null;
}
return true;
};

const dismiss = (cm) => {
const s = getState(cm);
if (!s.suggestion) return false;
Expand Down Expand Up @@ -354,6 +382,18 @@ export const setupAiAutocomplete = (editor, options) => {
return;
}

if (
event.key === 'ArrowRight'
&& (event.metaKey || event.ctrlKey)
&& !event.shiftKey
&& !event.altKey
) {
event.preventDefault();
event.stopPropagation();
acceptWord(cm);
return;
}

if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
Expand Down
Loading