Skip to content

Commit 1f58670

Browse files
committed
Ensure hotkeys are case sensitive
1 parent 58bba11 commit 1f58670

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ function findHotkey(toolbar: Element, key: string): HTMLElement | null {
389389

390390
function shortcut(toolbar: Element, event: KeyboardEvent) {
391391
if ((event.metaKey && modifierKey === 'Meta') || (event.ctrlKey && modifierKey === 'Control')) {
392-
const button = findHotkey(toolbar, event.key)
392+
const key = event.shiftKey ? event.key.toUpperCase() : event.key
393+
const button = findHotkey(toolbar, key)
393394
if (button) {
394395
button.click()
395396
event.preventDefault()

test/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ describe('markdown-toolbar-element', function () {
193193
})
194194
})
195195

196+
describe('hotkey case-sensitivity', function () {
197+
it('does not bold selected text when using the capitalized hotkey', function () {
198+
focus()
199+
setVisualValue('The |quick| brown fox jumps over the lazy dog')
200+
pressHotkey('B') // capital `B` instead of lowercase `b`
201+
assert.equal('The |quick| brown fox jumps over the lazy dog', visualValue())
202+
})
203+
})
204+
196205
describe('bold', function () {
197206
it('bold selected text when you click the bold icon', function () {
198207
setVisualValue('The |quick| brown fox jumps over the lazy dog')

0 commit comments

Comments
 (0)