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
[NETBEANS-977] Improve text layout in word wrap mode. #598
Conversation
The patch is clean and has tests but it would take me some time to understand what you did there as I'm not familiar with the area. It would be nice to see Miloslav Metelka show up here. I see you show the line wrap character only if |
The isNonPrintableCharactersVisible setting can be triggered via the "Toggle Non-printable Characters" action--I assigned it a keyboard shortcut in the Preferences pane to be able to invoke it. Yeah, when I looked at the historical "git blame", Miroslav was the one who wrote all the related logic (most of it back in 2010). |
I have added a few more known issues related to word wrapping in the NetBeans editor, in case anyone who knows the code strolls through and wants to comment: https://issues.apache.org/jira/browse/NETBEANS-978 (Fixing these few word wrapping bugs would increase the IDE's value as a general-purpose editor rather than just a code editor, at least for people who like to write long paragraphs of text without explicit line breaks. Though my own motivation for getting these fixed is because my spreadsheet-like NetBeans Platform application uses the NetBeans EditorKit for its table cell editor and formula bar.) |
I've sent an email to ask about Miloslav, let's hope he'll show up soon. |
With regards to the problems with the Arrow Up/Arrow Down/Home/End actions in wrapped paragraphs, I've done some investigations that I typed up in https://issues.apache.org/jira/browse/NETBEANS-980 (also closing NETBEANS-979 as a duplicate of the latter, since they turned out to be variations on the same problem). But this pull request can be reviewed and applied independently of those other issues. |
@eirikbakke, how confident are you about this patch, you're currently the most knowledgeable in this area and we should try to not necessarily rely on Oracle staff anymore as far as possible. If there are specific areas where you need help or are less confident about, please say so, but on the face of it this looks like an awesome enhancement that we should accept. |
I am not really an expert in this area, but looks reasonable to me.
…On Fri, Jun 22, 2018 at 6:49 PM, Eirik Bakke ***@***.***> wrote:
Improve text layout for the NetBeans editor's "word wrap" feature. This
makes the word wrap behavior more in line with that of other editors, and
makes wrapped text more readable. See detailed description and before/after
screenshot (also attached here) at https://issues.apache.org/
jira/browse/NETBEANS-977 .
[image: wrappingdiff]
<https://user-images.githubusercontent.com/886243/41788682-c239bcfe-764c-11e8-9ec3-efa2cbe21fa0.png>
------------------------------
You can view, comment on, or merge this pull request online at:
#598
Commit Summary
- [NETBEANS-977] Improve text layout in word wrap mode.
File Changes
- *A* editor.lib2/src/org/netbeans/modules/editor/lib2/view/
CharSequenceCharacterIterator.java
<https://github.com/apache/incubator-netbeans/pull/598/files#diff-0>
(104)
- *M* editor.lib2/src/org/netbeans/modules/editor/lib2/view/
DocumentViewOp.java
<https://github.com/apache/incubator-netbeans/pull/598/files#diff-1>
(20)
- *M* editor.lib2/src/org/netbeans/modules/editor/lib2/view/
HighlightsViewUtils.java
<https://github.com/apache/incubator-netbeans/pull/598/files#diff-2>
(122)
- *M* editor.lib2/src/org/netbeans/modules/editor/lib2/view/
WrapInfo.java
<https://github.com/apache/incubator-netbeans/pull/598/files#diff-3>
(2)
- *M* editor.lib2/src/org/netbeans/modules/editor/lib2/view/
WrapInfoUpdater.java
<https://github.com/apache/incubator-netbeans/pull/598/files#diff-4>
(18)
- *A* editor.lib2/test/unit/src/org/netbeans/modules/editor/lib2/view/
AdjustBreakOffsetToWordTest.java
<https://github.com/apache/incubator-netbeans/pull/598/files#diff-5>
(278)
Patch Links:
- https://github.com/apache/incubator-netbeans/pull/598.patch
- https://github.com/apache/incubator-netbeans/pull/598.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#598>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAHk8FENI1dG2hG_bqftnFOpUtjyq7nOks5t_SAlgaJpZM4U0HSF>
.
|
Would be good for at least @sdedic to comment, and let's merge then. |
There is one issue that I see now--since there is less margin on the right now, putting the cursor at the last character on a wrap line makes the editor scroll horizontally by a few pixels to put it fully into view, even if the last character is just a whitespace. I should probably fix that before the patch is applied. Now busy with another deadline; will revisit in a couple of weeks. |
The patch seems ok to me, I just do not have all the details regarding the line wrapping code cached in my memory right now. |
OK, @eirikbakke, its been reviewed in different ways now, even by @mmetelka, just say the word when you're done -- and/or if more reviews are needed after you make further tweaks -- and then let's merge this cool enhancement. |
Great! I've actually prepared a few more commits that should be reviewed as part of this patch (improving horizontal scroll behavior in view of the new wrapping policy). But before I push them for review, I'd like to make sure I'm not breaking any existing unit tests. I'm having trouble [1] running unit tests for the editor.lib2 module, even before the patch is applied. Is anyone able to run the test suite successfully, in particular for this module? [1] "task failed due to: java.lang.NoClassDefFoundError: org/netbeans/editor/GuardedDocument", e.g. in org.netbeans.modules.editor.lib2.highlighting.HighlightingManagerTest. See email thread on the dev list with subject "Does Travis and/or Jenkins run the NetBeans test suite?" |
I've added a few more commits to this pull request, to improve the editor's horizontal scrolling behavior to work well with line wrapping enabled. I've also confirmed that there are no new broken tests in the editor, editor.lib, and editor.lib2 modules as a result of these commits. Though note that both the editor.lib2 module and the editor module had broken tests before this patch was applied. And the latter modules' tests don't seem to be run by Travis nor Jenkins. (See the email thread on the dev list with the subject "Does Travis and/or Jenkins run the NetBeans test suite?") |
@eirikbakke, how far along is this from your point of view? Do you need a review, of what specifically, is it ready to be merged from your point of view, and how confident are you about it? |
I think this patch as well as #603 is ready now. I have not been able to find any new bugs or test failures introduced by them. It might be a good general policy to always require at least a cursory review of new commits by someone else than the original author. But there are no blockers from my point of view. |
The upstream repo changed its directory structure, which means the pull request got a merge conflict. Now trying to figure out how to merge or rebase it from my side... |
a38784d
to
7364449
Compare
I rebased (and force-pushed) this pull request since changes in the upstream directory structure caused a merge conflict. I've had the patch enabled (together with #603 ) in both my development IDE and my NetBeans Platform application for about a week now, with no ill effects, so I think both of these pull requests are ready to be merged. |
final TextLayout lineContTextLayout = getLineContinuationCharTextLayout(); | ||
final float lineContTextLayoutAdvance = | ||
lineContTextLayout == null ? 0f : lineContTextLayout.getAdvance(); | ||
availableWidth = Math.max(getVisibleRect().width, 4 * getDefaultCharWidth() + lineContTextLayoutAdvance); |
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.
original code did not change availableWidth
if lineContTextLayout == null
; is it OK to alter 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.
Yes; the getLineWrapType() != LineWrapType.NONE check is sufficient. Previously, getLineContinuationCharTextLayout would never return null in practice--only if the font could not display the line continuation character or its alternate. And if that ever happened, there would have been an NPE when WrapInfo calls paintTextLayout with the null layout.
I changed this so that getLineContinuationCharTextLayout can now return null without error (and added Javadoc to that effect). Rather than disabling line wrapping altogether, this simply avoids displaying displaying the line continuation character. Then I made this the default, unless the user opts to display hidden characters (paragraph marks etc).
I just looked over the call sites of getLineContinuationCharTextLayout again; they seem to do the right thing.
ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/HighlightsViewUtils.java
Outdated
Show resolved
Hide resolved
? preferredMaximumBreakOffset | ||
: bi.preceding(preferredMaximumBreakOffset); | ||
if (ret == BreakIterator.DONE) | ||
ret = preferredMaximumBreakOffset; |
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.
Use {} around if-ed statement; maybe return preferredMaximumBreakOffset
immediately for better clarity (case preferredMaximumBreakOffset == 0
handled at 801).
If bi.preceding(...) == 0
, that is boundary at char 0, is it OK to search forwards (as seen below) ?
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.
OK, fixed cosmetic issues.
Yes, that case is intentional. When the break line is in the middle of a word, we normally scan backwards to try to find the beginning of that word, and then we break there. But if the beginning of the word is in fact at the beginning of the current break line, then that means we have a super-long word that spans the entire viewport, and we must "give up" and break after the word instead, beyond the preferred break offset (requiring horizontal scrolling in the editor). This case is exercised many times when AdjustBreakOffsetToWordTest is run (I just checked to be sure).
This squashed commit combines the following commits (1-5 were seen in the original pull request, before rebase to fix merge conflict due to directory structure change): 1) Improve text layout in word wrap mode. 2) Refactor EditorCaret to avoid repeated code for getting the JViewport. 3) Fix scrollRectToVisible behavior for the improved text wrap layout. 4) Modify the word wrapping policy slightly to allow at most one whitespace character to trail the preferred wrap width. This avoids having to paint the caret outside the wrapped editor viewport. 5) Improve text caret behavior when typing at the end of a wrapped paragraph. 6) (2018-09-13:) Cosmetic adjustments after pull request comments. Use {} around one-line ifs. Also do "return preferredMaximumBreakOffset" instead of "ret = preferredMaximumBreakOffset" in adjustBreakOffsetToWord, as suggested in PR comment. They are logically equivalent at this point in the code.
08cb0cd
to
70f1868
Compare
I incorporated sdedic's comment and pushed again. (After having to rebase and force-push to fix the directory structure merge conflict, it seems I have to force push again to get the pull request updated. Sorry--I hope it doesn't make the PR history too confusing.) |
Is this ready to be merged? Would be great to have in Apache NetBeans 10. |
Should be ready, yes. |
OK, merging, this has been reviewed a lot and everyone is happy. |
Improve text layout for the NetBeans editor's "word wrap" feature. This makes the word wrap behavior more in line with that of other editors, and makes wrapped text more readable. See detailed description and before/after screenshot (also attached here) at https://issues.apache.org/jira/browse/NETBEANS-977 .