diff --git a/src/components/LuceneQueryEditor.tsx b/src/components/LuceneQueryEditor.tsx index 85cfd6d..99e3518 100644 --- a/src/components/LuceneQueryEditor.tsx +++ b/src/components/LuceneQueryEditor.tsx @@ -2,16 +2,15 @@ import React, { useRef, useCallback } from "react"; import { css } from "@emotion/css"; -import CodeMirror, { ReactCodeMirrorRef, keymap } from '@uiw/react-codemirror'; +import CodeMirror, { ReactCodeMirrorRef, keymap} from '@uiw/react-codemirror'; import {linter, Diagnostic, lintGutter} from "@codemirror/lint" -import {autocompletion, CompletionContext} from "@codemirror/autocomplete" +import {autocompletion, CompletionContext, CompletionResult} from "@codemirror/autocomplete" import { LuceneQuery } from "@/utils/lucene"; - export type LuceneQueryEditorProps = { placeholder?: string, value: string, - autocompleter: (word: string) => any, + autocompleter: (word: string) => CompletionResult, onChange: (query: string) => void onSubmit: (query: string) => void } @@ -39,10 +38,10 @@ export function LuceneQueryEditor(props: LuceneQueryEditorProps){ let suggestions; let word = context.matchBefore(/\S*/); if (!word){ return null } - suggestions = await autocompleter(word?.text); + suggestions = await autocompleter(word?.text); if (suggestions && suggestions.options.length > 0 ) { // Fixes autocompletion inserting an extra quote when the cursor is before a quote - const cursorIsBeforeQuote = context.state.doc.toString().slice(context.pos, context.pos + 1) === '"'; + const cursorIsBeforeQuote = /^\s*"/.test(context.state.doc.toString().slice(context.pos)); if (cursorIsBeforeQuote) { suggestions.options = suggestions.options.map(o => ({...o, apply: `${o.label.replace(/"$/g, '')}`})); }