Skip to content

Commit

Permalink
Fix CodeMirror6 search issue
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Feb 27, 2024
1 parent a6ef4ee commit 80b4d08
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/contentScript/codeMirror6Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ export default function codeMirror6Plugin(pluginContext: PluginContext, CodeMirr
const { EditorSelection } = require('@codemirror/state') as typeof CodeMirrorStateType;

const completeMarkdown = async (completionContext: CompletionContext): Promise<CompletionResult> => {
const prefix = completionContext.matchBefore(/[@][@]\w+/);
// Start completions on @@, match any characters that aren't in "()[]{};>,\n"
const prefix = completionContext.matchBefore(/[@][@][^()\[\]{};:>,\n]*/);
if (!prefix || (prefix.from === prefix.to && !completionContext.explicit)) {
return null;
}

const searchText = prefix.text.substring(2); // Remove @@s
const response = await pluginContext.postMessage({
command: 'getNotes',
prefix: prefix.text,
prefix: searchText,
});

const createApplyCompletionFn = (noteTitle: string, noteId: string) => {
Expand Down Expand Up @@ -63,7 +65,7 @@ export default function codeMirror6Plugin(pluginContext: PluginContext, CodeMirr
}

const addNewNoteCompletion = (todo: boolean) => {
const title = prefix.text.substring(2);
const title = searchText;
const description = todo ? 'New Task' : 'New Note';
completions.push({
label: description,
Expand All @@ -81,7 +83,7 @@ export default function codeMirror6Plugin(pluginContext: PluginContext, CodeMirr
});
};

if (response.allowNewNotes) {
if (response.allowNewNotes && searchText.length > 0) {
addNewNoteCompletion(true);
addNewNoteCompletion(false);
}
Expand Down

0 comments on commit 80b4d08

Please sign in to comment.