Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9bb1cd1 authored by Gilles Debunne's avatar Gilles Debunne
Browse files

resolved conflicts for merge of fb729202 to master

Change-Id: Ic571594b14f2822094d5c1aa4c4b1e9da4a2eae0
parents e98ae0a0 fb729202
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -272,9 +272,11 @@ public class SpellChecker implements SpellCheckerSessionListener {
                            ((attributes & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) > 0);
                            ((attributes & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) > 0);


                    SpellCheckSpan spellCheckSpan = mSpellCheckSpans[j];
                    SpellCheckSpan spellCheckSpan = mSpellCheckSpans[j];

                    if (!isInDictionary && looksLikeTypo) {
                    if (!isInDictionary && looksLikeTypo) {
                        createMisspelledSuggestionSpan(editable, suggestionsInfo, spellCheckSpan);
                        createMisspelledSuggestionSpan(editable, suggestionsInfo, spellCheckSpan);
                    }
                    }

                    editable.removeSpan(spellCheckSpan);
                    editable.removeSpan(spellCheckSpan);
                    break;
                    break;
                }
                }
@@ -295,20 +297,21 @@ public class SpellChecker implements SpellCheckerSessionListener {
        }, SPELL_PAUSE_DURATION);
        }, SPELL_PAUSE_DURATION);
    }
    }


    private void createMisspelledSuggestionSpan(Editable editable,
    private void createMisspelledSuggestionSpan(Editable editable, SuggestionsInfo suggestionsInfo,
            SuggestionsInfo suggestionsInfo, SpellCheckSpan spellCheckSpan) {
            SpellCheckSpan spellCheckSpan) {
        final int start = editable.getSpanStart(spellCheckSpan);
        final int start = editable.getSpanStart(spellCheckSpan);
        final int end = editable.getSpanEnd(spellCheckSpan);
        final int end = editable.getSpanEnd(spellCheckSpan);
        if (start < 0 || end < 0) return; // span was removed in the meantime
        if (start < 0 || end <= start) return; // span was removed in the meantime


        // Other suggestion spans may exist on that region, with identical suggestions, filter
        // Other suggestion spans may exist on that region, with identical suggestions, filter
        // them out to avoid duplicates. First, filter suggestion spans on that exact region.
        // them out to avoid duplicates.
        SuggestionSpan[] suggestionSpans = editable.getSpans(start, end, SuggestionSpan.class);
        SuggestionSpan[] suggestionSpans = editable.getSpans(start, end, SuggestionSpan.class);
        final int length = suggestionSpans.length;
        final int length = suggestionSpans.length;
        for (int i = 0; i < length; i++) {
        for (int i = 0; i < length; i++) {
            final int spanStart = editable.getSpanStart(suggestionSpans[i]);
            final int spanStart = editable.getSpanStart(suggestionSpans[i]);
            final int spanEnd = editable.getSpanEnd(suggestionSpans[i]);
            final int spanEnd = editable.getSpanEnd(suggestionSpans[i]);
            if (spanStart != start || spanEnd != end) {
            if (spanStart != start || spanEnd != end) {
                // Nulled (to avoid new array allocation) if not on that exact same region
                suggestionSpans[i] = null;
                suggestionSpans[i] = null;
            }
            }
        }
        }
@@ -355,6 +358,8 @@ public class SpellChecker implements SpellCheckerSessionListener {
        SuggestionSpan suggestionSpan = new SuggestionSpan(mTextView.getContext(), suggestions,
        SuggestionSpan suggestionSpan = new SuggestionSpan(mTextView.getContext(), suggestions,
                SuggestionSpan.FLAG_EASY_CORRECT | SuggestionSpan.FLAG_MISSPELLED);
                SuggestionSpan.FLAG_EASY_CORRECT | SuggestionSpan.FLAG_MISSPELLED);
        editable.setSpan(suggestionSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        editable.setSpan(suggestionSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        mTextView.invalidateRegion(start, end);
    }
    }


    private class SpellParser {
    private class SpellParser {
+40 −33
Original line number Original line Diff line number Diff line
@@ -4326,15 +4326,24 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    }
    }


    private void invalidateCursor(int a, int b, int c) {
    private void invalidateCursor(int a, int b, int c) {
        if (a >= 0 || b >= 0 || c >= 0) {
            int start = Math.min(Math.min(a, b), c);
            int end = Math.max(Math.max(a, b), c);
            invalidateRegion(start, end);
        }
    }

    /**
     * Invalidates the region of text enclosed between the start and end text offsets.
     *
     * @hide
     */
    void invalidateRegion(int start, int end) {
        if (mLayout == null) {
        if (mLayout == null) {
            invalidate();
            invalidate();
        } else {
        } else {
            if (a >= 0 || b >= 0 || c >= 0) {
                int lineStart = mLayout.getLineForOffset(start);
                int first = Math.min(Math.min(a, b), c);
                int top = mLayout.getLineTop(lineStart);
                int last = Math.max(Math.max(a, b), c);

                int line = mLayout.getLineForOffset(first);
                int top = mLayout.getLineTop(line);


                // This is ridiculous, but the descent from the line above
                // This is ridiculous, but the descent from the line above
                // can hang down into the line we really want to redraw,
                // can hang down into the line we really want to redraw,
@@ -4342,36 +4351,36 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                // sure everything that needs to be redrawn really is.
                // sure everything that needs to be redrawn really is.
                // (But not the whole line above, because that would cause
                // (But not the whole line above, because that would cause
                // the same problem with the descenders on the line above it!)
                // the same problem with the descenders on the line above it!)
                if (line > 0) {
                if (lineStart > 0) {
                    top -= mLayout.getLineDescent(line - 1);
                    top -= mLayout.getLineDescent(lineStart - 1);
                }
                }


                int line2;
                int lineEnd;


                if (first == last)
                if (start == end)
                    line2 = line;
                    lineEnd = lineStart;
                else
                else
                    line2 = mLayout.getLineForOffset(last);
                    lineEnd = mLayout.getLineForOffset(end);


                int bottom = mLayout.getLineTop(line2 + 1);
                int bottom = mLayout.getLineBottom(lineEnd);


                final int horizontalPadding = getCompoundPaddingLeft();
                final int compoundPaddingLeft = getCompoundPaddingLeft();
                final int verticalPadding = getExtendedPaddingTop() + getVerticalOffset(true);
                final int verticalPadding = getExtendedPaddingTop() + getVerticalOffset(true);


                // If used, the cursor drawables can have an arbitrary dimension that can go beyond
                int left, right;
                // the invalidated lines specified above.
                if (lineStart == lineEnd) {
                for (int i = 0; i < mCursorCount; i++) {
                    left = (int) mLayout.getPrimaryHorizontal(start);
                    Rect bounds = mCursorDrawable[i].getBounds();
                    right = (int) (mLayout.getPrimaryHorizontal(end) + 1.0);
                    top = Math.min(top, bounds.top);
                    left += compoundPaddingLeft;
                    bottom = Math.max(bottom, bounds.bottom);
                    right += compoundPaddingLeft;
                    // Horizontal bounds are already full width, no need to update
                } else {
                    // Rectangle bounding box when the region spans several lines
                    left = compoundPaddingLeft;
                    right = getWidth() - getCompoundPaddingRight();
                }
                }


                invalidate(horizontalPadding + mScrollX, top + verticalPadding,
                invalidate(mScrollX + left, verticalPadding + top,
                        horizontalPadding + mScrollX + getWidth() -
                        mScrollX + right, verticalPadding + bottom);
                        getCompoundPaddingLeft() - getCompoundPaddingRight(),
                        bottom + verticalPadding);
            }
        }
        }
    }
    }


@@ -5904,10 +5913,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                if (cursorOffsetVertical != 0) {
                if (cursorOffsetVertical != 0) {
                    canvas.translate(0, -cursorOffsetVertical);
                    canvas.translate(0, -cursorOffsetVertical);
                }
                }
                invalidate(true);
                invalidate(true); // TODO invalidate cursor region only
            } else {
            } else {
                stopAnimation();
                stopAnimation();
                invalidate(false);
                invalidate(false); // TODO invalidate cursor region only
            }
            }
        }
        }


@@ -7730,9 +7739,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            }
            }
        }
        }


        if (what instanceof UpdateAppearance || what instanceof ParagraphStyle
        if (what instanceof UpdateAppearance || what instanceof ParagraphStyle) {
                || (what instanceof SuggestionSpan && (((SuggestionSpan)what).getFlags()
                        & SuggestionSpan.FLAG_AUTO_CORRECTION) != 0)) {
            if (ims == null || ims.mBatchEditNesting == 0) {
            if (ims == null || ims.mBatchEditNesting == 0) {
                invalidate();
                invalidate();
                mHighlightPathBogus = true;
                mHighlightPathBogus = true;