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

Feature: Scroll to Line number based on Hash IE http://foo.com/p/bar#L10 will scroll to line 10. #4554

Merged
merged 13 commits into from Dec 26, 2020

Conversation

JohnMcLear
Copy link
Member

@JohnMcLear JohnMcLear commented Dec 8, 2020

How to use (tm)

Clicking on side div line number to set line number hash and then on visiting scrolling back into view.

  • Agree on UX.
  • Agree this should be in core.
  • Tests
  • Docs?
  • Correct Y position when padding-top is not visible.
  • Some linting
  • Someone please check my test spec because I think I messed something up

Future TODOs:

  • Anchor Support IE #foo will visit <h1>foo</h1> ?

@webzwo0i
Copy link
Member

webzwo0i commented Dec 9, 2020

agreed this is useful to be in core and works for me.

any reason you are not using code from ace2_inner.js or scroll.js? Something like

function scrollSelectionIntoView() {
or
Scroll.prototype.scrollNodeVerticallyIntoView = function (rep, innerHeight) {
, although this means you need to set rep? (Like setting the caret to the beginning of the line - maybe the editor will automatically scroll there?)

@JohnMcLear
Copy link
Member Author

I can use setrep. Will try that. Good suggestion.

Afaik I don't use it because sometimes using ace inner code can get a little spaghetti where just interacting with outer is clean. Will see.

@JohnMcLear
Copy link
Member Author

@webzwo0i give that a pull and test. Now it focused caret too.. But note that I'm still using new logic to handle focus because trying to use ace.ace_scrollSelectionIntoView(); after exposing it did not work. I also prefer this UX 👍

@madix93
Copy link

madix93 commented Dec 11, 2020

Hello,

We've been using some pads for a very long time and line numbers can change over time. So being able to set an anchor would be useful too.

Or, even better, being able to set an anchor in the table of contents entries. So that, https://foo.com/p/bar#EntryOneOfToc will scroll directly to EntryOneOfToc.

For example, there is a table of contents on this pad https://pad.april.org/p/radio_cause_commune. It would be useful to be able to have an URL going directly to an entry of the table of contents. And, we could share this url by email for example.

All the best,

@webzwo0i
Copy link
Member

webzwo0i commented Dec 13, 2020

Try with a setTimeout, (compare with b83589f )

The default behavior with ace.ace_scrollSelectionIntoView(); is probably that the line will be the last line in the view (not the first one).

In the commit above the line that has the caret is not the first visible line in the editor, but when we now start typing or scroll to the right, no additional scrolling happens. Code that incorporates the offset of the first line and the offsetTop of the iframe is commented in the code. Can't we use the offset of the first line and the offset of the line we want to go to, to determine how much we need to scroll? IE if the offset of the first line is 30 (while scrollY is 0) and we want to go to the offset 1000, we need to scroll 1000 - 30.

There is also Scroll.prototype._getPaddingTopAddedWhenPageViewIsEnable that returns the top padding of ace_outer.

However, there is still one big problem with my solution: When we have a lot of lines and want to go to a line in the middle of the pad, it won't work unless we increase the timeout (firefox needs a larger timeout than chromium). I can't put much time into better understanding the ACE code and don't understand what exactly has not finished loading.

Maybe the method needs to be triggered in another handler.

One other thing is, do we need to take into account lines with line attributes? Because the caret (first char in a line) is at [y, 1] on a line with line attributes and at [y, 0] on a line without attributes. Might be irrelevant when using setSelection.

I'm okay with the way you solved it, so don't mind my code, unless you have a good idea if there is another place to call the method from

@JohnMcLear
Copy link
Member Author

So ..

  1. test with long pads.
  2. test with long lines with varying line heights etc.

Ack, will do.

@JohnMcLear
Copy link
Member Author

Tested pad with 5K lines and it works fine.

Tested content with varying line height and it works fine.

Tested in Chrome and FF.

@JohnMcLear
Copy link
Member Author

@webzwo0i can you check my test coverage please?

helper.waitFor(() => {
const topOffset = parseInt(chrome$('iframe').first('iframe')
.contents().find('#outerdocbody').css('top'));
return (!topOffset); // no css top should be set.
Copy link
Member

Choose a reason for hiding this comment

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

see above, also applies to here

@webzwo0i
Copy link
Member

RE test: I added a comment there. Also, if you happen to know how to get the visible lines from the viewport, then that's probably more accurate?

@JohnMcLear
Copy link
Member Author

It's something I'm gonna have to bake in.

@JohnMcLear
Copy link
Member Author

Okay this is good for final review and merge.

@sonarcloud
Copy link

sonarcloud bot commented Dec 26, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
26.7% 26.7% Duplication

@webzwo0i webzwo0i merged commit 38c9827 into develop Dec 26, 2020
@rhansen rhansen deleted the scroll-to-line branch December 27, 2020 22:33
webzwo0i pushed a commit that referenced this pull request Jan 4, 2021
 will scroll to line 10. (#4554)

Includes test coverage
Co-authored-by: webzwo0i <webzwo0i@c3d2.de>
JohnMcLear added a commit that referenced this pull request Feb 15, 2021
 will scroll to line 10. (#4554)

Includes test coverage
Co-authored-by: webzwo0i <webzwo0i@c3d2.de>
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.

None yet

3 participants