-
Notifications
You must be signed in to change notification settings - Fork 360
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
Add line numbers support #2062
Add line numbers support #2062
Conversation
guanglinn
commented
Jun 5, 2023
- Add line numbers support for Edit mode and code blocks in View mode;
- Update Prism from v1.17.1 to v1.29.0.
@@ -490,6 +498,11 @@ public boolean getDocumentHighlightState(final String path, final CharSequence c | |||
return getBool(PREF_PREFIX_HIGHLIGHT_STATE + path, lengthOk && isHighlightingEnabled()); | |||
} | |||
|
|||
public boolean getEditorLineNumbersState(final CharSequence chars) { | |||
final boolean lengthOk = chars != null && chars.length() < (_isDeviceGoodHardware ? 100000 : 35000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you used some performance related values here... How well is performance overall, does it greatly impact i.e. scrolling or loading speed? Last time I visited this, it made everything horribly slow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't do enough testing. It is important but I'm not good at testing, could you have a test for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a moderate to big textfile and scroll a bit. You will immediately notice when it's slow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only draw line numbers for the visible lines +- 2 pages.
The highlighter class does this. We can look at it / reuse some code imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, the algorithm or method for displaying line numbers is still worth optimizing. Second, the editor's loading strategy for large files may also need to be optimized, such as just loading nearby 1000 lines at a time, which can gracefully load large files. I could try to optimize it if I'm free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guang-lin Note that Incrementally loading files with Android can be a pain as the underlying file system is unreliable. Our current system (trying to save multiple times etc) is hacky but prevents data loss 99.99% of the time.
app/thirdparty/java/other/flexmark/ext/codeblocks/LineNumbersAttributeProvider.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your help! I looked through and added my thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my point of view the code looks good
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Show resolved
Hide resolved
Note: Today i go on holyday for 3 weeks where i have no computer so i cannot do any code reviews in this time |
Fine, have a good holiday! |
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Outdated
Show resolved
Hide resolved
From my point of view every thing else looks good |
031eb51
to
64fd499
Compare
What is the status here? Any way I can help move this along? |
for (int i = 1; i < count; i++) { | ||
if (text.charAt(layout.getLineStart(i) - 1) == '\n') { | ||
number++; | ||
y = layout.getLineTop(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this look in todo.txt where we add extra padding to the top of the line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks better 😊
I think the status is stable. It can be better improved, if there are better ideas in the future. |
Hello, I try to find some time on this (hot) weekend to review again and hopefully merge this week. Regarding todo.txt, would it be possible to add a offset at the number so it better fits (vertical center/middle) to the line? That offset can be conditionally activated by checking the format |
You're in Austria Right? I was in Germany a few weeks ago and it was quite warm :)
I think we can look at Font Metrics and align the bottom of the number to the line's baseline. This will be uniform in all cases and will not require special a case for Todo. |
Yes! Hm, I think at the end it would be the best solution if the text is vertical-centered to the (full) line. Especially also when it's multiline (regarding line wrapping) |
I have to disagree. Vim and VsCode both align the bottom of the0 number to bottom of the first letter in the line. I think this is now it should go. |
…rmance improvements.
e7871c0
to
a7fdd30
Compare
@guang-lin |
I think yes. It's my pleasure to contribute to this project. 😊 |
protected void onDraw(Canvas canvas) { | ||
super.onDraw(canvas); | ||
// If line numbers can be drawn | ||
if (_nuEnabled && _maxLineNumber < (AppSettings._isDeviceGoodHardware ? 5000 : 3000)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As line numbers have to be enabled manually, perhaps we should just issue a toast warning instead of hard blocking on isDeviceGoodHardware
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also just try to make line numbers dynamic (draw them only for visible lines). That will avoid this completely. Lets remove this test for the line count at first and then I can help with the dynamic line numbers...
Now support iterating from the first visible line rather than the second line when the view is not scrolling, even at around 30,000th line. |
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
Outdated
Show resolved
Hide resolved
Changed the branch to linenumbers branch. Merging this PR and improvements can be continued via additional PRs to linenumbers branch. Then we can merge it to master when you think it's fine. Thanks for the contribution! |