Issue 21335 - XTextRange::getStart() and XTextRange::getEnd() confusion
Summary: XTextRange::getStart() and XTextRange::getEnd() confusion
Status: CLOSED FIXED
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: Other Linux, all
: P3 Trivial
Target Milestone: ---
Assignee: chne
QA Contact: issues@api
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-16 18:25 UTC by con.hennessy
Modified: 2013-02-24 21:10 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
sample testcase (6.48 KB, application/octet-stream)
2003-11-10 10:06 UTC, thomas.lange
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description con.hennessy 2003-10-16 18:25:10 UTC
It is very confusing when using the above mentioned methds as getStart() can actually 
return the end of the range, but the documentation only states : 
   a text range which contains only the start of this text range.  
 
This statement by itself is not very clear and is at the worst misleading as it would lead 
one to think that the position closest to the beginign of  the document would be 
returned - the opposite seems to be true! 
 
Please fix either the implementation ( or provide a new clearer interface ) or update the 
documentation. My preference is to fix the implementation otherwise I have to do a 
XTextRangeCompare which I think is quite an expensive operation.
Comment 1 con.hennessy 2003-10-17 00:41:33 UTC
[this is the text I sent to the dev@api mailign list ] 
 If you have a very simple text document e.g. with the following content : 
start 
middle1 
middle2 
end 
 
And run the following macro : 
Sub Main 
        Dim model, cont, selection As Object 
        Dim  selections As Object 
        cont = StarDesktop.ActiveFrame.Controller 
        model = ThisComponent 
        selections = cont.GetSelection() 
        selection = selections.getByIndex(0) 
        msgbox ( "the selection is :" + selection.GetString() ) 
         
        Dim paragraphs, para as Object 
        paragraphs = model.Text.createEnumeration() 
        do while ( paragraphs.HasMoreElements )  
                currentPara = paragraphs.nextElement() 
                resStart = model.Text.compareRegionStarts( currentPara, 
selection ) 
                resEnd = model.Text.compareRegionEnds( currentPara, 
selection ) 
                msgbox ( "for [" + currentPara.getString() + "] region beg 
shows : " + resStart + " region end shows : " + resEnd) 
        loop 
End Sub 
 
 
Basically the docs for compareRegionStarts()/compareRegionEnds() state 
that when 
the first param < the second param : result = 1 
the first param == the second param : result = 0 
the first param > the second param : result = -1 
 
However you will get the following output if "middle1" is selected : 
the selection is : middle1 
for Start region beg shows : 1 region end shows : 1   
for middle1 region beg shows : 1 region end shows : 0 
for middle2 region beg shows : -1 region end shows : -1 
for end region beg shows : -1 region end shows : -1 
 
you will get the following output if "dle1" is selected : 
the selection is : dle1 
for Start region beg shows : 1 region end shows : 1 
for middle1 region beg shows : 1 region end shows : 1 
for middle2 region beg shows : -1 region end shows : -1 
for end region beg shows : -1 region end shows : -1 
 
you will get the following output if "end" is selected : 
the selection is : end 
for Start region beg shows : 1 region end shows : 1 
for middle1 region beg shows : 1 region end shows : 1 
for middle2 region beg shows : 1 region end shows : 1 
for end region beg shows : 1 region end shows : 0 
 
None of this corresponds to  
http://api.openoffice.org/docs/common/ref/com/sun/star/text/
XTextRangeCompare.html 
which if it did I would expect : 
the selection is : middle1 
for Start region beg shows : 1 region end shows : 1   
for middle1 region beg shows : 0 region end shows : 0 ( the selection start 
should be  
                                                                                the same as the 
paragraph start ) 
for middle2 region beg shows : -1 region end shows : -1 
for end region beg shows : -1 region end shows : -1 
 
you will get the following output if "dle1" is selected : 
the selection is : dle1 
for Start region beg shows : 1 region end shows : 1 
for middle1 region beg shows : 1 region end shows : 0 ( the selection end 
should be  
                                                                                the same as the 
paragraph end) 
for middle2 region beg shows : -1 region end shows : -1 
for end region beg shows : -1 region end shows : -1 
 
you will get the following output if "end" is selected : 
the selection is : end 
for Start region beg shows : 1 region end shows : 1 
for middle1 region beg shows : 1 region end shows : 1 
for middle2 region beg shows : 1 region end shows : 1 
for end region beg shows : 0 region end shows : 0 ( the selection start 
should be  
                                                                                the same as the 
paragraph start ) 
 
Am I misunderstanding the docs, or is this a known bug ? 
CPH 
Comment 2 ooo 2003-10-23 09:30:42 UTC
if there is no good reason for this, this behaviour should be changed.
 If there is good reason, this should be explained and a property
offered to easily get the order.  This property should be a method at
XTextRange, but this would be incompatible. It should be stated there
anyway, expecially for the case we ever create new interfaces in
org.openoffice namespace.

Forwarding to responsible developer.
Comment 3 thomas.lange 2003-10-28 13:09:51 UTC
Sub Main

Dim model, cont, selection As Object 
Dim  selections As Object 
model = ThisComponent 
'cont = StarDesktop.ActiveFrame.Controller 
cont = model.getCurrentController()
selections = cont.GetSelection() 
selection = selections.getByIndex(0) 
msgbox ( "the selection is :" + selection.GetString() ) 
 
Dim paragraphs, para as Object 
paragraphs = model.Text.createEnumeration() 
do while ( paragraphs.HasMoreElements )  
        currentPara = paragraphs.nextElement() 
        resStart = model.Text.compareRegionStarts( currentPara,
selection ) 
        resEnd = model.Text.compareRegionEnds( currentPara, selection ) 
        msgbox ( "for [" + currentPara.getString() + "] region beg
shows : " + resStart + " region end shows : " + resEnd) 
loop 

End Sub



Already fixed along with internal bug #109732# in CWS tlapi1.

TL->CN: Please confirm.
Comment 4 thomas.lange 2003-10-28 13:10:37 UTC
.
Comment 5 thomas.lange 2003-10-28 14:43:41 UTC
.
Comment 6 thomas.lange 2003-10-28 14:46:10 UTC
Fixed in CWS os22.

Files changed:
- unoobj2.cxx  1.38.60.1
- unotext.cxx  1.22.262.1
Comment 7 thomas.lange 2003-10-28 14:49:02 UTC
.
Comment 8 thomas.lange 2003-10-28 14:49:37 UTC
Sorry!

!!! Fixed in CWS os23 !!!
Comment 9 thomas.lange 2003-10-28 14:53:18 UTC
Needs also file
- unoparagraph.cxx  1.27.226.1
Comment 10 thomas.lange 2003-10-29 09:12:00 UTC
Also changed:
bookmrk.hxx  1.3.464.1
Comment 11 thomas.lange 2003-11-10 10:02:10 UTC
.
Comment 12 thomas.lange 2003-11-10 10:04:45 UTC
.
Comment 13 thomas.lange 2003-11-10 10:05:24 UTC
Fixed in CWS os23.

See attached document.
Comment 14 thomas.lange 2003-11-10 10:06:46 UTC
Created attachment 11087 [details]
sample testcase
Comment 15 chne 2003-11-18 14:19:49 UTC
verified in os23
Comment 16 chne 2003-12-10 12:04:09 UTC
tested in src680_m17