mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: handle ESC key press to cancel the NotePropertiesDialog (#1125)
* Electron: enable ESC key press to dismiss NotePropertyDialog, when no editedKey. * Desktop: handle ESC key press to cancel the NotePropertiesDialog
This commit is contained in:
parent
0c98573700
commit
739fb2c3d2
@ -16,6 +16,8 @@ class NotePropertiesDialog extends React.Component {
|
||||
|
||||
this.okButton_click = this.okButton_click.bind(this);
|
||||
this.cancelButton_click = this.cancelButton_click.bind(this);
|
||||
this.onKeyDown = this.onKeyDown.bind(this);
|
||||
this.okButton = React.createRef();
|
||||
|
||||
this.state = {
|
||||
formNote: null,
|
||||
@ -43,6 +45,12 @@ class NotePropertiesDialog extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
if (this.state.editedKey == null) {
|
||||
this.okButton.current.focus();
|
||||
}
|
||||
}
|
||||
|
||||
async loadNote(noteId) {
|
||||
if (!noteId) {
|
||||
this.setState({ formNote: null });
|
||||
@ -184,6 +192,14 @@ class NotePropertiesDialog extends React.Component {
|
||||
this.closeDialog(false);
|
||||
}
|
||||
|
||||
onKeyDown(event) {
|
||||
if (event.keyCode === 13) {
|
||||
this.closeDialog(true);
|
||||
} else if (event.keyCode === 27) {
|
||||
this.closeDialog(false);
|
||||
}
|
||||
}
|
||||
|
||||
editPropertyButtonClick(key, initialValue) {
|
||||
this.setState({
|
||||
editedKey: key,
|
||||
@ -222,6 +238,7 @@ class NotePropertiesDialog extends React.Component {
|
||||
|
||||
async cancelProperty() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.okButton.current.focus();
|
||||
this.setState({
|
||||
editedKey: null,
|
||||
editedValue: null
|
||||
@ -347,7 +364,17 @@ class NotePropertiesDialog extends React.Component {
|
||||
const formNote = this.state.formNote;
|
||||
|
||||
const buttonComps = [];
|
||||
buttonComps.push(<button key="ok" style={styles.button} onClick={this.okButton_click}>{_('Apply')}</button>);
|
||||
buttonComps.push(
|
||||
<button
|
||||
key="ok"
|
||||
style={styles.button}
|
||||
onClick={this.okButton_click}
|
||||
ref={this.okButton}
|
||||
onKeyDown={this.onKeyDown}
|
||||
>
|
||||
{_('Apply')}
|
||||
</button>
|
||||
);
|
||||
buttonComps.push(<button key="cancel" style={styles.button} onClick={this.cancelButton_click}>{_('Cancel')}</button>);
|
||||
|
||||
const noteComps = [];
|
||||
|
Loading…
Reference in New Issue
Block a user