From 73e45f51f0836f2fd3ae85b6e81070ac2d148003 Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Sun, 22 Mar 2020 14:57:40 +0530 Subject: [PATCH] add command handler to uncatch keyboard event if search is closed --- lib/actions/sessions.ts | 16 +++++++++++----- lib/actions/ui.ts | 2 +- lib/command-registry.ts | 8 +++++++- 3 files changed, 19 insertions(+), 7 deletions(-) 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();