diff --git a/lib/actions/sessions.ts b/lib/actions/sessions.ts index fa8ddc0b..356cfe13 100644 --- a/lib/actions/sessions.ts +++ b/lib/actions/sessions.ts @@ -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) => { const targetUid = uid || getState().sessions.activeUid!; - dispatch({ - type: SESSION_SEARCH_CLOSE, - uid: targetUid - }); + if (getState().sessions.sessions[targetUid]?.search) { + dispatch({ + type: SESSION_SEARCH_CLOSE, + uid: targetUid + }); + } else { + if (keyEvent) { + keyEvent.catched = false; + } + } }; } diff --git a/lib/actions/ui.ts b/lib/actions/ui.ts index 172a36f7..dd7ed58e 100644 --- a/lib/actions/ui.ts +++ b/lib/actions/ui.ts @@ -325,7 +325,7 @@ export function execCommand(command: string, fn: (...args: any[]) => void, e: an command, effect() { if (fn) { - fn(e); + fn(e, dispatch); } else { rpc.emit('command', command); } diff --git a/lib/command-registry.ts b/lib/command-registry.ts index 86d89cc4..4c8e827d 100644 --- a/lib/command-registry.ts +++ b/lib/command-registry.ts @@ -1,9 +1,15 @@ 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 const {getDecoratedKeymaps} = remote.require('./plugins'); -let commands: Record void> = {}; +let commands: Record void> = { + 'editor:search-close': (e, dispatch) => { + dispatch(closeSearch(undefined, e)); + } +}; export const getRegisteredKeys = () => { const keymaps = getDecoratedKeymaps();