greena13 / react-hotkeys

Declarative hotkey and focus area management for React
https://github.com/greena13/react-hotkeys
ISC License
2.15k stars 160 forks source link

[BUG] Key combinations such as [ "d d" ] seem to store the 2nd "d" so next time you press "d" it first the ["d d"] combination #279

Open v-bbrady opened 4 years ago

v-bbrady commented 4 years ago

Describe the bug Hello, I have a number of required key combinations that use the same key twice. For example, ["d d"]. The first time I click "d d". It functions as expected. However when I hit "d" a single time after that it fires the ["d d"] combination. I believe it is storing the 2nd d somewhere so when a single "d" is pressed it fires the combination. Does anyone have any ideas on how to clear this memory? Or another solution.

`import { EditorCellType } from "../types"; import { CellType } from "@nteract/commutable"; import { ICellProps } from "./ConnectedCell";

/**

/**

function onKeySaveNotebook(e: KeyboardEvent, props: ICellProps) { e.preventDefault(); props.saveNotebook(); }

function onKeyToggleCellOutputVisibility(props: ICellProps) { props.toggleCellOutputVisibility(); }

function onKeyRestartKernel(props: ICellProps) { if (!props.settings.readOnly) { props.restartKernel(); } }

function onKeyDeleteCell(props: ICellProps) { props.deleteCell(); }

function onKeyInterruptKernel(props: ICellProps) { props.interruptKernel(); }

function onKeyChangeCellTypeToCode(props: ICellProps) { const cellType: CellType = props.settings.cellType; if (cellType !== EditorCellType.code) { props.changeCellType(EditorCellType.code); } }

function onKeyChangeCellTypeToMarkdown(props: ICellProps) { const cellType: CellType = props.settings.cellType; if (cellType !== EditorCellType.markdown) { props.changeCellType(EditorCellType.markdown); } }

function onKeyInsertCellBelow(props: any) { const cellType: CellType = props.cellType; const contentRef: string = props.contentRef; props.insertCellBelow(contentRef, cellType); }

function onKeyInsertCellAbove(props: any) { const cellType: CellType = props.cellType; const contentRef: string = props.contentRef; props.insertCellAbove(contentRef, cellType); }

function onKeyCopyCell(props: ICellProps) { props.copyCell(); }

function onKeyPasteCellBelow(props: ICellProps) { props.pasteCellBelow(); }

function onKeyCutCell(props: ICellProps) { props.cutCell(); }

function onKeyToggleOutputScrolling(props: ICellProps) { props.toggleOutputExpansion(); }

function onKeyFocusBelow(props: any) { props.focusBelowCell(); }

function onKeyFocusAbove(props: any) { props.focusAboveCell(); }

function onKeyExecuteCell(props: ICellProps) { // tslint:disable no-console console.log('rowboat'); props.executeCell(); }

function onKeyExecuteCellThenInsertCellBelow(props: any) { const cellType: CellType = props.cellType; const contentRef: string = props.contentRef; props.executeCell(); props.insertCellBelow(contentRef, cellType); }

function onKeyFocusEditor(props: ICellProps) { props.focusEditor(); } `

Expected behavior I am expecting the key combination to only fire when "d" and then "d" is pressed even after using "d d" once.

Platform (please complete the following information):

Harjot1Singh commented 4 years ago

Is this related to #255?