Skip to content

Commit d4e6f15

Browse files
committed
Add shortcut for bullet lists, and new "requires shift" option
1 parent f6772c1 commit d4e6f15

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ class MarkdownUnorderedListButtonElement extends MarkdownButtonElement {
232232
super()
233233
styles.set(this, {prefix: '- ', multiline: true, surroundWithNewlines: true})
234234
}
235+
connectedCallback() {
236+
super.connectedCallback()
237+
this.setAttribute('hotkey', '8')
238+
this.setAttribute('hotkey-requires-shift', 'true')
239+
}
235240
}
236241

237242
if (!window.customElements.get('md-unordered-list')) {
@@ -387,10 +392,13 @@ function focusKeydown(event: KeyboardEvent) {
387392
}
388393

389394
const shortcutListeners = new WeakMap()
395+
function elementHotkeyRequiresShift(element: Element): boolean {
396+
return element.hasAttribute('hotkey-requires-shift') && element.getAttribute('hotkey-requires-shift') !== 'false'
397+
}
390398

391-
function findHotkey(toolbar: Element, key: string): HTMLElement | null {
399+
function findHotkey(toolbar: Element, key: string, shiftPressed: boolean): HTMLElement | null {
392400
for (const el of toolbar.querySelectorAll<HTMLElement>('[hotkey]')) {
393-
if (el.getAttribute('hotkey') === key) {
401+
if (el.getAttribute('hotkey') === key && (!elementHotkeyRequiresShift(el) || shiftPressed)) {
394402
return el
395403
}
396404
}
@@ -400,7 +408,7 @@ function findHotkey(toolbar: Element, key: string): HTMLElement | null {
400408
function shortcut(toolbar: Element, event: KeyboardEvent) {
401409
if ((event.metaKey && modifierKey === 'Meta') || (event.ctrlKey && modifierKey === 'Control')) {
402410
const key = event.shiftKey ? event.key.toUpperCase() : event.key
403-
const button = findHotkey(toolbar, key)
411+
const button = findHotkey(toolbar, key, event.shiftKey)
404412
if (button) {
405413
button.click()
406414
event.preventDefault()

0 commit comments

Comments
 (0)