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 @@ -159,6 +159,7 @@ const ESQLEditorInternal = function ESQLEditor({
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>();
const editorModelUriRef = useRef<string | undefined>(undefined);
const containerRef = useRef<HTMLElement>(null);
const suppressSuggestionsRef = useRef(false);

const editorCommandDisposables = useRef(
new WeakMap<monaco.editor.IStandaloneCodeEditor, monaco.IDisposable[]>()
Expand Down Expand Up @@ -479,6 +480,10 @@ const ESQLEditorInternal = function ESQLEditor({

const triggerSuggestions = useCallback(() => {
setTimeout(() => {
if (suppressSuggestionsRef.current) {
suppressSuggestionsRef.current = false;
return;
}
editorRef.current?.trigger(undefined, 'editor.action.triggerSuggest', {});
}, 0);
}, []);
Expand Down Expand Up @@ -761,6 +766,7 @@ const ESQLEditorInternal = function ESQLEditor({
editorRef,
editorModel,
openIndicesBrowser,
suppressSuggestionsRef,
});

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ interface UseSourcesBadgeParams {
editorRef: MutableRefObject<monaco.editor.IStandaloneCodeEditor | undefined>;
editorModel: MutableRefObject<monaco.editor.ITextModel | undefined>;
openIndicesBrowser: (options?: { openedFrom?: IndicesBrowserOpenMode }) => void;
suppressSuggestionsRef: MutableRefObject<boolean>;
}

export const useSourcesBadge = ({
editorRef,
editorModel,
openIndicesBrowser,
suppressSuggestionsRef,
}: UseSourcesBadgeParams) => {
const { euiTheme } = useEuiTheme();
const decorationsRef = useRef<monaco.editor.IEditorDecorationsCollection | undefined>(undefined);
Expand Down Expand Up @@ -127,11 +129,17 @@ export const useSourcesBadge = ({
firstSupportedCommand.range.endColumn + 1
);
editor.setPosition(positionAfterCommand);
editor.revealPosition(positionAfterCommand);

suppressSuggestionsRef.current = true;

openIndicesBrowser({ openedFrom: IndicesBrowserOpenMode.Badge });

// Remove focus from the editor immediately so there is no visible
// focus state while the popover mounts and takes over.
(editor.getDomNode()?.ownerDocument.activeElement as HTMLElement)?.blur();
Comment thread
stratoula marked this conversation as resolved.
}
},
[editorModel, editorRef, openIndicesBrowser]
[editorModel, editorRef, openIndicesBrowser, suppressSuggestionsRef]
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ export function BrowserPopoverWrapper<TItem extends { name: string }>({
searchInputRef.current = node;
};

// Focus the search input when popover opens
// Focus the search input as soon as the popover opens so that focus
// transfers away from the editor immediately (avoids visible flicker).
useEffect(() => {
if (isOpen && !isLoading) {
// Use setTimeout to ensure the DOM is ready
setTimeout(() => {
if (isOpen) {
requestAnimationFrame(() => {
searchInputRef.current?.focus();
}, 0);
});
}
}, [isOpen, isLoading]);
}, [isOpen]);

const filterButton = (
<EuiFilterButton
Expand Down
Loading