@@ -2,16 +2,15 @@ import React, { useRef, useCallback } from "react";
2
2
import { css } from "@emotion/css" ;
3
3
4
4
5
- import CodeMirror , { ReactCodeMirrorRef , keymap } from '@uiw/react-codemirror' ;
5
+ import CodeMirror , { ReactCodeMirrorRef , keymap } from '@uiw/react-codemirror' ;
6
6
import { linter , Diagnostic , lintGutter } from "@codemirror/lint"
7
- import { autocompletion , CompletionContext } from "@codemirror/autocomplete"
7
+ import { autocompletion , CompletionContext , CompletionResult } from "@codemirror/autocomplete"
8
8
import { LuceneQuery } from "@/utils/lucene" ;
9
9
10
-
11
10
export type LuceneQueryEditorProps = {
12
11
placeholder ?: string ,
13
12
value : string ,
14
- autocompleter : ( word : string ) => any ,
13
+ autocompleter : ( word : string ) => CompletionResult ,
15
14
onChange : ( query : string ) => void
16
15
onSubmit : ( query : string ) => void
17
16
}
@@ -39,10 +38,10 @@ export function LuceneQueryEditor(props: LuceneQueryEditorProps){
39
38
let suggestions ;
40
39
let word = context . matchBefore ( / \S * / ) ;
41
40
if ( ! word ) { return null }
42
- suggestions = await autocompleter ( word ?. text ) ;
41
+ suggestions = await autocompleter ( word ?. text ) ;
43
42
if ( suggestions && suggestions . options . length > 0 ) {
44
43
// 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 ) ) ;
46
45
if ( cursorIsBeforeQuote ) {
47
46
suggestions . options = suggestions . options . map ( o => ( { ...o , apply : `${ o . label . replace ( / " $ / g, '' ) } ` } ) ) ;
48
47
}
0 commit comments