Bug 253056 - BlockSelection: add get/setBlockSelectionRectangle to StyledText
Summary: BlockSelection: add get/setBlockSelectionRectangle to StyledText
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 3.5 M7   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 262625 267804 269788
  Show dependency tree
 
Reported: 2008-11-01 10:13 EDT by Tom Hofmann CLA
Modified: 2009-04-30 21:32 EDT (History)
4 users (show)

See Also:
steve_northover: pmc_approved+


Attachments
patch (incomplete) (2.43 KB, patch)
2009-03-23 14:46 EDT, Felipe Heidrich CLA
no flags Details | Diff
patch (5.71 KB, patch)
2009-04-16 15:36 EDT, Felipe Heidrich CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2008-11-01 10:13:14 EDT
Follow-up from splitting bug 8521:

As a counterpart to the StyledText::getSelectionRanges API (bug 250171), clients also need to be able to set the block selection to the widget.

Therefore, I request the following API:

  void setSelectionRanges(int[])
Comment 1 Tom Hofmann CLA 2008-11-01 10:17:53 EDT
This is a blocking requirement for bug 19771, because there are many places where the text editors store the widget's selection in order to restore it later (e.g. after a compound operation).
Comment 2 Felipe Heidrich CLA 2008-11-03 11:17:09 EST
Not sure how this API will work.
Is very unlikely that all start/length pairs will form a rectangle. What to do when one start offset and the next are not in the same column ?

the only solution i can think of is:
block lead edge = minimum lead of all start offsets 
block trail edge = maximum trail of all end offsets

is that what you expected ?

------

Why do you need this API ? is to restore the state when eclipse restart ?
Comment 3 Tom Hofmann CLA 2008-11-03 11:45:02 EST
(In reply to comment #2)
> Is very unlikely that all start/length pairs will form a rectangle. What to do
> when one start offset and the next are not in the same column ?

Hm, I understand. My request does not make sense....

Does the normal setSelectionRange(int,int) call work during block selection (i.e. select the rectangle between the start and end point)? In that case, I could use it to restore the selection.

> Why do you need this API ? is to restore the state when eclipse restart ?

Not just on restart. There are numerous places where the current selection is remembered, then some more or less complex operation occurs (as an example, consider "Organize Imports"), then the selection gets restored. The goal is that the user does not perceive any selection change, even though the character range(s) covered by the selection may differ from the situation before the operation.

In order to really maintain the exact same selection, I would need get/setBlockSelectionRectangle which would work pixel based.

Comment 4 Felipe Heidrich CLA 2008-11-03 12:02:50 EST
(In reply to comment #3)
> Does the normal setSelectionRange(int,int) call work during block selection
> (i.e. select the rectangle between the start and end point)? 
Yes. the selection rectangle is defined by the left-top corner of the character at start offset and right-bottom corner of the character at end offset.


> In that case, I could use it to restore the selection.
Let me know if it works.

> > Why do you need this API ? is to restore the state when eclipse restart ?
> Not just on restart. There are numerous places where the current selection is
> remembered, then some more or less complex operation occurs (as an example,
> consider "Organize Imports"), then the selection gets restored. The goal is
> that the user does not perceive any selection change, even though the character
> range(s) covered by the selection may differ from the situation before the
> operation.
> In order to really maintain the exact same selection, I would need
> get/setBlockSelectionRectangle which would work pixel based.

Yes, but if the text under the selection rectangle changes during these operations the actual selected text will change.
Comment 5 Tom Hofmann CLA 2008-11-03 12:09:44 EST
(In reply to comment #4)
> > In that case, I could use it to restore the selection.
> Let me know if it works.

Will do. I removed the blocking flag.

> Yes, but if the text under the selection rectangle changes during these
> operations the actual selected text will change.

Yes - but that is typically ok from a user's perspective. We try to keep the "logical selection" stable, even if the actual range differs. Imagine you have a method or a couple of statements selected, then press Ctrl+Shift+O to organize the imports - you certainly don't expect the selection to be somewhere completely different.

What we do is we compute the logical start and endpoints of the selection before the operation, then track the content modification and the set the selection accordingly. 

In block selection mode, it will not be enough to just track the start and end offsets of the block selection, but also the pixel offsets relative to these offsets.

Comment 6 Felipe Heidrich CLA 2008-11-05 16:56:53 EST
Tom, should I close this problem report ?

I hope you can do all you need with setSelectionRange(int,int).
If not, we could look into adding getBlockSelectionRectangle/setBlockSelectionRectangle().
Comment 7 Tom Hofmann CLA 2008-11-06 03:24:57 EST
Access to the pixel-based block selection would be good in order to fix bug 19771 properly and transparently. I changed the summary accordingly.
Comment 8 Felipe Heidrich CLA 2008-11-07 14:48:39 EST
(In reply to comment #7)
> Access to the pixel-based block selection would be good in order to fix bug
> 19771 properly and transparently. I changed the summary accordingly.

is this a blocker for 19771 ?
Comment 9 Tom Hofmann CLA 2008-11-07 15:45:38 EST
(In reply to comment #8)
> is this a blocker for 19771 ?

Hard to say for sure at the moment, as I haven't looked at how to convert the previous setBlockSelection calls to the new calls. I don't think it is a hard blocker. 

Comment 10 Tom Hofmann CLA 2009-03-05 19:08:43 EST
This is still an issue surfacing at various places in the text editors.

It is now possible that the user creates a selection that cannot be reproduced programmatically. It is also possible that the same selection ranges are answered for two selections that look very obviously different from each other.

Look at bug 262625 for an illustrated example.

There is a strong need for platform-text to determine and restore the exact selection as it is displayed by the widget. This includes selection over the end of line.
Comment 11 Felipe Heidrich CLA 2009-03-06 15:53:48 EST
What getBlockSelectionRectangle returns when the block selection is not up ?
a) null
b) emtpy rect
c) the rectangle of the regular selection, 
----what if regular selection is empty (start==end) ?
    c.1) caret bounds 

What setBlockSelectionRectangle does if block selection mode == false ?
a) ignore
b) set block selection mode = true, and set the block selection 

