Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll position sync support #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Antonio-R1
Copy link

@Antonio-R1 Antonio-R1 commented Nov 13, 2022

Added support for syncing the scroll position of the webview with the position of the cursor.

I also tried to create a python3-markdown plugin as described in my comment in issue #35, but I could only find a hack solution. For lists and code blocks, for example, it only outputs the source line of the beginning of the list or code block, respectively.

The sourcepos extension from pandoc is only available for the commonmark, commonmark_x and gfm formats. This pull request changes the input format to commonmark and for using features like tables etc., the required extensions needs to be enabled or one of the other two formats can be used.

Currently, the position is always synced when the document is reloaded, but I think a new option in the preference window can be added for activating or deactivating the synchronization of the scroll position.

Copy link
Owner

@maoschanz maoschanz left a comment

Choose a reason for hiding this comment

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

it's pretty hard to read and without comments, so i needed a lot of motivation to review it sorry

}
}
if (highestLowerBoundElement) {
highestLowerBoundElement.scrollIntoViewIfNeeded();
Copy link
Owner

Choose a reason for hiding this comment

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

why "if needed"? isn't the standard just "scrollIntoView"?

@@ -9,12 +9,79 @@

_ = init_gettext()

SCRIPT_SCROLL_TO_CURSOR = """
Copy link
Owner

Choose a reason for hiding this comment

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

the script could be in a separate file, and loaded in the init. This way, it could be a js file with syntax coloration

@@ -278,6 +279,9 @@ def _on_reload_unsafe(self):
return
start, end = doc.get_bounds()
unsaved_text = doc.get_text(start, end, True)
cursor_position = doc.get_property("cursor-position")
text_iter = doc.get_iter_at_offset(cursor_position)
self._webview_manager.set_cursor_position (text_iter.get_line()+1, text_iter.get_line_offset()+1)
Copy link
Owner

Choose a reason for hiding this comment

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

why "+1"? does it not understand zeros? then isn't it problematic that you set cursor_row and column as 0 in the init?

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