Skip to content

Commit

Permalink
Optimized closing characters. (#41)
Browse files Browse the repository at this point in the history
* Optimized closing characters.

* Escaping works only with ' and "

* Changed var to const
  • Loading branch information
PrestonHager authored Dec 7, 2020
1 parent e3842e5 commit a599705
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void
const open = `([{'"`
const close = `)]}'"`
const codeAfter = afterCursor()
if (close.includes(event.key) && codeAfter.substr(0, 1) === event.key) {
const codeBefore = beforeCursor()
const escapeCharacter = `'"`.includes(event.key) && codeBefore.substr(codeBefore.length-1) !== "\\"
if (close.includes(event.key) && escapeCharacter && codeAfter.substr(0, 1) === event.key) {
const pos = save()
preventDefault(event)
pos.start = ++pos.end
restore(pos)
} else if (open.includes(event.key)) {
} else if (open.includes(event.key) && escapeCharacter) {
const pos = save()
preventDefault(event)
const text = event.key + close[open.indexOf(event.key)]
Expand Down

0 comments on commit a599705

Please sign in to comment.