summaryrefslogtreecommitdiff
path: root/core/java/android/text/DynamicLayout.java
diff options
context:
space:
mode:
authorSiyamed Sinir <siyamed@google.com>2017-12-18 18:47:37 -0800
committerSiyamed Sinir <siyamed@google.com>2017-12-18 23:32:50 -0800
commit50b585e20ce33aa795983ecc663cc444164479ce (patch)
treeddab99ce6de4cb9e535bbc1403688533cf54eb29 /core/java/android/text/DynamicLayout.java
parent866a3836aec17031459f0dc269ad8d37e9964a88 (diff)
Fix DynamicLayout block index calculation after edit
DynamicLayout made wrong adjustments to the block indices set to be redrawn. Every indice after the first change was being added the diff count in the blocks. However this meant when there are 2 deletes and an index as 1, it would become -1 (wrong array index). The change should be applied to indices outside of [firstBlock, lastBlock]. Test: Added android.text.DynamicLayoutTest#testReflow_afterSpannableEdit Test: bit FrameworksCoreTests:android.text.DynamicLayoutTest Test: bit FrameworksCoreTests:android.text.DynamicLayoutBlocksTest Test: bit CtsTextTestCases:android.text.cts.DynamicLayoutTest Bug: 67405337 Change-Id: Ie5e5658ffca4293f32f7b574d22d307e9e8d52dc
Diffstat (limited to 'core/java/android/text/DynamicLayout.java')
-rw-r--r--core/java/android/text/DynamicLayout.java26
1 files changed, 17 insertions, 9 deletions
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java
index fba358cf4c1b..71e039a1e0ef 100644
--- a/core/java/android/text/DynamicLayout.java
+++ b/core/java/android/text/DynamicLayout.java
@@ -492,7 +492,9 @@ public class DynamicLayout extends Layout
}
}
- private void reflow(CharSequence s, int where, int before, int after) {
+ /** @hide */
+ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+ public void reflow(CharSequence s, int where, int before, int after) {
if (s != mBase)
return;
@@ -805,8 +807,8 @@ public class DynamicLayout extends Layout
return;
}
- int firstBlock = -1;
- int lastBlock = -1;
+ /*final*/ int firstBlock = -1;
+ /*final*/ int lastBlock = -1;
for (int i = 0; i < mNumberOfBlocks; i++) {
if (mBlockEndLines[i] >= startLine) {
firstBlock = i;
@@ -821,10 +823,10 @@ public class DynamicLayout extends Layout
}
final int lastBlockEndLine = mBlockEndLines[lastBlock];
- boolean createBlockBefore = startLine > (firstBlock == 0 ? 0 :
+ final boolean createBlockBefore = startLine > (firstBlock == 0 ? 0 :
mBlockEndLines[firstBlock - 1] + 1);
- boolean createBlock = newLineCount > 0;
- boolean createBlockAfter = endLine < mBlockEndLines[lastBlock];
+ final boolean createBlock = newLineCount > 0;
+ final boolean createBlockAfter = endLine < mBlockEndLines[lastBlock];
int numAddedBlocks = 0;
if (createBlockBefore) numAddedBlocks++;
@@ -863,12 +865,18 @@ public class DynamicLayout extends Layout
if (numAddedBlocks + numRemovedBlocks != 0 && mBlocksAlwaysNeedToBeRedrawn != null) {
final ArraySet<Integer> set = new ArraySet<>();
+ final int changedBlockCount = numAddedBlocks - numRemovedBlocks;
for (int i = 0; i < mBlocksAlwaysNeedToBeRedrawn.size(); i++) {
Integer block = mBlocksAlwaysNeedToBeRedrawn.valueAt(i);
- if (block > firstBlock) {
- block += numAddedBlocks - numRemovedBlocks;
+ if (block < firstBlock) {
+ // block index is before firstBlock add it since it did not change
+ set.add(block);
+ }
+ if (block > lastBlock) {
+ // block index is after lastBlock, the index reduced to += changedBlockCount
+ block += changedBlockCount;
+ set.add(block);
}
- set.add(block);
}
mBlocksAlwaysNeedToBeRedrawn = set;
}