mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
* feat: define and expose obsidian-specific vim commands jumpToNextHeading: g] jumpToPreviousHeading: g[ * Implement jumpToPreviousLink motion * Refactoring and implementing jumpToNextLink * refactor: new jumpToPattern function that can be used for motions * refactor: renamed file and removed unneeded exports * fix: return last found index even if fewer than n instances found, instead of undefined * feat: implement moveUpSkipFold and moveDownSkipFold * refactor: extract out helper functions for defining obsidian vim actions * refactor: split vimApi.ts into two files * refactor: add comment * refactor: update names, types, etc * feat: followLinkUnderCursor action * feat: jumpToLink now jumps to both markdown and wiki links * refactor: rename fns * refactor: add docstrings / change var names * feat: implement looping around * refactor: cleaner implementation of jumpToPattern * Change mappings for next/prev heading to [[ and ]] * Tiny fixes * docs: update docs now that some more motions are provided by default --------- Co-authored-by: Erez Shermer <erezshermer@gmail.com>
33 lines
884 B
TypeScript
33 lines
884 B
TypeScript
/**
|
|
* Partial representation of the CodeMirror Vim API that we use to define motions, commands, etc.
|
|
*
|
|
* References:
|
|
* https://github.com/replit/codemirror-vim/blob/master/src/vim.js
|
|
* https://libvoyant.ucr.edu/resources/codemirror/doc/manual.html
|
|
*/
|
|
|
|
import { Editor as CodeMirrorEditor } from "codemirror";
|
|
import { EditorPosition } from "obsidian";
|
|
|
|
export type MotionFn = (
|
|
cm: CodeMirrorEditor,
|
|
cursorPosition: EditorPosition, // called `head` in the API
|
|
motionArgs: { repeat: number }
|
|
) => EditorPosition;
|
|
|
|
export type ActionFn = (
|
|
cm: CodeMirrorEditor,
|
|
actionArgs: { repeat: number },
|
|
) => void;
|
|
|
|
export type VimApi = {
|
|
defineMotion: (name: string, fn: MotionFn) => void;
|
|
defineAction: (name: string, fn: ActionFn) => void;
|
|
mapCommand: (
|
|
keys: string,
|
|
type: string,
|
|
name: string,
|
|
args: any,
|
|
extra: { [x: string]: any }
|
|
) => void;
|
|
};
|