Skip to content

feat: provide new motions for jumping to the previous or next Markdown code fence#284

Open
alythobani wants to merge 10 commits into
esm7:masterfrom
alythobani:alyt/5-feat-jump-to-code-fence
Open

feat: provide new motions for jumping to the previous or next Markdown code fence#284
alythobani wants to merge 10 commits into
esm7:masterfrom
alythobani:alyt/5-feat-jump-to-code-fence

Conversation

@alythobani
Copy link
Copy Markdown
Contributor

This PR adds a new pair of "jump to ..." motions, for jumping to the previous/next code fence. Maps them to gc (next) and gC (previous) by default.

Added this for myself (wanted a way to easily jump past a codeblock, which I can now mostly do by jumping to its closing fence with these motions) and figured I'd share as a PR in case it's useful for other users.

Comment on lines +4 to +17
/**
* Returns a fake CodeMirror editor bound to the given `contentLines`.
*/
export function createFakeCodeMirrorEditor(
contentLines: string[]
): Pick<CodeMirrorEditor, "getValue" | "indexFromPos" | "posFromIndex"> {
const content = contentLines.join("\n");
const lineStartIndexes = getLineStartIndexes(contentLines);
return {
getValue: () => content,
indexFromPos: ({ line, ch }: EditorPosition) => lineStartIndexes[line] + ch,
posFromIndex: (index: number) => getEditorPositionForIndex(index, lineStartIndexes),
};
}
Copy link
Copy Markdown
Contributor Author

@alythobani alythobani May 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this CodeMirror.Editor-mocking util for testing motions in a slightly more integration-test way. (The existing tests/jumpToLink.test.ts file I previously made, just tests expected vs actual regex matches, vs tests/jumpToCodeFence.test.ts can now use this fake editor to test expected vs actual cursor position)

- CodeMirror.Editor is globally available as a type (and already used in other files), so lets just
  stick consistently to using that
Comment thread motions/jumpToHeading.ts
@@ -1,4 +1,3 @@
import { Editor as CodeMirrorEditor } from "codemirror";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized we can just use the CodeMirror.Editor type without needing to import it, so went ahead and removed these unnecessary aliases I'd added in a previous PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant