Skip to content

Commit

Permalink
Merge pull request #74 from github/event_prevent_deafult_apply
Browse files Browse the repository at this point in the history
Move preventDefault into apply functions
  • Loading branch information
keithamus authored Sep 22, 2023
2 parents ce94934 + d933491 commit 432d70d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function getButtons(toolbar: Element): HTMLElement[] {
function keydown(fn: (event: KeyboardEvent) => void): (event: KeyboardEvent) => void {
return function (event: KeyboardEvent) {
if (event.key === ' ' || event.key === 'Enter') {
event.preventDefault()
fn(event)
}
}
Expand Down Expand Up @@ -121,9 +120,10 @@ const manualStyles = {
class MarkdownButtonElement extends HTMLElement {
constructor() {
super()
const apply = () => {
const apply = (event: Event) => {
const style = styles.get(this)
if (!style) return
event.preventDefault()
applyStyle(this, style)
}
this.addEventListener('keydown', keydown(apply))
Expand Down Expand Up @@ -316,6 +316,7 @@ function applyFromToolbar(event: Event) {
const mdButtonStyle = target.getAttribute('data-md-button')
const style = manualStyles[mdButtonStyle as keyof typeof manualStyles]
if (!style) return
event.preventDefault()
applyStyle(target, style)
}

Expand Down

0 comments on commit 432d70d

Please sign in to comment.