mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 20:24:01 +02:00
Adds Unicode LF character to line endings for clipboard plaintext (#2040)
* Adds Unicode LF character to line endings for clipboard plaintext This addresses https://github.com/ianstormtaylor/slate/issues/1932 * Fixes plaintext/unicode pastes not having line breaks * Removes stray spaces for Prettier * Refactors Value creation to save 4 lines
This commit is contained in:
committed by
Ian Storm Taylor
parent
2e9b94b481
commit
3eabdea8d6
@@ -1,4 +1,6 @@
|
||||
import Base64 from 'slate-base64-serializer'
|
||||
import Plain from 'slate-plain-serializer'
|
||||
import { Value } from 'slate'
|
||||
import TRANSFER_TYPES from '../constants/transfer-types'
|
||||
import getWindow from 'get-window'
|
||||
import findDOMNode from './find-dom-node'
|
||||
@@ -82,6 +84,12 @@ function cloneFragment(event, value, fragment = value.fragment) {
|
||||
|
||||
attach.setAttribute('data-slate-fragment', encoded)
|
||||
|
||||
// Creates value from only the selected blocks
|
||||
// Then gets plaintext for clipboard with proper linebreaks for BLOCK elements
|
||||
// Via Plain serializer
|
||||
const valFromSelection = Value.create({ document: fragment })
|
||||
const plainText = Plain.serialize(valFromSelection)
|
||||
|
||||
// Add the phony content to a div element. This is needed to copy the
|
||||
// contents into the html clipboard register.
|
||||
const div = window.document.createElement('div')
|
||||
@@ -95,7 +103,7 @@ function cloneFragment(event, value, fragment = value.fragment) {
|
||||
// (mapped to 'text/url-list'); so, we should only enter block if !IS_IE
|
||||
if (event.clipboardData && event.clipboardData.setData && !IS_IE) {
|
||||
event.preventDefault()
|
||||
event.clipboardData.setData(TEXT, div.textContent)
|
||||
event.clipboardData.setData(TEXT, plainText)
|
||||
event.clipboardData.setData(FRAGMENT, encoded)
|
||||
event.clipboardData.setData(HTML, div.innerHTML)
|
||||
return
|
||||
|
Reference in New Issue
Block a user