Prevent crash

This commit is contained in:
M66B 2024-05-23 14:00:23 +02:00
parent a47cda9a42
commit 04730c7d1a
1 changed files with 31 additions and 2 deletions

View File

@ -1769,8 +1769,37 @@ public class StyleHelper {
static void markAsInserted(Editable text, int start, int end) {
for (InsertedSpan span : text.getSpans(0, text.length(), InsertedSpan.class))
text.removeSpan(span);
if (start >= 0 && start < end && end <= text.length())
text.setSpan(new InsertedSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (start >= 0 && start < end && end <= text.length()) {
/*
java.lang.IndexOutOfBoundsException: Invalid Context Range: 0, 1 must be in 0, 0
at android.graphics.Paint.getRunCharacterAdvance(Paint.java:3541)
at android.text.TextLine.getRunAdvance(TextLine.java:1274)
at android.text.TextLine.handleText(TextLine.java:1361)
at android.text.TextLine.handleRun(TextLine.java:1640)
at android.text.TextLine.measureRun(TextLine.java:882)
at android.text.TextLine.measure(TextLine.java:604)
at android.text.TextLine.metrics(TextLine.java:494)
at android.text.Layout.getLineExtent(Layout.java:1896)
at android.text.Layout.getLineMax(Layout.java:1843)
at android.text.Layout.getLineRight(Layout.java:1833)
at android.widget.TextView.getCursorAnchorInfo(TextView.java:14517)
at android.widget.Editor$CursorAnchorInfoNotifier.updatePosition(Editor.java:4883)
at android.widget.Editor$PositionListener.onPreDraw(Editor.java:3750)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1176)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4158)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2836)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10145)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1406)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415)
at android.view.Choreographer.doCallbacks(Choreographer.java:1015)
at android.view.Choreographer.doFrame(Choreographer.java:945)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389)
at android.os.Handler.handleCallback(Handler.java:959)
*/
Pair<Integer, Integer> range = ensureParagraph(text, start, end);
if (range != null)
text.setSpan(new InsertedSpan(), range.first, range.second, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
static class InsertedSpan implements NoCopySpan {