add command handler to uncatch keyboard event if search is closed

This commit is contained in:
Labhansh Agrawal 2020-03-22 14:57:40 +05:30 committed by Benjamin Staneck
parent d046d6cf99
commit 73e45f51f0
3 changed files with 19 additions and 7 deletions

View file

@ -145,13 +145,19 @@ export function onSearch(uid?: string) {
}; };
} }
export function closeSearch(uid?: string) { export function closeSearch(uid?: string, keyEvent?: any) {
return (dispatch: HyperDispatch, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const targetUid = uid || getState().sessions.activeUid!; const targetUid = uid || getState().sessions.activeUid!;
dispatch({ if (getState().sessions.sessions[targetUid]?.search) {
type: SESSION_SEARCH_CLOSE, dispatch({
uid: targetUid type: SESSION_SEARCH_CLOSE,
}); uid: targetUid
});
} else {
if (keyEvent) {
keyEvent.catched = false;
}
}
}; };
} }

View file

@ -325,7 +325,7 @@ export function execCommand(command: string, fn: (...args: any[]) => void, e: an
command, command,
effect() { effect() {
if (fn) { if (fn) {
fn(e); fn(e, dispatch);
} else { } else {
rpc.emit('command', command); rpc.emit('command', command);
} }

View file

@ -1,9 +1,15 @@
import {remote} from 'electron'; import {remote} from 'electron';
import {HyperDispatch} from './hyper';
import {closeSearch} from './actions/sessions';
// TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 // TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31
const {getDecoratedKeymaps} = remote.require('./plugins'); const {getDecoratedKeymaps} = remote.require('./plugins');
let commands: Record<string, (...args: any[]) => void> = {}; let commands: Record<string, (event: any, dispatch: HyperDispatch) => void> = {
'editor:search-close': (e, dispatch) => {
dispatch(closeSearch(undefined, e));
}
};
export const getRegisteredKeys = () => { export const getRegisteredKeys = () => {
const keymaps = getDecoratedKeymaps(); const keymaps = getDecoratedKeymaps();