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

keydown Component events #58

Closed
J0ekr opened this issue May 20, 2019 · 2 comments
Closed

keydown Component events #58

J0ekr opened this issue May 20, 2019 · 2 comments
Labels
resolution:resolved This issue was already resolved (e.g. by another ticket). type:question

Comments

@J0ekr
Copy link

J0ekr commented May 20, 2019

Hey,
im trying to build a CKEditor application with Vue, where I want to save every single keystroke to a csv file.
Therefore I want to use the keydown event, but I can't get it to work.
Or are the only component events in vue the ones listed here?
https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/frameworks/vuejs.html#component-events
In my template I currently have:

<ckeditor :editor="editor" :value="editorData" :config="editorConfig" @ready="onEditorReady"
                      @input="onEditorInput" @keydown="onKeyDown"></ckeditor>
@Mgsy
Copy link
Member

Mgsy commented May 22, 2019

Hello, unfortunately you can use only component events which are presented in our documentation. However, you can listen to keydown event directly from the editing area and capture all keys.

To do that, let's prepare a simple plugin:

function CaptureKeys( editor ) {
    editor.editing.document.view.on( 'keydown', ( evt, data ) => {
        console.log( data );
        console.log( 'Pressed key: ' + data.domEvent.key );

        // Do something on keydown...
    }
} 

And include it to the editor config:

// ...
editorConfig: {
    plugins: [
            EssentialsPlugin,
            BoldPlugin,
            ItalicPlugin,
            LinkPlugin,
            ParagraphPlugin,
	    Font,
	    CaptureKeys
     ],
// ...

Now, just open the editor and all keys will be logged to the console:

image

@Mgsy Mgsy added pending:feedback This issue is blocked by necessary feedback. type:question labels May 22, 2019
@J0ekr
Copy link
Author

J0ekr commented May 22, 2019

Thank you this works.

I created a new javascript file CaptureKeys.js

export function CaptureKeys( editor ) {
    editor.editing.view.document.on( 'keydown', ( evt, data ) => {
        console.log( 'Pressed key: ' + data.domEvent.key );
        // Do something on keydown...
    })
}

and then importing import {CaptureKeys} from '../../CaptureKeys.js in my vue editor file.

I first got TypeError: Cannot read property 'getAttribute' of null
But could fix it by copying the vue.config.js from #55 (comment)

@J0ekr J0ekr closed this as completed May 22, 2019
@Mgsy Mgsy added resolution:solved and removed pending:feedback This issue is blocked by necessary feedback. labels May 22, 2019
@Reinmar Reinmar added resolution:resolved This issue was already resolved (e.g. by another ticket). and removed resolution:solved labels Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution:resolved This issue was already resolved (e.g. by another ticket). type:question
Projects
None yet
Development

No branches or pull requests

3 participants