yuku / textcomplete

Autocomplete for HTMLTextAreaElement and more.
https://yuku.takahashi.coffee/textcomplete/
MIT License
1.74k stars 303 forks source link

manually fire select? #289

Closed unhammer closed 4 years ago

unhammer commented 8 years ago

How can I manually fire select on the active drop-down? I'm considering using this with https://quilljs.com/ which of course defines its own handlers for tab in list-indentation contexts etc.; and I'd like to define a tab-handler that does completion iff there's a drop-down, otherwise runs through the other handlers.

unhammer commented 7 years ago

It seems I don't need to trigger it myself, as long as I can override Quill's other tab-handlers:

  quill.keyboard.addBinding(
    {
      key: 9
    },
    function(_range, _context) {
      // Run the other handlers iff no dropdown:
      return $('.textcomplete-dropdown').filter(":visible").length === 0;
    }
  );
  // Give it priority over the other handlers:
  quill.keyboard.bindings[9].unshift(quill.keyboard.bindings[9].pop())

This works for my case (though I still feel like it should be possible to trigger the select from code).

nunesbeto commented 7 years ago

Thanks a lot @unhammer! It worked for me.