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

Make linewrapping plugin recompute breaks before scrolling #1190

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data/plugins/linewrapping.lua
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,15 @@ function DocView:new(doc)
end
end

local old_scroll_to_line = DocView.scroll_to_line
function DocView:scroll_to_line(...)
LineWrapping.update_docview_breaks(self)
old_scroll_to_line(self, ...)
end

local old_scroll_to_make_visible = DocView.scroll_to_make_visible
function DocView:scroll_to_make_visible(line, col)
LineWrapping.update_docview_breaks(self)
Copy link
Member

Choose a reason for hiding this comment

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

Seems like overriding DocView:scroll_to_line is enough to fix the issue with the projectsearch plugin. Any reason to also call LineWrapping.update_docview_breaks on DocView:scroll_to_make_visible? I'm worried that calling LineWrapping.reconstruct_breaks (which is called by update_docview_breaks) will hurt performance more since it is already been called on each update().

Otherwise the fix is good.

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 am under the impression that update_docview_breaks will only call reconstruct_breaks if necessary, so only once. It'll check the width a few extra times, but that's relatively harmless, IMO.

I added it to the other scroll function as well in case any other plugins or modifications use it, to make sure everything is as robust as possible. One function call with an if statement is an acceptable overhead, I think.

Copy link
Member

Choose a reason for hiding this comment

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

I did some core.log testing directly on reconstruct_breaks and it was executing its code on every call, it doesn't seems to implement any state tracking for now. And adding the update breaks to scroll visible just increases the amount of times it gets called when manually scrolling the docview

Copy link
Member

@jgmdev jgmdev Nov 7, 2022

Choose a reason for hiding this comment

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

my bad, that isn't correct... it is only been triggered now on scroll hover with the call to LineWrapping.update_docview_breaks(self) on DocView:scroll_to_make_visible

Edit: Actually I'm wrong again, should get some sleep xD

old_scroll_to_make_visible(self, line, col)
if self.wrapped_settings then self.scroll.to.x = 0 end
end
Expand Down