Will it need to scroll to show the new block selection (when it isn't in within the client area) ?


Steve:
I have these APIs internally already, it is just a matter of deciding a few questions. We have very little time to add new APIs.
Comment 12 Tom Hofmann CLA 2009-03-11 04:16:47 EDT
> What getBlockSelectionRectangle returns when the block selection is not up ?
> a) null
> b) emtpy rect
> c) the rectangle of the regular selection, 
> ----what if regular selection is empty (start==end) ?
>     c.1) caret bounds 

No strong opinion, you could even throw the SWT complement of IllegalStateException or alike. c) does not really make sense, since a linear selection is not a rectangle. I would prefer b) over a) as null is always problematic. The API could state that the returned rectangle is not well defined if the widget is not in block selection mode.


> What setBlockSelectionRectangle does if block selection mode == false ?
> a) ignore
> b) set block selection mode = true, and set the block selection 

Again, using this API in non-block mode seems an error to me. b) seems dangerous, so I would prefer a) or an exception.


> Will it need to scroll to show the new block selection (when it isn't in 
> within the client area) ?

No - I would expect the API to behave similar to setSelectionRange, which does not reveal the selection. Clients can always call showSelection to achieve the same.
Comment 13 Felipe Heidrich CLA 2009-03-23 14:46:19 EDT
Created attachment 129626 [details]
patch (incomplete)
Comment 14 Felipe Heidrich CLA 2009-03-23 14:46:57 EDT
Missed M6, we will need PMC approval for new API.
Comment 15 Tom Hofmann CLA 2009-04-15 15:10:16 EDT
Definitely major for text land: without this, using block selection mode in editors is a pain in many situations (see blocking list).
Comment 16 Felipe Heidrich CLA 2009-04-15 19:57:22 EDT
Steve, I have the code ready. Are you okay with me sending the request to PMC ?
Comment 17 Steve Northover CLA 2009-04-16 13:01:46 EDT
Yes, the API is needed.  Please request on the PMC list.
Comment 18 Felipe Heidrich CLA 2009-04-16 15:36:45 EDT
Created attachment 132128 [details]
patch
Comment 19 Dani Megert CLA 2009-04-17 03:16:58 EDT
Thanks guys!
Comment 20 Felipe Heidrich CLA 2009-04-17 10:50:45 EDT
Fixed in HEAD > 20090417

(sorry it took so long)
Comment 21 Tom Hofmann CLA 2009-04-17 11:09:34 EDT
> Fixed in HEAD > 20090417

Cool! ... although now I probably have to come up with fixes for those other bugs... grrr. :-)