Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape does not close the autocomplete #322

Open
laurentsenta opened this issue Jun 17, 2020 · 4 comments
Open

Escape does not close the autocomplete #322

laurentsenta opened this issue Jun 17, 2020 · 4 comments
Labels
bug @textcomplete/core Issues associated to @textcomplete/core

Comments

@laurentsenta
Copy link

I get this behavior in my code and on the demo page:
https://yuku.takahashi.coffee/textcomplete/

  • type :s or something so that the autocomplete dropdown shows up,
  • press "escape,"
  • I expect the autocomplete to disappear; it does not.
@laurentsenta
Copy link
Author

laurentsenta commented Jun 17, 2020

I'd be happy to contribute if you need a hand,

Could you give me some context?
It looks like the code is designed to handle escape, so this looks like a bug rather than a new feature.

https://github.com/yuku/textcomplete/blob/main/packages/textcomplete-core/src/Textcomplete.ts#L96-L101

@yuku yuku added @textcomplete/core Issues associated to @textcomplete/core bug labels Jun 18, 2020
@yuku
Copy link
Owner

yuku commented Jun 18, 2020

Thanks for opening the issue. When a user press "escape",

  1. TextareaEditor.prototype.onKeydown event handler is executed.
  2. The editor emits "esc" event by calling emitEscEvent at L98
  3. Textcomplete.prototype.handleEsc is executed. And call customEvent.preventDefault() if the dropdown is shown.
  4. Finally, the mouseEvent.preventDefault() is called at L100-L102.

@hamza-mostafa
Copy link

@laurentsenta @yuku Hello guys,
I cannot reproduce this, nor find a PR, has this been fixed in another PR?
@laurentsenta would you please share the browser and version you are using?

@renaldas-kerpe-arria
Copy link

renaldas-kerpe-arria commented Nov 26, 2020

Here's how you can fix this locally:

class CodeMirrorEditor2 extends CodeMirrorEditor {
  constructor(cm: CodeMirror.Editor) {
    super(cm);

    (this as any).stopListening();
    (this as any).onKeyup = (_cm: CodeMirror.Editor, e: KeyboardEvent) => {
      const code = this.getCode(e);
      if (code !== 'DOWN' && code !== 'UP' && code !== 'ESC') {
        this.emitChangeEvent();
      }
    };
    (this as any).startListening();
  }
}

FYI this issue only happens with CodeMirror editor, which assumes that all the keys, except 'DOWN' and 'UP' should trigger a change event, which in turn re-opens the dropdown. I have added a third exclusion for the 'ESC' key in the above code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug @textcomplete/core Issues associated to @textcomplete/core
Projects
None yet
Development

No branches or pull requests

4 participants