Remove multistep autocomplete
This commit is contained in:
parent
a8bc3e1f96
commit
bb51be900d
packages/builder/src/components/common/CodeEditor
|
@ -7,7 +7,7 @@ import {
|
||||||
Helper,
|
Helper,
|
||||||
Snippet,
|
Snippet,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { CompletionContext, startCompletion } from "@codemirror/autocomplete"
|
import { CompletionContext } from "@codemirror/autocomplete"
|
||||||
import { EditorView } from "@codemirror/view"
|
import { EditorView } from "@codemirror/view"
|
||||||
import { BindingCompletion } from "@/types"
|
import { BindingCompletion } from "@/types"
|
||||||
|
|
||||||
|
@ -131,8 +131,7 @@ export const snippetAutoComplete = (snippets: Snippet[]): BindingCompletion => {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.matchBefore(/\$\("[\s\w]*/)) {
|
if (wrappedAutocompleteMatch(context)) {
|
||||||
// We are handing a js field completion
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,11 +200,15 @@ export const hbAutocomplete = (
|
||||||
return coreCompletion
|
return coreCompletion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wrappedAutocompleteMatch(context: CompletionContext) {
|
||||||
|
return context.matchBefore(/\$\("[\s\w]*/)
|
||||||
|
}
|
||||||
|
|
||||||
export const jsAutocomplete = (
|
export const jsAutocomplete = (
|
||||||
baseCompletions: BindingCompletionOption[]
|
baseCompletions: BindingCompletionOption[]
|
||||||
): BindingCompletion => {
|
): BindingCompletion => {
|
||||||
function coreCompletion(context: CompletionContext) {
|
function coreCompletion(context: CompletionContext) {
|
||||||
let jsBinding = context.matchBefore(/\$\("[\s\w]*/)
|
let jsBinding = wrappedAutocompleteMatch(context)
|
||||||
let options = baseCompletions || []
|
let options = baseCompletions || []
|
||||||
|
|
||||||
if (jsBinding) {
|
if (jsBinding) {
|
||||||
|
@ -233,61 +236,26 @@ export const jsHelperAutocomplete = (
|
||||||
baseCompletions: BindingCompletionOption[]
|
baseCompletions: BindingCompletionOption[]
|
||||||
): BindingCompletion => {
|
): BindingCompletion => {
|
||||||
function coreCompletion(context: CompletionContext) {
|
function coreCompletion(context: CompletionContext) {
|
||||||
if (context.matchBefore(/\$\("[\s\w]*/)) {
|
if (wrappedAutocompleteMatch(context)) {
|
||||||
// We are handing a js field completion
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
let jsBinding = context.matchBefore(/\bhelpers\.\w*/)
|
let jsBinding = context.matchBefore(/\b(\w+\.?).*/)
|
||||||
|
if (!jsBinding || !"helpers.".startsWith(jsBinding.text.split(".")[0])) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
if (jsBinding) {
|
if (jsBinding) {
|
||||||
let options = baseCompletions || []
|
let options = baseCompletions || []
|
||||||
const match = jsBinding.text.match(/\bhelpers\.(?<helper>\w*)/)
|
const match = jsBinding.text.match(/\bhelpers\.(?<helper>\w*)/)
|
||||||
if (!match) {
|
const query = match?.groups?.["helper"] || ""
|
||||||
return null
|
|
||||||
}
|
|
||||||
const query = match.groups?.["helper"] || ""
|
|
||||||
let filtered = bindingFilter(options, query)
|
let filtered = bindingFilter(options, query)
|
||||||
return {
|
return {
|
||||||
from: jsBinding.from,
|
from: jsBinding.from,
|
||||||
to: jsBinding.from + match[0].length,
|
to: jsBinding.from + jsBinding.text.length,
|
||||||
filter: false,
|
filter: false,
|
||||||
options: filtered,
|
options: filtered,
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const prefix = context.matchBefore(/\b\w+/)
|
|
||||||
if (prefix && "helpers.".startsWith(prefix.text)) {
|
|
||||||
return {
|
|
||||||
from: context.pos - prefix.text.length,
|
|
||||||
to: context.pos,
|
|
||||||
filter: false,
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
label: "helpers.",
|
|
||||||
type: "text",
|
|
||||||
simple: true,
|
|
||||||
apply: (
|
|
||||||
view: EditorView,
|
|
||||||
_completion: BindingCompletionOption,
|
|
||||||
from: number,
|
|
||||||
to: number
|
|
||||||
) => {
|
|
||||||
insertBinding(
|
|
||||||
view,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
"helpers.",
|
|
||||||
EditorModes.JS,
|
|
||||||
AutocompleteType.TEXT
|
|
||||||
)
|
|
||||||
|
|
||||||
// Trigger again the completion, to chain it with the helpers completion
|
|
||||||
startCompletion(view)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
Loading…
Reference in New Issue