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

add onKeyup handler #111

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ You can interact with the CodeMirror instance using a `ref` and the `getCodeMirr
* `onCursorActivity` `Function (codemirror)` called when the cursor is moved
* `onFocusChange` `Function (focused)` called when the editor is focused or loses focus
* `onScroll` `Function (scrollInfo)` called when the editor is scrolled
* `onKeyup` `Function ()` called on handling of keyup event
* `preserveScrollPosition` `Boolean=false` preserve previous scroll position after updating value
* `value` `String` the editor value

Expand Down
5 changes: 5 additions & 0 deletions src/Codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const CodeMirror = createReactClass({
onCursorActivity: PropTypes.func,
onFocusChange: PropTypes.func,
onScroll: PropTypes.func,
onKeyup: PropTypes.func,
options: PropTypes.object,
path: PropTypes.string,
value: PropTypes.string,
Expand Down Expand Up @@ -54,6 +55,7 @@ const CodeMirror = createReactClass({
this.codeMirror.on('focus', this.focusChanged.bind(this, true));
this.codeMirror.on('blur', this.focusChanged.bind(this, false));
this.codeMirror.on('scroll', this.scrollChanged);
this.codeMirror.on('keyup', this.keyup.bind(this, true));
this.codeMirror.setValue(this.props.defaultValue || this.props.value || '');
},
componentWillUnmount () {
Expand Down Expand Up @@ -106,6 +108,9 @@ const CodeMirror = createReactClass({
scrollChanged (cm) {
this.props.onScroll && this.props.onScroll(cm.getScrollInfo());
},
keyup () {
this.props.onKeyup && this.props.onKeyup();
},
codemirrorValueChanged (doc, change) {
if (this.props.onChange && change.origin !== 'setValue') {
this.props.onChange(doc.getValue(), change);
Expand Down