Skip to content

Commit

Permalink
reduce minify size
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed May 19, 2020
1 parent 4cf44dd commit df33039
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void
}

if (isFirefox) {
event.preventDefault()
preventDefault(event)
insert("\n" + newLinePadding)
} else {
// Normal browsers
if (newLinePadding.length > 0) {
event.preventDefault()
preventDefault(event)
insert("\n" + newLinePadding)
}
}
Expand All @@ -243,12 +243,12 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void
const codeAfter = afterCursor()
if (close.includes(event.key) && codeAfter.substr(0, 1) === event.key) {
const pos = save()
event.preventDefault()
preventDefault(event)
pos.start = ++pos.end
restore(pos)
} else if (open.includes(event.key)) {
const pos = save()
event.preventDefault()
preventDefault(event)
const text = event.key + close[open.indexOf(event.key)]
insert(text)
pos.start = ++pos.end
Expand All @@ -258,7 +258,7 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void

function handleTabCharacters(event: KeyboardEvent) {
if (event.key === "Tab") {
event.preventDefault()
preventDefault(event)
if (event.shiftKey) {
const before = beforeCursor()
let [padding, start,] = findPadding(before)
Expand All @@ -280,7 +280,7 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void

function handleJumpToBeginningOfLine(event: KeyboardEvent) {
if (event.key === "ArrowLeft" && event.metaKey) {
event.preventDefault()
preventDefault(event)
const before = beforeCursor()
let [padding, start, end] = findPadding(before)
if (before.endsWith(padding)) {
Expand All @@ -303,7 +303,7 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void

function handleUndoRedo(event: KeyboardEvent) {
if (isUndo(event)) {
event.preventDefault()
preventDefault(event)
at--
const record = history[at]
if (record) {
Expand All @@ -313,7 +313,7 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void
if (at < 0) at = 0
}
if (isRedo(event)) {
event.preventDefault()
preventDefault(event)
at++
const record = history[at]
if (record) {
Expand Down Expand Up @@ -349,7 +349,7 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void
}

function handlePaste(event: ClipboardEvent) {
event.preventDefault()
preventDefault(event)
const text = ((event as any).originalEvent || event).clipboardData.getData("text/plain")
const pos = save()
insert(text)
Expand Down Expand Up @@ -421,6 +421,10 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void
return editor.textContent || ""
}

function preventDefault(event: Event) {
event.preventDefault()
}

return {
updateOptions(options: Partial<Options>) {
options = {...options, ...options}
Expand Down

0 comments on commit df33039

Please sign in to comment.