Skip to content

Commit

Permalink
Fix paste over selection
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Dec 1, 2020
1 parent ed03d0f commit 84aaec0
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,10 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement) => void
function handlePaste(event: ClipboardEvent) {
preventDefault(event)
const text = ((event as any).originalEvent || event).clipboardData.getData("text/plain")
const sel = window.getSelection()
const selection = !sel.isCollapsed
const pos = save()
insert(text)
highlight(editor)
if (selection) {
restore({start: pos.end, end: pos.end})
} else {
restore({start: pos.end + text.length, end: pos.end + text.length})
}
restore({start: pos.start + text.length, end: pos.start + text.length})
}


Expand Down

0 comments on commit 84aaec0

Please sign in to comment.