@@ -2,16 +2,15 @@ import React, { useRef, useCallback } from "react";
22import { css } from "@emotion/css" ;
33
44
5- import CodeMirror , { ReactCodeMirrorRef , keymap } from '@uiw/react-codemirror' ;
5+ import CodeMirror , { ReactCodeMirrorRef , keymap } from '@uiw/react-codemirror' ;
66import { linter , Diagnostic , lintGutter } from "@codemirror/lint"
7- import { autocompletion , CompletionContext } from "@codemirror/autocomplete"
7+ import { autocompletion , CompletionContext , CompletionResult } from "@codemirror/autocomplete"
88import { LuceneQuery } from "@/utils/lucene" ;
99
10-
1110export type LuceneQueryEditorProps = {
1211 placeholder ?: string ,
1312 value : string ,
14- autocompleter : ( word : string ) => any ,
13+ autocompleter : ( word : string ) => CompletionResult ,
1514 onChange : ( query : string ) => void
1615 onSubmit : ( query : string ) => void
1716}
@@ -39,10 +38,10 @@ export function LuceneQueryEditor(props: LuceneQueryEditorProps){
3938 let suggestions ;
4039 let word = context . matchBefore ( / \S * / ) ;
4140 if ( ! word ) { return null }
42- suggestions = await autocompleter ( word ?. text ) ;
41+ suggestions = await autocompleter ( word ?. text ) ;
4342 if ( suggestions && suggestions . options . length > 0 ) {
4443 // Fixes autocompletion inserting an extra quote when the cursor is before a quote
45- const cursorIsBeforeQuote = context . state . doc . toString ( ) . slice ( context . pos , context . pos + 1 ) === '"' ;
44+ const cursorIsBeforeQuote = / ^ \s * " / . test ( context . state . doc . toString ( ) . slice ( context . pos ) ) ;
4645 if ( cursorIsBeforeQuote ) {
4746 suggestions . options = suggestions . options . map ( o => ( { ...o , apply : `${ o . label . replace ( / " $ / g, '' ) } ` } ) ) ;
4847 }
0 commit comments