Issue 21398 - StarBasic can't tell one end of a range from the other
Summary: StarBasic can't tell one end of a range from the other
Status: ACCEPTED
Alias: None
Product: Writer
Classification: Application
Component: code (show other issues)
Version: OOo 1.1 RC5
Hardware: All All
: P4 Trivial with 1 vote (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-18 09:51 UTC by ingenstans
Modified: 2013-08-07 14:38 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ingenstans 2003-10-18 09:51:17 UTC
The functions getEnd() and getStart(), when applied to a text range, return a 
range from beginning and the end, as they should. The bug is that you don't know 
which you'll get. Sometimes getStart() returns the start of a range. Sometimes 
it returns the end. getEnd() will always return the opposite end to getStart(). 

The expected, and logical behaviour, is that getStart() should always return the 
end of the range nearest the start of the text, and getEnd() should return the 
end furthest from the start. This should obviously dependent on the way the text 
is read -- ie the start shouold be on th eleft i English and on the right in eg 
Hebrew.

For the moment there is a workaround. You just need to compare the two ranges 
before using them, to determine which is actually the start and which th eend. 

As an immediate fix, I suggest changing the documentation in the API, to add to 
each method the following warning:

" getStart() and getEnd() are guaranteed to return the beinning and end of a 
text range. Despite their names, it is not guaranteed that the range returned by 
betStart() will come before the range returned by getEnd(). If you want to use 
them as the start and end points of a range to be traversed, you need to check 
which one comes first. This can be done, in Basic, with code like this

...
 if not atext.compareRegionStarts(aRange.getStart(),aRange.getEnd()) then
      startcursor=atext.createTextCursorByRange(aRange.getStart())
      stopcursor=atext.createTextCursorByRange(aRange.getEnd())
 else
      startcursor=atext.createTextCursorByRange(aRange.getEnd())
      stopcursor=atext.createTextCursorByRange(aRange.getStart())
end if
...
"
Comment 1 kay.ramme 2003-10-20 08:57:59 UTC
Andrease, please have a look at this and target it appropriately.
Comment 2 ab 2003-10-20 11:12:10 UTC
That seems to be a (Writer?) API problem and has nothing to do with Basic.
Comment 3 Oliver Specht 2003-10-20 11:28:02 UTC
The start or end position does not and should not depend on the
writing direction. 

os->tl: Either the bookmark that is created for SwXTextRange objects
should be in the right direction or the getStart/End methods should
check the direction.
Comment 4 thomas.lange 2003-10-20 14:30:43 UTC
Set target to OOo 2.0
Comment 5 stephan.wunderlich 2004-05-03 13:13:35 UTC
SW: changed Prio
Comment 6 stephan.wunderlich 2004-05-05 16:49:23 UTC
SW: changed target
Comment 7 untel 2006-07-05 01:41:13 UTC
I know this is an old issue, but I'd like an update about it.

Has it been effectively solved by the similar Issue 21335 (which is reported as
fixed)?

If not, at least *one* example where getStart and getEnd doesn't give
respectively the leftmost and rightmost end of the selected range would be
appreciated.

On my end, these methods seem to do their jobs as expected, but I'd like to know
if it's stabilized.
Comment 8 untel 2006-07-26 02:56:13 UTC
Long forgotten issue apparently, if it's still an issue.

Anyways, will reluctantly continue to use andrewb's hack posted in his initial
message, and other hacks when necessary.... assuming of course that
compareRegionStarts itself has no unforseen bugs.

It is unfortunate one cannot trust such simple methods.