Skip to content

Preserve the cursor position when entering and exiting markdown-edit-code-block#914

Merged
syohex merged 1 commit intojrblevin:masterfrom
knu:feat/edit-code-block-preserve-point
Jul 18, 2025
Merged

Preserve the cursor position when entering and exiting markdown-edit-code-block#914
syohex merged 1 commit intojrblevin:masterfrom
knu:feat/edit-code-block-preserve-point

Conversation

@knu
Copy link
Contributor

@knu knu commented Jul 18, 2025

By saving and restoring the relative cursor position when entering and exiting edit-indirect mode, users can continue editing from the same location after making changes to the code block.

Description

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves an existing feature)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have updated the documentation in the README.md file if necessary.
  • I have added an entry to CHANGES.md.
  • I have added tests to cover my changes.
  • All new and existing tests passed (using make test).

…-code-block`

By saving and restoring the relative cursor position when entering and exiting edit-indirect mode, users can continue editing from the same location after making changes to the code block.
@knu knu force-pushed the feat/edit-code-block-preserve-point branch from f596b7d to 74a695d Compare July 18, 2025 08:40
(setq markdown--edit-indirect-committed-position nil))

(with-eval-after-load 'edit-indirect
(advice-add #'edit-indirect-commit :after #'markdown--edit-indirect-move-to-committed-position))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to advise these functions because existing hooks have limitations:

  • edit-indirect-after-commit-functions are run from the inside of save-excursion.
  • edit-indirect-before-commit-functions and edit-indirect-before-commit-hook are run in the parent buffer and have no access to the edit-indirect buffer.

@syohex syohex merged commit c6ac744 into jrblevin:master Jul 18, 2025
4 checks passed
@knu knu deleted the feat/edit-code-block-preserve-point branch July 19, 2025 01:43
@knu knu mentioned this pull request Jul 19, 2025
9 tasks
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.

2 participants