add find next and find previous commands to nav

This commit is contained in:
Cassie Tarakajian 2017-09-14 16:58:59 -04:00
parent 7f206122a2
commit 34cf86326b
2 changed files with 42 additions and 6 deletions

View file

@ -219,6 +219,26 @@ class Nav extends React.PureComponent {
<span className="nav__keyboard-shortcut">{metaKeyName}+F</span> <span className="nav__keyboard-shortcut">{metaKeyName}+F</span>
</button> </button>
</li> </li>
<li className="nav__dropdown-item">
<button
onClick={() => this.props.cmController.findNext()}
onFocus={this.handleFocus.bind(this, 'edit')}
onBlur={this.handleBlur}
>
Find Next
<span className="nav__keyboard-shortcut">{metaKeyName}+G</span>
</button>
</li>
<li className="nav__dropdown-item">
<button
onClick={() => this.props.cmController.findPrev()}
onFocus={this.handleFocus.bind(this, 'edit')}
onBlur={this.handleBlur}
>
Find Previous
<span className="nav__keyboard-shortcut">{'\u21E7'}+{metaKeyName}+G</span>
</button>
</li>
</ul> </ul>
</li> </li>
{/* {/*
@ -395,7 +415,9 @@ Nav.propTypes = {
showKeyboardShortcutModal: PropTypes.func.isRequired, showKeyboardShortcutModal: PropTypes.func.isRequired,
cmController: PropTypes.shape({ cmController: PropTypes.shape({
tidyCode: PropTypes.func, tidyCode: PropTypes.func,
showFind: PropTypes.func showFind: PropTypes.func,
findNext: PropTypes.func,
findPrev: PropTypes.func
}) })
}; };

View file

@ -49,6 +49,8 @@ class Editor extends React.Component {
super(props); super(props);
this.tidyCode = this.tidyCode.bind(this); this.tidyCode = this.tidyCode.bind(this);
this.showFind = this.showFind.bind(this); this.showFind = this.showFind.bind(this);
this.findNext = this.findNext.bind(this);
this.findPrev = this.findPrev.bind(this);
} }
componentDidMount() { componentDidMount() {
this.beep = new Audio(beepUrl); this.beep = new Audio(beepUrl);
@ -122,7 +124,9 @@ class Editor extends React.Component {
this.props.provideController({ this.props.provideController({
tidyCode: this.tidyCode, tidyCode: this.tidyCode,
showFind: this.showFind showFind: this.showFind,
findNext: this.findNext,
findPrev: this.findPrev
}); });
} }
@ -208,7 +212,17 @@ class Editor extends React.Component {
} }
showFind() { showFind() {
this._cm.execCommand('find'); this._cm.execCommand('findPersistent');
}
findNext() {
this._cm.focus();
this._cm.execCommand('findNext');
}
findPrev() {
this._cm.focus();
this._cm.execCommand('findPrev');
} }
toggleEditorOptions() { toggleEditorOptions() {