textComplete.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. // We “inherit” the jquery-textcomplete plugin to integrate with our
  2. // EscapeActions system. You should always use `escapeableTextComplete` instead
  3. // of the vanilla `textcomplete`.
  4. let dropdownMenuIsOpened = false;
  5. $.fn.escapeableTextComplete = function(...args) {
  6. this.textcomplete(...args);
  7. // Since commit d474017 jquery-textComplete automatically closes a potential
  8. // opened dropdown menu when the user press Escape. This behavior conflicts
  9. // with our EscapeActions system, but it's too complicated and hacky to
  10. // monkey-pach textComplete to disable it -- I tried. Instead we listen to
  11. // 'open' and 'hide' events, and create a ghost escapeAction when the dropdown
  12. // is opened (and rely on textComplete to execute the actual action).
  13. this.on({
  14. 'textComplete:show'() {
  15. dropdownMenuIsOpened = true;
  16. },
  17. 'textComplete:hide'() {
  18. Tracker.afterFlush(() => {
  19. dropdownMenuIsOpened = false;
  20. });
  21. },
  22. });
  23. };
  24. EscapeActions.register('textcomplete',
  25. () => {},
  26. () => dropdownMenuIsOpened
  27. );