From 2adf45cdbc2acbb61a524ba6af7155eaa52c3ead Mon Sep 17 00:00:00 2001 From: Aly Thobani Date: Fri, 10 May 2024 11:20:21 -0700 Subject: [PATCH] refactor: add docstrings / change var names --- actions/followLinkUnderCursor.ts | 11 +++++++---- actions/moveSkippingFolds.ts | 6 ++++++ motions/jumpToHeading.ts | 6 ++++++ motions/jumpToLink.ts | 6 ++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/actions/followLinkUnderCursor.ts b/actions/followLinkUnderCursor.ts index d25dd91..fe4faaa 100644 --- a/actions/followLinkUnderCursor.ts +++ b/actions/followLinkUnderCursor.ts @@ -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"); } }; diff --git a/actions/moveSkippingFolds.ts b/actions/moveSkippingFolds.ts index 8527db9..a513a93 100644 --- a/actions/moveSkippingFolds.ts +++ b/actions/moveSkippingFolds.ts @@ -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, diff --git a/motions/jumpToHeading.ts b/motions/jumpToHeading.ts index babea46..38541ac 100644 --- a/motions/jumpToHeading.ts +++ b/motions/jumpToHeading.ts @@ -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, diff --git a/motions/jumpToLink.ts b/motions/jumpToLink.ts index ae2af27..9ba9624 100644 --- a/motions/jumpToLink.ts +++ b/motions/jumpToLink.ts @@ -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,