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

unable to hook plugin to 'enter' key #207

Closed
xerosanyam opened this issue Feb 20, 2019 · 2 comments
Closed

unable to hook plugin to 'enter' key #207

xerosanyam opened this issue Feb 20, 2019 · 2 comments

Comments

@xerosanyam
Copy link

I am unable to use enter key in keymap

    this.editor.registerPlugin(keymap({
      'Enter': printSomething
    }))

this doesn't work in tiptap, but something similar works in prosemirror
Help

@xerosanyam
Copy link
Author

it was added use basekeymap in tiptap/Editor.js
overrode it for my usecase

@Chrissi2812
Copy link
Contributor

You could also register a custom plugin.

import { Editor, EditorContent, EditorMenuBar, Extension } from 'tiptap'

new Editor({
  extensions: [
    new class extends Extension {
      keys() {
        return {
          Enter(state, dispatch, view) {
            // return true prevents default behaviour
            return true
          },
        }
      }
    }(),
  ],
  content: '',
});

jcmorrow added a commit to replayio/devtools that referenced this issue Oct 15, 2021
Changes
---

There are a lot of changes! Replacing just draft.js was not too
difficult but it involved a couple of larger changes:

- Store and render comments at JSON. We're currently storing comments as
  markdown. The tiptap docs have [quite a bit to say about
  that](https://tiptap.dev/guide/output#not-an-option-markdown). The
  TL;DR is that tiptap will only output in JSON or HTML. JSON makes much
  more sense to me, since it's easier to do parsing/traversing and
  validation. Hopefully, we'll never have to manually do that, but if we
  ever *did*, I would much rather do it over JSON than HTML.
- Because we are now storing and displaying comments as JSON, we
  *always* render comments in the editor, even if they are not currently
  editable. This involves swapping around quite a lot of stuff inside of
  Transcript, but I think overall it's gotten easier to read/manage.

Other Changes
---

- Our types for comments are super interesting. I've changed things up a
  bit, pulling out an interface that Reply and Comment have in common,
  which I've called `Remark`. It's not used that often, but it's nice to
  have a shorthand.
- `PendingComment` and `PendingReply` are now just type aliases to
  `Partial<Comment>` and `Partial<Reply>`. I think this makes sense? So
  all fields are valid, but all of them also might not be there.
- Sort comments first by their video time, but then by the time they
  were created. When you have multiple comments at the same pause,
  replying to them can cause their order to change in the UI. This is a
  bit of an edge case but adding a stable tie-break to the sort avoids
  it.
- Add `tiptap` and some extensions. I have not added mention support
  completely, although I did POC it locally and it was good, though
  needed some design help.
- Remove all `Draft.js` code.
- Try to reduce the complexity in `Transcript` rendering. I am 95% sure that I could have taken this further, but this has been a quagmire of a change for two tricky reasons which I'll mention below, so I'm leaving this for another time.

Places I Got Stuck
---
- This is a silly one, but it was really hard to get `tiptap` to submit
  on hitting `Enter`. The docs about [overriding
  shortcuts](https://tiptap.dev/guide/output#not-an-option-markdown) did
  not work at all for me, nor did the answer to this
  [issue](ueberdosis/tiptap#207) which has a
  bunch of thumbsups. This makes me think that something changed in
  tiptap recently, because I had to do this:

```
Extension.create({
  name: "myCustomPlugin",
  addKeyboardShortcuts() {
    return {
      Enter: ({ editor }) => {
        //override code goes here
        return true;
      },
    };
  },
}),
```

This is *similar* to the docs, and to that issue answer, but it's just a
*bit* different, and for some reason this works and the others did not
\*shrug\*.

- Apollo optimistic updates failed silently. I have still not totally
  traced down the cause of this, but I'm *fairly* sure that it was
  caused by the `update` entry of a mutation that was writing an object
  to the Apollo cache without correctly setting all of the required
  fields and `__typename`. Again, maybe with more time I could get a
  more satisfying explanation, but for now I would rather just get this
  out.

---

Closes https://github.com/RecordReplay/devtools/issues/3735
jcmorrow added a commit to replayio/devtools that referenced this issue Oct 15, 2021
Changes
---

There are a lot of changes! Replacing just draft.js was not too
difficult but it involved a couple of larger changes:

- Store and render comments at JSON. We're currently storing comments as
  markdown. The tiptap docs have [quite a bit to say about
  that](https://tiptap.dev/guide/output#not-an-option-markdown). The
  TL;DR is that tiptap will only output in JSON or HTML. JSON makes much
  more sense to me, since it's easier to do parsing/traversing and
  validation. Hopefully, we'll never have to manually do that, but if we
  ever *did*, I would much rather do it over JSON than HTML.
- Because we are now storing and displaying comments as JSON, we
  *always* render comments in the editor, even if they are not currently
  editable. This involves swapping around quite a lot of stuff inside of
  Transcript, but I think overall it's gotten easier to read/manage.

Other Changes
---

- Our types for comments are super interesting. I've changed things up a
  bit, pulling out an interface that Reply and Comment have in common,
  which I've called `Remark`. It's not used that often, but it's nice to
  have a shorthand.
- `PendingComment` and `PendingReply` are now just type aliases to
  `Partial<Comment>` and `Partial<Reply>`. I think this makes sense? So
  all fields are valid, but all of them also might not be there.
- Sort comments first by their video time, but then by the time they
  were created. When you have multiple comments at the same pause,
  replying to them can cause their order to change in the UI. This is a
  bit of an edge case but adding a stable tie-break to the sort avoids
  it.
- Add `tiptap` and some extensions. I have not added mention support
  completely, although I did POC it locally and it was good, though
  needed some design help.
- Remove all `Draft.js` code.
- Try to reduce the complexity in `Transcript` rendering. I am 95% sure that I could have taken this further, but this has been a quagmire of a change for two tricky reasons which I'll mention below, so I'm leaving this for another time.

Places I Got Stuck
---
- This is a silly one, but it was really hard to get `tiptap` to submit
  on hitting `Enter`. The docs about [overriding
  shortcuts](https://tiptap.dev/guide/output#not-an-option-markdown) did
  not work at all for me, nor did the answer to this
  [issue](ueberdosis/tiptap#207) which has a
  bunch of thumbsups. This makes me think that something changed in
  tiptap recently, because I had to do this:

```
Extension.create({
  name: "myCustomPlugin",
  addKeyboardShortcuts() {
    return {
      Enter: ({ editor }) => {
        //override code goes here
        return true;
      },
    };
  },
}),
```

This is *similar* to the docs, and to that issue answer, but it's just a
*bit* different, and for some reason this works and the others did not
\*shrug\*.

- Apollo optimistic updates failed silently. I have still not totally
  traced down the cause of this, but I'm *fairly* sure that it was
  caused by the `update` entry of a mutation that was writing an object
  to the Apollo cache without correctly setting all of the required
  fields and `__typename`. Again, maybe with more time I could get a
  more satisfying explanation, but for now I would rather just get this
  out.

---

Closes https://github.com/RecordReplay/devtools/issues/3735
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants