Skip to content

Commit 35405d2

Browse files
committed
add option to disable the holding key
1 parent 0001e50 commit 35405d2

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can check a demonstration of this plugin [here](##). [SOON]
2323
| Option | Description | Default |
2424
|-|-|-
2525
| `longPressKey` | The key you can hold to open the dialog. | `shift` |
26-
| `longPressDuration` | The minimum hold time of the ``longPressKey`` (in milliseconds). | `800`
26+
| `longPressDuration` | The minimum hold time of the ``longPressKey`` (in milliseconds). Set to `0` to deactivate. | `800`
2727
| `shortcut` | The (optional) shortcut that can open/close the dialog. | `shift+k`
2828
| `css` | The (optional) CSS of the dialog in case you wish to customize it. | `null`
2929

src/KeymapsDialog.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class KeymapsDialog {
180180
<style>${this.renderCSS()}</style>
181181
<div id="keymaps-dialog" class="${this.isOpen ? 'open' : ''}">
182182
<header>
183-
<h3>Keyboard Shortcuts (hold ${titleCase(this.options.longPressKey)} to show)</h3>
183+
<h3>Keyboard Shortcuts ${this.options.longPressDuration && this.options.longPressKey ? html`(hold ${titleCase(this.options.longPressKey)} to show)` : ''}</h3>
184184
</header>
185185
<main>
186186
${reg && Object.keys(reg).map(category => html`

src/index.ts

+21-19
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,29 @@ export default (editor: Editor, opts = {}): void => {
4242
})
4343
}
4444

45-
let longPressTimeout: NodeJS.Timeout | undefined = undefined
45+
if (options.longPressDuration && options.longPressKey) {
46+
let longPressTimeout: NodeJS.Timeout | undefined = undefined
4647

47-
document.addEventListener('keydown', event => {
48-
// Handle long press of the longPressKey
49-
if (event.key.toLowerCase() === options.longPressKey) {
50-
if (!longPressTimeout) {
51-
longPressTimeout = setTimeout(() => {
52-
editor.runCommand(cmdKeymapsDialog)
53-
}, options.longPressDuration)
48+
document.addEventListener('keydown', event => {
49+
// Handle long press of the longPressKey
50+
if (event.key.toLowerCase() === options.longPressKey) {
51+
if (!longPressTimeout) {
52+
longPressTimeout = setTimeout(() => {
53+
editor.runCommand(cmdKeymapsDialog)
54+
}, options.longPressDuration)
55+
}
5456
}
55-
}
56-
})
57+
})
5758

58-
document.addEventListener('keyup', event => {
59-
// Clear the long press timeout if the key is released (and close the dialog)
60-
if (event.key.toLowerCase() === options.longPressKey && !isShortcutActive) {
61-
if (longPressTimeout) {
62-
clearTimeout(longPressTimeout)
63-
longPressTimeout = undefined
59+
document.addEventListener('keyup', event => {
60+
// Clear the long press timeout if the key is released (and close the dialog)
61+
if (event.key.toLowerCase() === options.longPressKey && !isShortcutActive) {
62+
if (longPressTimeout) {
63+
clearTimeout(longPressTimeout)
64+
longPressTimeout = undefined
65+
}
66+
editor.stopCommand(cmdKeymapsDialog)
6467
}
65-
editor.stopCommand(cmdKeymapsDialog)
66-
}
67-
})
68+
})
69+
}
6870
}

0 commit comments

Comments
 (0)