Skip to content

Commit

Permalink
Add wrapping of selected text on self closing char
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Apr 2, 2021
1 parent a85bcb1 commit d16edae
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,15 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement, pos?: P
} else if (
open.includes(event.key)
&& !escapeCharacter
// Only if string or have empty space after
&& (`"'`.includes(event.key) || ['', ' ', '\n'].includes(charAfter))
) {
// Place closing char.
const pos = save()
preventDefault(event)
const text = event.key + close[open.indexOf(event.key)]
const pos = save()
const wrapText = pos.start == pos.end ? '' : getSelection().toString()
const text = event.key + wrapText + close[open.indexOf(event.key)]
insert(text)
pos.start = ++pos.end
pos.start++
pos.end++
restore(pos)
}
}
Expand Down

0 comments on commit d16edae

Please sign in to comment.