0

I contribute to a text editor app and have observed the following behavior: When I add or remove a MetricAffectingSpan (have tested with LineHeightSpan and TextAppearanceSpan), the edit text jumps to the current cursor location.

The jump appears to be triggered by a call to bringPointIntoView() in onPreDraw(). Adding CharacterStyle spans such as ForegroundColorSpan or BackgroundColorSpan does not cause this behavior.

This behavior is undesirable. I would like to prevent the addition of spans from causing the scroll position to jump. An explanation of what is going on and possible ways to work around it would be very helpful.

hs1
  • 51
  • 1
  • 4

1 Answers1

0

My current solution is to just block the call to bringPointIntoView from onPreDraw

It's not pretty and probably not the best way to go about this. However, it seems to produce the desired behavior for me at this time


// In my derived class

    private boolean _blockBringPointIntoView = false;
    @Override
    public boolean onPreDraw() {
        _blockBringPointIntoView = true;
        try {
            return super.onPreDraw();
        } finally {
            _blockBringPointIntoView = false;
        }
    }

    @Override
    public boolean bringPointIntoView(int cursor) {
        if (!_blockBringPointIntoView) {
            return super.bringPointIntoView(cursor);
        } else {
            return false;
        }
    }
hs1
  • 51
  • 1
  • 4