Skip to content

Commit

Permalink
handle space in path in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Mar 16, 2024
1 parent 3d24728 commit 486bb81
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/pages/Drive/markdown/plugins/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ export function createAutocompleteFromDrivePath(getFolder: (path: string) => Tre
if (nodeBefore.name != "URL") return null;
let textBefore = context.state.sliceDoc(nodeBefore.from, context.pos);
let fullPathBefore = /^\.?\/(.*\/)?/.exec(textBefore)?.[0];
let pathBefore = /(\.?\/)\w*$/.exec(textBefore);

console.log(textBefore, fullPathBefore, pathBefore);
let pathBefore = /(\.?\/)[\w%]*$/.exec(textBefore);

if (!pathBefore && !context.explicit) return null;
if (!fullPathBefore) return null;

try {
let options: string[] = [];

const folder = getFolder(fullPathBefore);
const folder = getFolder(fullPathBefore.replace("%20", " "));
for (const child of folder) options.push(child.name);

return {
from: pathBefore ? nodeBefore.from + pathBefore.index : context.pos,
options: options.map((p) => ({ label: (pathBefore?.[1] ?? "/") + p })),
options: options.map((p) => {
const path = ((pathBefore?.[1] ?? "/") + p).replace(" ", "%20");
return { label: path };
}),
validFor: /^(\/.*)?$/,
};
} catch (e) {
Expand Down

0 comments on commit 486bb81

Please sign in to comment.