Skip to main content
Participating Frequently
March 4, 2009
Answered

Bug in Styles

  • March 4, 2009
  • 1 reply
  • 691 views
Hi,
This bug is although reproducible, but the steps I've found are a bit complex. I've also confirmed this bug on SimpleEditorWithCSS sample. I'm using Gumbo build (4.0.0.5121) with TLF build-377.

Steps to reproduce on SimpleEditorWithCSS:
1. select "style" tab and then select Level to Span
2. select text from postion "X" to position "Y" and set styleName to "style1"
3. select text from postion "X-10" to position "Y-10" and set styleName to "style2"
4. select text from postion "X-5" to position "Y+10" and set styleName to "style1"
(Please note that these positions are not exactly needed, but these positions show the pattern which is needed to reproduce)

Result on released binaries: Editor Hangs
Result on debug build: Exception (I've pasted the stack from EditManager.doOperation onwords)
RangeError: invalid parameter to FlowGroupElement.split
at flashx.textLayout.elements::FlowGroupElement/splitAtPosition()
at flashx.textLayout.operations::FlowElementOperation/getTargetElement()
at flashx.textLayout.operations::ChangeElementStyleNameOperation/doOperation()
at flashx.textLayout.edit::EditManager/doInternal()
at flashx.textLayout.edit::EditManager/doOperation()

Thanks,
Ahmed
This topic has been closed for replies.
Correct answer longlostbigelow
I'm not seeing a reference to an original bug, which the post on 11/23 implies, but in looking at the SimpleEditorWithCSS sample, the issue is with how the operation collects and iterates over the elements having the style applied. Because the example sited is using the same style name as that applied to the second element, a series of merges occur which renders the second element invalid.

Initial State:
<span styleID="a">foo</span><span styleID="b">bar</span><span>moreFooBar</span>
Selection from "oo" of "foo" to "more" and new styleID="b"

"foo" will be split:
<span styleID="a">f</span><span styleID="b">oo</span>...

During operation, normalize will merge "bar" into "oo":
span styleID="a">f</span><span styleID="b">oobar</span>

------
Because the code is iterating over "targets" the "bar" span is still in the list even though it is no longer part of the Text Flow. The solution to this is to check to see if the current target has no parent, indicating that a merge has happened, and in that case skip it. Adding the following code while performing "for each (target in targetList)" of the SimpleEditorPanel to read:

if(target.parent == null)
{
absStart += target.textLength;
continue;
}

No exceptions are thrown and the sample behaves as expected. This code has been updated in Adobe's source and will be posted when made available to the public.

It is important to note that collecting targets prior to execution of an operation can lead to the target becoming invalid. Client code which "pre-determines" targets prior to operating on them, should re-validate them during a looping operation. Alternatively, a client could loop based on text indexes and collect each target individually rather than assembling a list ahead of time.

1 reply

Adobe Employee
March 5, 2009
Thanks for the report. I'll look into it.
longlostbigelowCorrect answer
Participating Frequently
March 17, 2009
I'm not seeing a reference to an original bug, which the post on 11/23 implies, but in looking at the SimpleEditorWithCSS sample, the issue is with how the operation collects and iterates over the elements having the style applied. Because the example sited is using the same style name as that applied to the second element, a series of merges occur which renders the second element invalid.

Initial State:
<span styleID="a">foo</span><span styleID="b">bar</span><span>moreFooBar</span>
Selection from "oo" of "foo" to "more" and new styleID="b"

"foo" will be split:
<span styleID="a">f</span><span styleID="b">oo</span>...

During operation, normalize will merge "bar" into "oo":
span styleID="a">f</span><span styleID="b">oobar</span>

------
Because the code is iterating over "targets" the "bar" span is still in the list even though it is no longer part of the Text Flow. The solution to this is to check to see if the current target has no parent, indicating that a merge has happened, and in that case skip it. Adding the following code while performing "for each (target in targetList)" of the SimpleEditorPanel to read:

if(target.parent == null)
{
absStart += target.textLength;
continue;
}

No exceptions are thrown and the sample behaves as expected. This code has been updated in Adobe's source and will be posted when made available to the public.

It is important to note that collecting targets prior to execution of an operation can lead to the target becoming invalid. Client code which "pre-determines" targets prior to operating on them, should re-validate them during a looping operation. Alternatively, a client could loop based on text indexes and collect each target individually rather than assembling a list ahead of time.