-
Notifications
You must be signed in to change notification settings - Fork 127
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
KeyPress Event #100
Comments
So, I have been able to find out how to attach a key press handler after playing around much more! But the I am now having an issue where when I press the enter key, the handler doesn't trigger. I would like to add a custom handler when the users presses the enter key while typing. Here is my component <tiptap-vuetify
v-model="message"
:extensions="extensions"
placeholder="Message..."
:card-props="{ flat: true }"
:editor-properties="{
editorProps:{
handleKeyDown: (view, event) => {
this.handleKey(event)
this.handleKey(view)
if (event.key === 'Enter') {
// do something
return true
}
return false
}
}
}"
/>
Is this the correct way of adding a custom handler for when a users presses the Enter key, or is there a better way? |
This is the only way to track a keypress event. After your message, I have plans to simplify this, to use Vue's events on the component, e.g: <tiptap-vuetify
v-model="message"
:extensions="extensions"
@keydown="keydownHandler"
@keypress="keypressHandler"
/> Glad you found the answer, I wanted to write you an hour ago, I knew the answer, but I was a little busy. |
I spent time searching and found how to do it in tiptap. Here's how it works through my package: import { Extension } from 'tiptap' Add your extension to data: () => ({
extensions: [],
nativeExtensions: [
new class extends Extension {
keys () {
return {
Enter (state, dispatch, view) {
console.log('Enter!')
// return true prevents default behaviour
return true
}
}
}
}()
],
content: 'test'
}), Use <tiptap-vuetify
v-model="content"
:native-extensions="nativeExtensions"
:extensions="extensions"
/> Such a difficult decision only with the Enter, I don’t know why. I'm sorry if you spent a lot of time finding a solution. I am happy to help you if you have a problem. |
Called when the editor receives a keydown event. re #100
I released a new version By the way, please write down if everything works, please. |
No worries at all and I have successfully implemented your suggestion and it works as designed! Thank you very much! Now I can use your amazing editor for creating messages! 😃 |
I spoke a little too soon haha. I have a method that resides in the main component that I would like to call when the user presses enter (from within the new class extends Extension {
keys() {
return {
Enter(state, dispatch, view) {
this.sendMessage();
return true
}
}
}
} The |
Enter: (state, dispatch, view) => {
this.sendMessage();
return true
} |
I was able to play around with it deeper and got it to work correctly after your massive hint! Thank you for that!!!! I made a new JS file that held my custom extension in it to handle the Enter key press. I imported that into the component that I was using and instanciated a new instance of the extension class in the nativeExtensions data element. From there I passed a reference to the desired class in the component as an option to the extension. Componentimport SendMessage from './sendMessage'
export default {
data() {
return {
nativeExtensions: [
new SendMessage({
sendMessage: () => this.sendMessage()
}
]
}
},
methods: {
sendMessage() {...}
}
} Extension Classimport { Extension } from 'tiptap'
export default class SendMessage extends Extension {
keys() {
return {
Enter: (state, dispatch, view) => {
this.options.sendMessage();
return true
}
}
}
} Thanks again for all of the help and speedy replies!!!! 😃 |
Hey @iliyaZelenko , is the above mentioned @keydown method working, or do i need to use :nativeExtension for getting keydown events? Seems like it is working for all keypress, except "enter". |
I was wondering how I can attach a custom key press event? I've tried looking over the docs and wasn't able to find anything. I tried looking at the issues and nothing similar was asked.
The text was updated successfully, but these errors were encountered: