Skip to content

Commit

Permalink
support for many links in the same line
Browse files Browse the repository at this point in the history
  • Loading branch information
jaanonim committed Aug 25, 2023
1 parent 492a7ac commit aa6ff58
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/EditorSuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ export class EditorSuggester extends EditorSuggest<VerseLink> {
.getLine(cursor.line)
.substring(0, cursor.ch);

const match = currentContent.match(linkRegex)?.first() ?? "";
if (match) {
console.log(match);
return {
end: cursor,
start: {
line: cursor.line,
ch: currentContent.lastIndexOf(match),
},
query: match,
};
}
return null;
const matches = currentContent.match(linkRegex);
if (!matches) return null;
return matches?.reduce((prev, match) => {
if (match && prev === null) {
const end = currentContent.lastIndexOf(match);
if (end === 0 || currentContent.charAt(end - 1) !== "[")
return {
end: cursor,
start: {
line: cursor.line,
ch: end,
},
query: match,
};
}
return null;
}, null);
}
getSuggestions(
context: EditorSuggestContext
Expand Down

0 comments on commit aa6ff58

Please sign in to comment.