Skip to content

how to do command enter and preventing enter from being sent to code editor? #144

Open

Description

@TheBuilderJR

tried this to no avail

        onKeyDown={(e) => {
          if (e.key == "Enter" && (e.ctrlKey || e.metaKey)) {
            onSubmit(e);
            return false;
          }
        }}

Activity

  1. jaywcjlove commented on Mar 5, 2023

    @jaywcjlove
    Member
  2. aleda145 commented on Mar 5, 2023

    @aleda145

    I was looking at this package, and got the same issue. Linked codesandbox doesn't work for me (using Firefox/Linux (Pop!))
    Enter events will still be sent and be added to the CodeEditor. The same onKeyDown eveent on a normal textarea works as expected though. So might be an issue with how onKeyDown is implemented on the CodeEditor?

  3. jaywcjlove commented on Mar 8, 2023

    @jaywcjlove
    Member

    onKeyDown: (evn) => {
    if (!other.onKeyDown || other.onKeyDown(evn) !== false) {
    shortcuts(evn);
    }
    },

    onKeyDown={(event) => {
    +  event.preventDefault();
      console.log(">>>>");
    +  return true
    }}

    @aleda145 Maybe it can solve your problem

  4. aleda145 commented on Mar 8, 2023

    @aleda145

    onKeyDown: (evn) => {
    if (!other.onKeyDown || other.onKeyDown(evn) !== false) {
    shortcuts(evn);
    }
    },

    onKeyDown={(event) => {
    +  event.preventDefault();
      console.log(">>>>");
    +  return true
    }}

    @aleda145 Maybe it can solve your problem

    It doesn't work :/, same problem. Also tried adding event.stopPropagation();, didn't help either. My enter event is still sent to the codeEditor, creating a new line.

    The following textArea works as expected for me

    <textarea
      onKeyDown={(event) => {
        event.preventDefault();
      }}
    ></textarea>

    Let me know if there anything you want from me to debug this!

    Great package, I still use it! ⭐

    I wanted it to run a SQL query on shift+Enter and not create a new line. But changed to ctrl+space instead, works just as well 😄 !

  5. emptycrown commented on Jun 3, 2023

    @emptycrown

    Running into the same issue -- the event cannot be stopped. Any update here?

  6. Haiqi-Wu commented on Jun 16, 2023

    @Haiqi-Wu

    Same issue.Any update?

  7. jaywcjlove commented on Jun 16, 2023

    @jaywcjlove
    Member

    onKeyDown: (evn) => {
    if (!other.onKeyDown || other.onKeyDown(evn) !== false) {
    shortcuts(evn);
    }
    },

    onKeyDown={(event) => {
    +  event.preventDefault();
      console.log(">>>>");
    +  return true
    }}

    @aleda145 Maybe it can solve your problem

    Maybe I don't understand what it means, haven't solved the problem yet?

    @emptycrown @Haiqi-Wu @aleda145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions