Issue 29942 - Changing the String property of a text range also changes the neighboring range
Summary: Changing the String property of a text range also changes the neighboring range
Status: CLOSED FIXED
Alias: None
Product: Writer
Classification: Application
Component: code (show other issues)
Version: OOo 1.1 RC5
Hardware: All All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: stephan.wunderlich
QA Contact: issues@sw
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-07 16:38 UTC by akrioukov
Modified: 2013-08-07 14:41 UTC (History)
1 user (show)

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


Attachments
Text document with a macro allowing to reproduce the problem. (6.89 KB, application/vnd.sun.xml.writer)
2004-06-07 16:40 UTC, akrioukov
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description akrioukov 2004-06-07 16:38:10 UTC
In fact, this problem is related with OOo Writer search and replace
functionality (at least I couldn't reproduce it with text ranges created by
another way). Suppose we have a program which uses XSearchable.findAll () in
order to get all occurences of a specific string in a document. When we are
iterating through these occurences and set their String to another value (in
case you are interesting why not to use OOo built-in replace functionality
instead, see the issue 10569).

This issue deals with the case where some of the found text ranges immediately
follow each other. For example, suppose we are searching for the letter "z" in
order to replace it with "s" in a text which contains, say, a word written as
"thizzzz": of course, we should get several neighbouring ranges, each covering a
single letter "z". And now the problem: for a mystical reason setting the String
property of one such range also changes the String of the range which
immediately follows it. Now this second range will also cover the text we have
just inserted before, i. e. "sz" in our case instead of a single "z"! This
behavior is illustrated by the attahced document with a macro: running this
macro replaces "thizzzz" with "this", so that several occurences of "z" become
one single "s" :-) 

The most annoying fact is, that this specific problem never existed before
1.1.0rc5, and so it is a result of some relatively recent code changes. I didn't
reported it when I experienced it first just because I don't really believe it
ever gets fixed :( . However, I need this issue at least in order to be able to
give links to it, instead of describing the problem (which is not so easy to
describe) each time.
Comment 1 akrioukov 2004-06-07 16:40:08 UTC
Created attachment 15718 [details]
Text document with a macro allowing to reproduce the problem.
Comment 2 michael.ruess 2004-06-08 07:29:52 UTC
MRU->SW: looks like API stuff.
Comment 3 stephan.wunderlich 2004-06-09 15:36:19 UTC
SW->TL: the macro searches for 'z' and wants to replace it by 's' .... findAll()
returns as expected {z,z,z,z} for thizzzz, but when the first z is replaced with
an 's' the content of the container changes to {z, sz, z , z} ... this way
'thizzz' is transformed to 'this' by simply replacing 'z' with 's' instead of
the expected 'thissss'. 
I could reproduce this behaviour in OOo1.0.1, OOo1.1.0 and OOo1.1.1, so it seems
to be not as new as mentioned in the description. Anyway this behaviour differs
from the expectation and the behaviour in the UI so it should be taken into
account to get it solved in OOo2.0.
Comment 4 thomas.lange 2004-06-11 09:02:33 UTC
.
Comment 5 thomas.lange 2004-07-13 11:16:27 UTC
The problem is that bookmarks which are used to specify the text range grow when
text is inserted directly before them.
Since searching for "z" in a text like "zzzzz" results in 5 bookmarks
(XTextRanges) following directly each other, replacing the first results
indirectly in having the second extended by the new inserted text and so on.

Unfortunately it is not as simple as using an uno cursor for the implementation
since those grow by text inserted directly after it.

Need to check with OS and AMA what to do.

Code references: 
- SwXTextRange::DeleteAndInsert
- SwTxtNode::Update
- SwIndexReg::Update

Comment 6 thomas.lange 2004-07-13 11:22:51 UTC
A workaround for the current implementation would be to replace the strings in
reverse order i.e. starting with the one last found.
Comment 7 thomas.lange 2004-10-04 14:05:20 UTC
Fixed in CWS tl03.
Files changed:
- ndtxt.cxx  new revision: 1.36.38.1
Comment 8 thomas.lange 2004-10-04 14:06:56 UTC
.
Comment 9 thomas.lange 2004-11-01 09:14:48 UTC
.
Comment 10 thomas.lange 2004-11-01 09:15:07 UTC
.
Comment 11 thomas.lange 2004-11-01 09:15:52 UTC
OK in CWS tl03.
Comment 12 stephan.wunderlich 2004-11-02 11:51:52 UTC
looks good in cws_tl03 => verified
Comment 13 stephan.wunderlich 2004-12-16 12:09:26 UTC
ok in src680_m66 => closed