1

我试图让我的编辑器在用户键入“自定义”后自动完成。

到目前为止,我所做的是将 identifierRegexps 更改为[/[a-zA-Z_0-9\.\-\u00A2-\uFFFF]/] 允许我确定“。”之后的完整前缀。

我可以看到代码正在进入该editor.commands.on部分,但是“自定义”时未显示自动完成弹出窗口。是键入的。

我发现我可以做到的一种方法是添加“自定义”。到wordList数组中的所有单词,但我希望自动完成弹出窗口只显示“Method1”而不是“custom.Method1”。

componentDidMount() {
        addCompleter({
            identifierRegexps: [/[a-zA-Z_0-9\.\-\u00A2-\uFFFF]/],
            getCompletions: function(editor, session, pos, prefix, callback) {
                var completions: any[] = [];
                var wordList
                
                if (prefix == "custom."){
                    wordList = [Method1, Date, Method2];
                    wordList.forEach(function (w) {
                        completions.push({
                            value: w,
                        });
                    });
                    editor.commands.on("afterExec", function (e: { command: { name: string; }; args: string; editor: { completers: any[]; execCommand: (arg0: string) => void; }; }, t: any) {
                        if (e.command.name == "insertstring" && e.args == ".") {
                            e.editor.execCommand("startAutocomplete");
                            e.editor.execCommand("showPopup");
                        }
                    })
                }
                callback(null, completions);               
            }
        })
    }
4

0 回答 0