Ensure window-start and window-hscroll remain unchanged#63
Open
jamescherti wants to merge 1 commit into
Open
Conversation
dc3ca39 to
9878c7b
Compare
jcs090218
reviewed
Dec 1, 2024
bc07ab7 to
8509575
Compare
8509575 to
0d8f877
Compare
c7307d5 to
5effd04
Compare
5effd04 to
4886d79
Compare
Contributor
Author
|
I've updated the commit and commit message, @jcs090218. Because markdown-toc modifies the buffer content while it is visible in a window, Emacs often realigns the display to keep the point visible, which frequently causes the window-start to jump. Using save-window-excursion does not fix this issue that this commit fixes. This is noticeable when the Table of Contents is updated at the top of a file while the user is working further down. Steps to Reproduce:
(I recommend reducing the window width and disabling line truncation, as this makes it easier to reproduce the issue.) |
e2e17c4 to
64fd324
Compare
Generating a table of contents involves modifying the buffer content while it is visible in a window. When Markdown content is added or removed above the current cursor position, Emacs often realigns the display to keep the point visible, which frequently causes the window-start to jump. This is noticeable when the Table of Contents is generated at the top of a file while the user is working further down. By capturing the number of visual lines between the cursor and the top of the window before the TOC generation and restoring that relative offset afterward, we ensure the visual layout remains stable and prevent the text from shifting unexpectedly under the user's eyes. This commit prevents markdown-toc-generate-toc from disrupting the user's scroll position by preserving the window-start relative to the cursor.
64fd324 to
4450c36
Compare
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 commit ensures that
markdown-toc-generate-tocdoes not change the window-start or window-hscroll, addressing a common issue that can alter these settings. (I mentioned this issue in this article, and the version of this pull request is better than the cod snippet in the article.)