Apache OpenOffice (AOO) Bugzilla – Issue 29942
Changing the String property of a text range also changes the neighboring range
Last modified: 2013-08-07 14:41:36 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.
Created attachment 15718 [details] Text document with a macro allowing to reproduce the problem.
MRU->SW: looks like API stuff.
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.
.
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
A workaround for the current implementation would be to replace the strings in reverse order i.e. starting with the one last found.
Fixed in CWS tl03. Files changed: - ndtxt.cxx new revision: 1.36.38.1
OK in CWS tl03.
looks good in cws_tl03 => verified
ok in src680_m66 => closed