Skip to content

Commit

Permalink
fixed paste over selection issue (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike76-dev authored and antonmedv committed Dec 1, 2020
1 parent d88a7a2 commit ed03d0f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,16 @@ 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)
restore({start: pos.end + text.length, end: pos.end + text.length})
if (selection) {
restore({start: pos.end, end: pos.end})
} else {
restore({start: pos.end + text.length, end: pos.end + text.length})
}
}


Expand Down

0 comments on commit ed03d0f

Please sign in to comment.