Skip to content

Conversation

@M1cha
Copy link

@M1cha M1cha commented Jul 5, 2022

This Pull Request fixes/closes #1017.

This is a simple implementation that works really well according to my testing.

It may need some improvements like an UI indicator for both the current column and the keymap.
We should talk about that as part of this PR.

One issue that I've found:
It is hard to use keyrepeat on the left key to scroll to the beginning without leaving the diff because starting from column 0 the key suddenly has a different meaning and jumps all the way back up.
A solution would be to provide separate keymaps for scrolling.

I followed the checklist:

  • I added unittests
  • I ran make check without errors
  • I tested the overall application
  • I added an appropriate item to the changelog

the diff viewer will need it in a future commit
@M1cha M1cha changed the title Diff horizontal scroll Allow to scroll diffs horizontally Jul 5, 2022
@extrawurst
Copy link
Collaborator

looks nice! lets paint a scrollbar only as long as scroll is not 0

@M1cha
Copy link
Author

M1cha commented Jul 6, 2022

I'm not sure if that's the best way since you might still wanna scroll vertically while being scrolled horizontally and still see where in the document you you are.

@extrawurst
Copy link
Collaborator

extrawurst commented Jul 6, 2022

Don’t know what the vertical scrolling has to do with it

@M1cha
Copy link
Author

M1cha commented Jul 6, 2022

well you can scroll both directions at the same time and while being scrolled horizontally I'd still like to know where I am vertically.

@extrawurst
Copy link
Collaborator

Still no idea why we worry about the existing scrollbar (vertical).
For the horizontal Scrollbar I would try to not convolute the view as long as we did not start scrolling to the right.

@M1cha
Copy link
Author

M1cha commented Jul 6, 2022

oh for some reason I thought that you mean that we hide the vertical scrollbar as soon as we're scrolled horizontally, sry about that 🙄

@M1cha M1cha force-pushed the diff-horizontal-scroll branch from 2ad5854 to aa79e98 Compare July 7, 2022 16:03
converting tabs to spaces had to be moved from after the formatting to
before it because `trim_offset` seems to remove leading tabs from the output
string (not the input string) for some reason.

calculating the longtest line is cached to prevent a theoretical
decrease in performance.
@M1cha M1cha force-pushed the diff-horizontal-scroll branch from aa79e98 to fbb0fe1 Compare July 7, 2022 16:05
@M1cha
Copy link
Author

M1cha commented Jul 7, 2022

I've implemented a scroll bar :) A few things:

  • it's using the vertical bar symbol. that looks a little weird but I couldn't find a better one
  • calculating the longest line is not yet correct. 1) I'd have to convert tabs to spaces (again) before doing the calculation, but also, it only accounts for text, not for any meta data. I tried asking the span list for the longest line but that seems to trip on the selection which always has the full width. any ideas?

@extrawurst
Copy link
Collaborator

looks like a good start. but yeah it definitely misses the correct max-scroll pos. I did not have time to check the code yet. you can go for what ever solution as long as it is accurate and cache the result if it is potentially expensive (it would scale with the length of the diff) as long as the diff is not updated

@extrawurst
Copy link
Collaborator

are you still going to work on this?

@extrawurst extrawurst marked this pull request as draft September 2, 2022 07:28
@M1cha
Copy link
Author

M1cha commented Sep 2, 2022

At least not within the next few weeks. So if anyone else wants to take over feel free. If not and I feel like continuing this I'll say so here.

@cruessler
Copy link
Collaborator

@extrawurst, @M1cha I have a few relatively minor changes locally that address the issues I have found so far, but I don’t have push access to this PR. I can open a separate PR from my fork and link to this one there. Is that ok?

cruessler/diff-horizontal-scroll

@M1cha
Copy link
Author

M1cha commented Sep 13, 2022

that'd make sense. btw the longest_line calculation was insane. It's better to either use for loops like this:

self.longest_line = 0;
if let Some(diff) = self.diff.as_ref() {
	for hunk in &diff.hunks {
		for line in &hunk.lines {
			self.longest_line = self.longest_line.max(line.content.len());
		}
	}
}

or something a little more functional:

self.longest_line = self
	.diff
	.iter()
	.flat_map(|diff| diff.hunks.iter())
	.flat_map(|hunk| hunk.lines.iter())
	.map(|line| line.content.len())
	.max()
	.unwrap_or(0);

I pulled these snippets out of old chats with co-workers about this and didn't verify if those solutions still match what's currently on my branch.

@cruessler
Copy link
Collaborator

@M1cha Thanks for the hint, I was able to incorporate your suggestion into the new PR!

@extrawurst
Copy link
Collaborator

closed in favour of #1327

@extrawurst extrawurst closed this Jan 8, 2023
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.

Allow to scroll diffs horizontally

3 participants