Bug 531957 - [code mining] Line content annotation doesn't take the expected space
Summary: [code mining] Line content annotation doesn't take the expected space
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.8   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.8 M7   Edit
Assignee: Angelo ZERR CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 531769
Blocks:
  Show dependency tree
 
Reported: 2018-03-03 05:04 EST by Angelo ZERR CLA
Modified: 2018-04-05 17:31 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Angelo ZERR CLA 2018-03-03 05:04:25 EST
When line content annotation is created with the label "X" and it is must inserted inside "abc" like this a[X]bc, the "[X] annotation is drawn on the top of b a[X and b]c.

This bug is because of the line content annotation redraw the next character of the annotion (c) and GlyphMetrics doesn't take well place: the width is "X" width but it should be "X width + c width".

So today to fix this problem, line content annotation must add an extra space 
like this "X ".
Comment 1 Mickael Istria CLA 2018-03-03 05:11:13 EST
I don't think it's a bug as it doesn't decrease user experience (codemining already insert the space, doesn't it?). It's more a suboptimal implementation to improve.
Comment 2 Angelo ZERR CLA 2018-03-03 05:20:02 EST
> I don't think it's a bug as it doesn't decrease user experience (codemining already insert the space, doesn't it?)

No it doesn't insert space. It uses GlyphMetrics to take some place and after line content annotation draw inside the place taken by GlyphMetrics.

As character is redrawn, GlyphMetrics width must be the annotation width + character width.

I have created a gerrit patch for that, but perhaps it should be better that XText team review this gerrit patch because problem was found by a guy of XText.

This gerrit patch fixes the problem, but what about the edition? It should be cool if we could have feedback of XText guys to know if my gerrit patch is OK for draw and for editing too.
Comment 3 Mickael Istria CLA 2018-03-03 05:30:00 EST
(In reply to Angelo ZERR from comment #2)
> As character is redrawn, GlyphMetrics width must be the annotation width +
> character width.

Yes, but it's already the current behavior of LineContentAnnotation, isn't it?
 
> I have created a gerrit patch for that, but perhaps it should be better that
> XText team review this gerrit patch because problem was found by a guy of
> XText.

The only proper solution here would be the addition of the "prefixMetrics" or similar. Is this what you have in mind here?

But what about the edition? The current behavior seems good: even with glyphMetrics, the "character" in styled text remain the whole rendered thing, ie the glyphmetrics area. So if one deletes the character, then it deletes the whole area, if one copy the area, the content of the clipboard is the character on which glyphmetrics applied.
Comment 4 Angelo ZERR CLA 2018-03-03 15:52:07 EST
> As character is redrawn, GlyphMetrics width must be the annotation width +
> character width.
> Yes, but it's already the current behavior of LineContentAnnotation, isn't it?

No, today GlyphMetrics width is today only annotation width. It doesn't contains the width of the character. My gerrit patch fixes that.

> The only proper solution here would be the addition of the "prefixMetrics" or similar. Is this what you have in mind here?

Yes sure, once "prefixMetrics" will be accepted we could remove the code of redraw the character. But I'm afraid that it will take time, so I would like to improve again redraw of character.

> But what about the edition? 

I mean type text which generates annotation, select text after the annotation, etc).

> The current behavior seems good: even with glyphMetrics, the "character" in styled text remain the whole rendered thing, ie the glyphmetrics area. So if one deletes the character, then it deletes the whole area, if one copy the area, the content of the clipboard is the character on which glyphmetrics applied.

Yes, but I have played with JDT CodeMining and sometimes annotation can disturb the developer which types content (when annotaion, is removed, added, etc).
Comment 5 Mickael Istria CLA 2018-03-05 03:59:37 EST
I'm marking this one as depending on bug 531769 because fixing bug 531769 would allow an elegant fix for this one. In the meantime, it's still fine to implement a workaround on CodeMining until bug 531769 is properly fixed and the proper implementation can be written on top of it.
Comment 6 Angelo ZERR CLA 2018-03-12 07:59:47 EDT
@Mickael, I'm working on this issue, the main goal is to improve draw of character hidden by GlyphMetrics. My gerrit patch will fix 2 issues:

 * the width of GlyphMetrics which must store the "annotation width + character width)
 * the style of character (bold, italic, etc).

A gerrit patch will come soon.
Comment 7 Eclipse Genie CLA 2018-03-12 16:37:35 EDT
New Gerrit change created: https://git.eclipse.org/r/119271
Comment 8 Angelo ZERR CLA 2018-03-12 16:40:59 EDT
@Mickael, please review my gerrit patch https://git.eclipse.org/r/#/c/119271/ where I have clean code to have a common code to update GlyphMetrics width:

 * inside text presentation listener 
 * and when annotation is drawn.

This gerrit patch fixes space problem.

This gerrit patch uses code from https://git.eclipse.org/r/#/c/119271 for inlined content annotation.