I am using CodeMirror6 autocompletion, I was wonder how to get the user select text when using auto completion? This is the code right now:
export function texAutoCompletions(context: CompletionContext) {
//let selectedText = context.activatedCompletion ? context.activatedCompletion.apply : '';
let word = context.matchBefore(/\[w\]*/);
if (!word) return null;
if (word.from === word.to && !context.explicit) return null;
return {
from: word.from,
options: [
snippetCompletion("\begin{#{1}}",{
label: "\begin{}",
type: "text",
detail: "env",
}),
{ label: "\section{}", type: "text", apply: "\section{}" },
{ label: "\subsection{}", type: "text", apply: "\subsection{}" },
{ label: "\usepackage{}", type: "text", apply: "\usepackage{}" },
{ label: "\footnote{}", type: "text", apply: "\footnote{}" },
],
};
}
how to get which commend the user select in current trigger or next trigger? I have tried:
let selectedText = context.activatedCompletion ? context.activatedCompletion.apply : '';
but it could not works. I have turned on the trigger when user select auto completement code like this:
const texEditorState = EditorState.create({
doc: ytext.toString(),
extensions: [
basicSetup,
autocompletion({
override: [texAutoCompletions],
tooltipClass: ttc,
activateOnCompletion: (com: Completion) => {
return true;
},
}),
],
});