mirror of https://github.com/laurent22/joplin.git
Desktop: Fixes #3700: Disable editor shortcuts when a dialog, such as GotoAnything, is visible
parent
7a4c97618d
commit
27c572b2f5
|
@ -99,6 +99,7 @@ const appDefaultState = Object.assign({}, defaultState, {
|
|||
watchedNoteFiles: [],
|
||||
lastEditorScrollPercents: {},
|
||||
devToolsVisible: false,
|
||||
visibleDialogs: {}, // empty object if no dialog is visible. Otherwise contains the list of visible dialogs.
|
||||
});
|
||||
|
||||
class Application extends BaseApplication {
|
||||
|
@ -280,6 +281,16 @@ class Application extends BaseApplication {
|
|||
newState.devToolsVisible = action.value;
|
||||
break;
|
||||
|
||||
case 'VISIBLE_DIALOGS_ADD':
|
||||
newState = Object.assign({}, state);
|
||||
newState.visibleDialogs[state.name] = true;
|
||||
break;
|
||||
|
||||
case 'VISIBLE_DIALOGS_REMOVE':
|
||||
newState = Object.assign({}, state);
|
||||
delete newState.visibleDialogs[state.name];
|
||||
break;
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
error.message = `In reducer: ${error.message} Action: ${JSON.stringify(action)}`;
|
||||
|
|
|
@ -224,7 +224,7 @@ class MainScreenComponent extends React.Component<any, any> {
|
|||
}) });
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps:any) {
|
||||
componentDidUpdate(prevProps:any, prevState:any) {
|
||||
if (this.props.noteListVisibility !== prevProps.noteListVisibility || this.props.sidebarVisibility !== prevProps.sidebarVisibility) {
|
||||
this.setState({ layout: produce(this.state.layout, (draftState:any) => {
|
||||
const noteListColumn = findItemByKey(draftState, 'noteListColumn');
|
||||
|
@ -238,6 +238,27 @@ class MainScreenComponent extends React.Component<any, any> {
|
|||
if (prevProps.style.width !== this.props.style.width || prevProps.style.height !== this.props.style.height) {
|
||||
this.updateRootLayoutSize();
|
||||
}
|
||||
|
||||
if (this.state.notePropertiesDialogOptions !== prevState.notePropertiesDialogOptions) {
|
||||
this.props.dispatch({
|
||||
type: this.state.notePropertiesDialogOptions && this.state.notePropertiesDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
||||
name: 'noteProperties',
|
||||
});
|
||||
}
|
||||
|
||||
if (this.state.noteContentPropertiesDialogOptions !== prevState.noteContentPropertiesDialogOptions) {
|
||||
this.props.dispatch({
|
||||
type: this.state.noteContentPropertiesDialogOptions && this.state.noteContentPropertiesDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
||||
name: 'noteContentProperties',
|
||||
});
|
||||
}
|
||||
|
||||
if (this.state.shareNoteDialogOptions !== prevState.shareNoteDialogOptions) {
|
||||
this.props.dispatch({
|
||||
type: this.state.shareNoteDialogOptions && this.state.shareNoteDialogOptions.visible ? 'VISIBLE_DIALOGS_ADD' : 'VISIBLE_DIALOGS_REMOVE',
|
||||
name: 'shareNote',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
|
|
@ -44,7 +44,7 @@ function editorCommandRuntime(declaration:CommandDeclaration, editorRef:any):Com
|
|||
}
|
||||
},
|
||||
isEnabled: (props:any) => {
|
||||
if (props.routeName !== 'Main') return false;
|
||||
if (props.routeName !== 'Main' || props.isDialogVisible) return false;
|
||||
if (props.markdownEditorViewerOnly) return false;
|
||||
if (!props.noteId) return false;
|
||||
const note = BaseModel.byId(props.notes, props.noteId);
|
||||
|
@ -60,6 +60,7 @@ function editorCommandRuntime(declaration:CommandDeclaration, editorRef:any):Com
|
|||
notes: state.notes,
|
||||
noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null,
|
||||
routeName: state.route.routeName,
|
||||
isDialogVisible: !!Object.keys(state.visibleDialogs).length,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -120,11 +120,21 @@ class Dialog extends React.PureComponent {
|
|||
|
||||
componentDidMount() {
|
||||
document.addEventListener('keydown', this.onKeyDown);
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'VISIBLE_DIALOGS_ADD',
|
||||
name: 'gotoAnything',
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.listUpdateIID_) clearTimeout(this.listUpdateIID_);
|
||||
document.removeEventListener('keydown', this.onKeyDown);
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'VISIBLE_DIALOGS_REMOVE',
|
||||
name: 'gotoAnything',
|
||||
});
|
||||
}
|
||||
|
||||
onKeyDown(event) {
|
||||
|
|
Loading…
Reference in New Issue