Fixed handling of span editing before TableElement
Project: http://git-wip-us.apache.org/repos/asf/flex-tlf/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-tlf/commit/3d51c48f Tree: http://git-wip-us.apache.org/repos/asf/flex-tlf/tree/3d51c48f Diff: http://git-wip-us.apache.org/repos/asf/flex-tlf/diff/3d51c48f Branch: refs/heads/develop Commit: 3d51c48f3b3a4851dcb0019a5270eea8dddc75bc Parents: a0a0749 Author: Harbs <ha...@in-tools.com> Authored: Mon Oct 6 11:58:25 2014 +0300 Committer: Harbs <ha...@in-tools.com> Committed: Mon Oct 6 11:58:25 2014 +0300 ---------------------------------------------------------------------- textLayout/src/flashx/textLayout/edit/ParaEdit.as | 11 +++++++++-- .../flashx/textLayout/elements/ParagraphElement.as | 16 ++++++++++++---- .../flashx/textLayout/elements/TableLeafElement.as | 5 +++++ 3 files changed, 26 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/3d51c48f/textLayout/src/flashx/textLayout/edit/ParaEdit.as ---------------------------------------------------------------------- diff --git a/textLayout/src/flashx/textLayout/edit/ParaEdit.as b/textLayout/src/flashx/textLayout/edit/ParaEdit.as index 09ee41b..4af7e23 100644 --- a/textLayout/src/flashx/textLayout/edit/ParaEdit.as +++ b/textLayout/src/flashx/textLayout/edit/ParaEdit.as @@ -30,11 +30,13 @@ package flashx.textLayout.edit import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.SubParagraphGroupElementBase; + import flashx.textLayout.elements.TableLeafElement; import flashx.textLayout.elements.TextFlow; import flashx.textLayout.formats.Float; import flashx.textLayout.formats.ITextLayoutFormat; import flashx.textLayout.formats.TextLayoutFormat; import flashx.textLayout.tlf_internal; + import flashx.textLayout.elements.TableElement; use namespace tlf_internal; @@ -69,10 +71,15 @@ package flashx.textLayout.edit { // If we're at the start a span, go to the previous span in the same paragraph, and insert at the end of it if (paraSelBegIdx == sibling.getElementRelativeStart(paragraph)) - sibling = FlowLeafElement(sibling).getPreviousLeaf(paragraph); - siblingIndex = sibling.parent.getChildIndex(sibling) + 1; + sibling = FlowLeafElement(sibling).getPreviousLeaf(paragraph); + if(sibling is TableLeafElement) + siblingIndex = sibling.parent.parent.getChildIndex(sibling.parent) + 1; + else + siblingIndex = sibling.parent.getChildIndex(sibling) + 1; } var insertParent:FlowGroupElement = sibling.parent; + if(insertParent is TableElement) + insertParent = insertParent.parent; // If we are adding text to the start or end of a link, it doesn't allow the insertion to group with the link. // So in that case, we will insert to the element beside the position that is *not* part of the link. http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/3d51c48f/textLayout/src/flashx/textLayout/elements/ParagraphElement.as ---------------------------------------------------------------------- diff --git a/textLayout/src/flashx/textLayout/elements/ParagraphElement.as b/textLayout/src/flashx/textLayout/elements/ParagraphElement.as index 1fec299..6527d7c 100644 --- a/textLayout/src/flashx/textLayout/elements/ParagraphElement.as +++ b/textLayout/src/flashx/textLayout/elements/ParagraphElement.as @@ -352,6 +352,8 @@ package flashx.textLayout.elements tlf_internal override function createContentAsGroup(pos:int=0):GroupElement { var tb:TextBlock = getTextBlockAtPosition(pos); + if(!tb) + tb = getTextBlockAtPosition(pos-1); var group:GroupElement = tb.content as GroupElement; if (!group) { @@ -467,14 +469,12 @@ package flashx.textLayout.elements { if(chldrn[i] is TableElement) { - if(chldrn[i].parentRelativeStart == pos) - return [chldrn[i]]; if(chldrn[i].parentRelativeStart < pos) { retVal.length = 0; continue; } - if(chldrn[i].parentRelativeStart > pos) + if(chldrn[i].parentRelativeStart >= pos) break; } retVal.push(chldrn[i]); @@ -487,7 +487,15 @@ package flashx.textLayout.elements { var relativeStart:int = child.getElementRelativeStart(this); var tb:TextBlock = getTextBlockAtPosition(relativeStart); - if (getTextBlocks().length == 0 || !tb) + if(!tb) + tb = getTextBlockAtPosition(relativeStart-1); + + if(!tb) + { + child.releaseContentElement(); + return; + } + if (getTextBlocks().length == 0) { child.releaseContentElement(); createTextBlock(); // does the whole tree http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/3d51c48f/textLayout/src/flashx/textLayout/elements/TableLeafElement.as ---------------------------------------------------------------------- diff --git a/textLayout/src/flashx/textLayout/elements/TableLeafElement.as b/textLayout/src/flashx/textLayout/elements/TableLeafElement.as index 44e62a4..0fdf629 100644 --- a/textLayout/src/flashx/textLayout/elements/TableLeafElement.as +++ b/textLayout/src/flashx/textLayout/elements/TableLeafElement.as @@ -115,6 +115,11 @@ package flashx.textLayout.elements { return _table.getParagraph(); } + + override public function getElementRelativeStart(ancestorElement:FlowElement):int + { + return _table.getElementRelativeStart(ancestorElement); + } } }