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

About recording key down event. #582

Open
Rexime opened this issue Sep 25, 2023 · 7 comments
Open

About recording key down event. #582

Rexime opened this issue Sep 25, 2023 · 7 comments

Comments

@Rexime
Copy link

Rexime commented Sep 25, 2023

Is there any way to record every key-down event when using the editor in my webapp?

@jaywcjlove
Copy link
Member

@Rexime https://uiwjs.github.io/react-codemirror/#/extensions/events

import CodeMirror from '@uiw/react-codemirror';
import { events } from '@uiw/codemirror-extensions-events';

function App() {
  const [scrollTop, setScrollTop] = useState(0);

  const eventExt = events.scroll({
    scroll: (evn) => {
      setScrollTop(evn.target.scrollTop);
    },
  });

  const eventExt2 = events.content({
    focus: (evn) => {
      console.log('focus');
    },
    blur: (evn) => {
      console.log('blur');
    },
  });

  return <CodeMirror value="console.log('hello world!');" height="200px" extensions={[eventExt, eventExt2]} />;
}
export default App;

@Rexime
Copy link
Author

Rexime commented Sep 26, 2023

Thanks a lot!!

@Rexime
Copy link
Author

Rexime commented Sep 26, 2023

@jaywcjlove I wanted to save every key code event, but I did not know how to do it. The example you provided was not for that purpose. Is there any example of that? Thank you so much!

@jaywcjlove
Copy link
Member

@Rexime I'm not sure what you need

/** Fired whenever a change occurs to the document. */
onChange?(value: string, viewUpdate: ViewUpdate): void;

@Rexime
Copy link
Author

Rexime commented Sep 26, 2023

@jaywcjlove I need to collect this kind of info https://www.toptal.com/developers/keycode. Like everytime I press a key, it will be recorded. I'm not sure if it's possible for the codemirror.

@jaywcjlove
Copy link
Member

@Rexime

  const eventExt2 = events.content({
    keydown: (evn) => {
      console.log('keydown');
    },
  });

@Rexime
Copy link
Author

Rexime commented Sep 26, 2023

@jaywcjlove Thank you soooo much!!!! You really made my day!

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