Skip to content

Commit 9a3eea6

Browse files
committed
fix(autocomplete): do not insert extra quote when completing between two quotes
1 parent 70a45a1 commit 9a3eea6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/components/LuceneQueryEditor.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import React, { useRef, useCallback } from "react";
22
import { css } from "@emotion/css";
33

44

5-
import CodeMirror, { ReactCodeMirrorRef, keymap } from '@uiw/react-codemirror';
5+
import CodeMirror, { ReactCodeMirrorRef, keymap} from '@uiw/react-codemirror';
66
import {linter, Diagnostic, lintGutter} from "@codemirror/lint"
7-
import {autocompletion, CompletionContext} from "@codemirror/autocomplete"
7+
import {autocompletion, CompletionContext, CompletionResult} from "@codemirror/autocomplete"
88
import { LuceneQuery } from "@/utils/lucene";
99

10-
1110
export 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

Comments
 (0)