Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 374086 - [syntax highlighting] "Highlight enclosing brackets" doesn't work well without "Highlight at caret location"
Summary: [syntax highlighting] "Highlight enclosing brackets" doesn't work well withou...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.8   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 3.8 M7   Edit
Assignee: Deepak Azad CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-13 10:55 EDT by Markus Keller CLA
Modified: 2012-03-19 10:52 EDT (History)
2 users (show)

See Also:
daniel_megert: review+


Attachments
fix (9.68 KB, text/plain)
2012-03-14 12:39 EDT, Deepak Azad CLA
no flags Details
additional fix (2.32 KB, patch)
2012-03-15 11:42 EDT, Deepak Azad CLA
no flags Details | Diff
patch for platform text (919 bytes, patch)
2012-03-17 08:43 EDT, Deepak Azad CLA
daniel_megert: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2012-03-13 10:55:34 EDT
"Highlight enclosing brackets" doesn't work well without "Highlight at caret location".

Bug 366400 comment 8 point 5 is still broken. More generally: Whenever you move into a pair of brackets from the outside (from left or from right), the crossed bracket is not highlighted again.


Before we working on a fix, consider whether "Highlight enclosing brackets" without "Highlight at caret location" makes sense at all from a usage point of view. If you're interested in enclosing brackets, why would you want to lose this information when you get close to a bracket?

I don't see a use case for this, and I think the first suboption should be renamed back to "Highlight both brackets". The third option should be a sub-option of the second option, and the third could be enabled by default (but it's still implicitly disabled out of the box because the second option is disabled).
Comment 1 Deepak Azad CLA 2012-03-13 11:04:03 EDT
(In reply to comment #0)
> Before we working on a fix, consider whether "Highlight enclosing brackets"
> without "Highlight at caret location" makes sense at all from a usage point of
> view. If you're interested in enclosing brackets, why would you want to lose
> this information when you get close to a bracket?
I don't know :-) To me not highlighting the bracket at caret location, with or without enclosing brackets enabled, is just wrong. I wanted to chuck this preference and always highlight both brackets...
 
> I don't see a use case for this, and I think the first suboption should be
> renamed back to "Highlight both brackets". The third option should be a
> sub-option of the second option, and the third could be enabled by default (but
> it's still implicitly disabled out of the box because the second option is
> disabled).
Isn't that a bit complicated? Also, the third option as a sub-option of the second option looks a bit odd...
Comment 2 Markus Keller CLA 2012-03-13 12:48:52 EDT
Not highlighting at the caret location makes sense when you're typing e.g. a closing ')': The box around the typed character can be distracting, but the matching bracket highlight is ambient information that is less intrusive but still interesting.

