feat: provide new motions for jumping to the previous or next Markdown code fence#284
Open
alythobani wants to merge 10 commits into
Open
feat: provide new motions for jumping to the previous or next Markdown code fence#284alythobani wants to merge 10 commits into
alythobani wants to merge 10 commits into
Conversation
…d show remapping example for them
alythobani
commented
May 25, 2026
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), | ||
| }; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
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
alythobani
commented
May 25, 2026
| @@ -1,4 +1,3 @@ | |||
| import { Editor as CodeMirrorEditor } from "codemirror"; | |||
Contributor
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new pair of "jump to ..." motions, for jumping to the previous/next code fence. Maps them to
gc(next) andgC(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.