Apache OpenOffice (AOO) Bugzilla – Issue 21335
XTextRange::getStart() and XTextRange::getEnd() confusion
Last modified: 2013-02-24 21:10:05 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.
[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
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.
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.
.
Fixed in CWS os22. Files changed: - unoobj2.cxx 1.38.60.1 - unotext.cxx 1.22.262.1
Sorry! !!! Fixed in CWS os23 !!!
Needs also file - unoparagraph.cxx 1.27.226.1
Also changed: bookmrk.hxx 1.3.464.1
Fixed in CWS os23. See attached document.
Created attachment 11087 [details] sample testcase
verified in os23
tested in src680_m17