This workflow is currently broken, but bug 372516 will fix that.
Comment 3 Deepak Azad CLA 2012-03-13 15:01:30 EDT
(In reply to comment #0)
> If you're interested in enclosing brackets, why would you want to lose
> this information when you get close to a bracket?

(In reply to comment #2)
> Not highlighting at the caret location makes sense when you're typing e.g. a
> closing ')': The box around the typed character can be distracting.

The above two sound a bit contradictory, no? Either you want the bracket at caret location highlighted or you don't. Is the fact that you just typed the bracket or not make that big a difference in the 'distraction' levels?

Other possible solution to the problem could be to use a different way of highlighting the brackets, which do not interfere with the caret and then highlight both all the time. Notepad++ just paints the matched brackets themselves in red color. I quite like that look and feel.
Comment 4 Markus Keller CLA 2012-03-13 16:19:54 EDT
(In reply to comment #3)
Sounds contradictory, but isn't, since the two statements apply to different settings. The distraction is that the box appears/disappears in situations where that's not interesting information.

With enclosing brackets enabled, moving the caret out of a pair of brackets has one interesting state change (from inner brackets to outer brackets) but with the bad setup you'd get two state changes (inner brackets, one bracket hides, outer brackets). When you move into the pair, the late appearance of the box looks like an off-by-one bug.

With both options disabled, you don't care about enclosing brackets, but you'd like to see the peer of the bracket at the caret location. The blinking of the peer the confirms that you closed the group you meant to close. Blinking at the caret as well would not give you more information.
Comment 5 Dani Megert CLA 2012-03-14 08:28:58 EDT
We will fix the preference UI for M6, but the bug itself (see comment 0) still needs to be investigated and fixed (can happen during M7).
Comment 6 Markus Keller CLA 2012-03-14 09:12:36 EDT
The current wording on the preference page has a few detail bugs that also make the options hard to understand.

Here's a version that removes the bad combination and clarifies the others:

[x] &Bracket highlighting
    o &Matching bracket
    o Ma&tching bracket and caret location
    o &Enclosing brackets
Comment 7 Deepak Azad CLA 2012-03-14 12:39:58 EDT
Created attachment 212665 [details]
fix
Comment 8 Deepak Azad CLA 2012-03-14 12:44:15 EDT
(In reply to comment #7)
> Created attachment 212665 [details]
> fix

The patch just tweaks the UI.

Regarding the bug in underlying preferences..
- We can simply add a disclaimer to MatchingCharacterPainter.setHighlightCharacterAtCaretLocation(boolean)- 
"Calling this method has no effect when enclosing brackets are enabled"
- And then just always paint both brackets when 'fHighlightEnclosingPeerCharacters' is true.

Is this what we are looking for? This can be fixed today itself..
Comment 9 Deepak Azad CLA 2012-03-14 13:02:08 EDT
(In reply to comment #8)
> Regarding the bug in underlying preferences..
> - We can simply add a disclaimer to
> MatchingCharacterPainter.setHighlightCharacterAtCaretLocation(boolean)- 
> "Calling this method has no effect when enclosing brackets are enabled"
> - And then just always paint both brackets when
> 'fHighlightEnclosingPeerCharacters' is true.
> 
> Is this what we are looking for? This can be fixed today itself..
Nevermind. Had a chat with Markus and understood that this is not what we want to do.
Comment 10 Dani Megert CLA 2012-03-14 13:04:24 EDT
The patch works but the code has issues:
- widgetSelected(...) is called on both buttons when going from on radio to
  another (see Javadoc for details). Hence you can't just adjust the prefs
  without checking (or using) the state.
- use getSelection() on the fields, that's simpler than getting the widget
  and casting it to a button
- should use getPreferenceStore() and not introduce 'fStore'
- typo: checkox
- addButton(...) uses wrong variable name (copied code)
Comment 11 Deepak Azad CLA 2012-03-14 13:20:37 EDT
Thanks Dani!

I pushed the final fix to master
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=310b5a4861b7c93e44dc110dca42def5aace82ab
Comment 12 Dani Megert CLA 2012-03-15 03:48:18 EDT
Verified the new preference UI in I20120314-1800.
Comment 13 Deepak Azad CLA 2012-03-15 11:42:40 EDT
Created attachment 212732 [details]
additional fix

There is a small problem in master (and in I20120314-1800), on clicking 'Restore defaults' the defaults are restored in the underlying preference file but the UI  for the reworked options is not updated to reflect the same.

The patch fixes the problem.
Comment 14 Deepak Azad CLA 2012-03-15 12:08:28 EDT
(In reply to comment #13)
> Created attachment 212732 [details] [diff]
> additional fix

Pushed to master - http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=a1a19e6a24a3bb58c04429a0b9ac4bc88fe7bf9a
Comment 15 Deepak Azad CLA 2012-03-17 08:43:07 EDT
Created attachment 212823 [details]
patch for platform text

Patch for the bug in Platform/Text.

Since we already tweaked the preference UI, to reproduce the bug and test the patch, change the line in MatchingCharacterPainter.setHighlightCharacterAtCaretLocation(boolean) to "fHighlightCharacterAtCaretLocation= false;"
Comment 16 Dani Megert CLA 2012-03-19 10:51:49 EDT
(In reply to comment #15)
> Created attachment 212823 [details] [diff]
> patch for platform text
> 
> Patch for the bug in Platform/Text.
> 
> Since we already tweaked the preference UI, to reproduce the bug and test the
> patch, change the line in
> MatchingCharacterPainter.setHighlightCharacterAtCaretLocation(boolean) to
> "fHighlightCharacterAtCaretLocation= false;"

Thanks.
Committed to master: http://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=82ab4ae30e3c1a61168a9cf156385d9a3b84c1fb