mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
refactor: add docstrings / change var names
This commit is contained in:
parent
3d457c2f8c
commit
2adf45cdbc
4 changed files with 25 additions and 4 deletions
|
|
@ -1,23 +1,26 @@
|
|||
import { ObsidianActionFn } from "../utils/obsidianVimCommand";
|
||||
|
||||
/**
|
||||
* Follows the link under the cursor, temporarily moving the cursor if necessary for follow-link to
|
||||
* work (i.e. if the cursor is on a starting square bracket).
|
||||
*/
|
||||
export const followLinkUnderCursor: ObsidianActionFn = (vimrcPlugin) => {
|
||||
// If the cursor is on the starting square bracket(s), we need to move it inside them
|
||||
const obsidianEditor = vimrcPlugin.getActiveObsidianEditor();
|
||||
const { line, ch } = obsidianEditor.getCursor();
|
||||
const firstTwoChars = obsidianEditor.getRange(
|
||||
{ line, ch },
|
||||
{ line, ch: ch + 2 }
|
||||
);
|
||||
let charOffset = 0;
|
||||
let numCharsMoved = 0;
|
||||
for (const char of firstTwoChars) {
|
||||
if (char === "[") {
|
||||
obsidianEditor.exec("goRight");
|
||||
charOffset++;
|
||||
numCharsMoved++;
|
||||
}
|
||||
}
|
||||
vimrcPlugin.executeObsidianCommand("editor:follow-link");
|
||||
// Move the cursor back to where it was
|
||||
for (let i = 0; i < charOffset; i++) {
|
||||
for (let i = 0; i < numCharsMoved; i++) {
|
||||
obsidianEditor.exec("goLeft");
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import VimrcPlugin from "../main";
|
||||
import { ObsidianActionFn } from "../utils/obsidianVimCommand";
|
||||
|
||||
/**
|
||||
* Moves the cursor down `repeat` lines, skipping over folded sections.
|
||||
*/
|
||||
export const moveDownSkippingFolds: ObsidianActionFn = (
|
||||
vimrcPlugin,
|
||||
cm,
|
||||
|
|
@ -9,6 +12,9 @@ export const moveDownSkippingFolds: ObsidianActionFn = (
|
|||
moveSkippingFolds(vimrcPlugin, repeat, "down");
|
||||
};
|
||||
|
||||
/**
|
||||
* Moves the cursor up `repeat` lines, skipping over folded sections.
|
||||
*/
|
||||
export const moveUpSkippingFolds: ObsidianActionFn = (
|
||||
vimrcPlugin,
|
||||
cm,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import { MotionFn } from "../utils/vimApi";
|
|||
|
||||
const HEADING_REGEX = /^#+ /gm;
|
||||
|
||||
/**
|
||||
* Jumps to the repeat-th next heading.
|
||||
*/
|
||||
export const jumpToNextHeading: MotionFn = (cm, oldPosition, { repeat }) => {
|
||||
return jumpToPattern({
|
||||
cm,
|
||||
|
|
@ -13,6 +16,9 @@ export const jumpToNextHeading: MotionFn = (cm, oldPosition, { repeat }) => {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Jumps to the repeat-th previous heading.
|
||||
*/
|
||||
export const jumpToPreviousHeading: MotionFn = (
|
||||
cm,
|
||||
oldPosition,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ const MARKDOWN_LINK_REGEX_STRING = "\\[[^\\]]+?\\]\\([^)]+?\\)";
|
|||
const LINK_REGEX_STRING = `${WIKILINK_REGEX_STRING}|${MARKDOWN_LINK_REGEX_STRING}`;
|
||||
const LINK_REGEX = new RegExp(LINK_REGEX_STRING, "g");
|
||||
|
||||
/**
|
||||
* Jumps to the repeat-th next link.
|
||||
*/
|
||||
export const jumpToNextLink: MotionFn = (cm, oldPosition, { repeat }) => {
|
||||
return jumpToPattern({
|
||||
cm,
|
||||
|
|
@ -16,6 +19,9 @@ export const jumpToNextLink: MotionFn = (cm, oldPosition, { repeat }) => {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Jumps to the repeat-th previous link.
|
||||
*/
|
||||
export const jumpToPreviousLink: MotionFn = (cm, oldPosition, { repeat }) => {
|
||||
return jumpToPattern({
|
||||
cm,
|
||||
|
|
|
|||
Loading…
Reference in a new issue