Cancel the delayed lookup when the query is cleared

What does this MR do and why?

With the delay option, lookUp schedules a timer for the lookup. When the query is then cleared, the timer still runs a lookup for the old query. In GitLab this throws Cannot read properties of null (reading 'text'). Feature specs log it as a browser console error.

This MR cancels the pending timer when catchQuery returns no query.

How to verify

The new spec in spec/javascripts/settings.spec.coffee types twice inside the delay, which schedules a timer. It then moves the caret so there is no query, and checks that the scheduled lookup does not run. Without the fix, _lookUp runs a second time.

Before After

The videos use a demo page with delay: 1000. The page types @j, then @jo within the delay, which schedules a lookup. It then clears the field before the delay ends. Before the fix, the scheduled lookup throws Cannot read properties of null (reading 'text'). After the fix, there is no error.

dist/js/jquery.atwho.js has the same one-line change by hand. dist/js/jquery.atwho.min.js is not rebuilt yet. It will come from the test-and-build job artifact.

References

Edited by Miguel Rincon

Merge request reports

Loading
Loading