Skip to content

Commit

Permalink
Cleaned op order of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Aug 20, 2024
1 parent dd39531 commit a656226
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,25 @@ private boolean isScrollSignificant() {
Math.abs(_hlRect.bottom - _oldHlRect.bottom) > _hlShiftThreshold;
}

private boolean canHighlight() {
return _hlEnabled && _hl != null && getLayout() != null;
// The order of tests here is important
// - we want to run getLocalVisibleRect even if recompute is true
// - we want to run isScrollSignificant after getLocalVisibleRect
private boolean runHighlight(final boolean recompute) {
return _hlEnabled && _hl != null &&
(getLocalVisibleRect(_hlRect) || recompute) &&
(recompute || _hl.hasSpans()) &&
(recompute || isScrollSignificant());
}

private void updateHighlighting() {
if (canHighlight() && getLocalVisibleRect(_hlRect) && isScrollSignificant()) {
if (runHighlight(false)) {
_hl.clearDynamic().applyDynamic(hlRegion());
_oldHlRect.set(_hlRect);
}
}

private void recomputeHighlighting() {
if (canHighlight()) {
if (runHighlight(true)) {
_hl.clearAll().recompute().applyStatic().applyDynamic(hlRegion());
}
}
Expand All @@ -158,7 +164,7 @@ private void recomputeHighlighting() {
* 3. If the text did not change during computation, we apply the highlighting
*/
private void recomputeHighlightingAsync() {
if (canHighlight()) {
if (runHighlight(true)) {
executor.execute(this::_recomputeHighlightingWorker);
}
}
Expand Down

0 comments on commit a656226

Please sign in to comment.