mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
jumpToLink can now jump to standalone hyperlinks
This commit is contained in:
parent
557cc6091a
commit
20eb7a0a4c
1 changed files with 12 additions and 3 deletions
|
|
@ -1,13 +1,22 @@
|
|||
import { jumpToPattern } from "../utils/jumpToPattern";
|
||||
import { MotionFn } from "../utils/vimApi";
|
||||
|
||||
const WIKILINK_REGEX_STRING = "\\[\\[[^\\]\\]]+?\\]\\]";
|
||||
const MARKDOWN_LINK_REGEX_STRING = "\\[[^\\]]+?\\]\\([^)]+?\\)";
|
||||
const LINK_REGEX_STRING = `${WIKILINK_REGEX_STRING}|${MARKDOWN_LINK_REGEX_STRING}`;
|
||||
const WIKILINK_REGEX_STRING = "\\[\\[.*?\\]\\]";
|
||||
const MARKDOWN_LINK_REGEX_STRING = "\\[.*?\\]\\(.*?\\)";
|
||||
const URL_REGEX_STRING = "\\w+://\\S+";
|
||||
|
||||
/**
|
||||
* Regex for a link (which can be a wikilink, a markdown link, or a standalone URL).
|
||||
*/
|
||||
const LINK_REGEX_STRING = `${WIKILINK_REGEX_STRING}|${MARKDOWN_LINK_REGEX_STRING}|${URL_REGEX_STRING}`;
|
||||
const LINK_REGEX = new RegExp(LINK_REGEX_STRING, "g");
|
||||
|
||||
/**
|
||||
* Jumps to the repeat-th next link.
|
||||
*
|
||||
* Note that since `jumpToPattern` uses `String.matchAll`, which internally updates `lastIndex`
|
||||
* after each match, it won't catch standalone URLs within wikilinks / markdown links
|
||||
* (which should be a good thing in most cases).
|
||||
*/
|
||||
export const jumpToNextLink: MotionFn = (cm, cursorPosition, { repeat }) => {
|
||||
return jumpToPattern({
|
||||
|
|
|
|||
Loading…
Reference in a new issue