mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 17:53:59 +02:00
add support for isShift on paste
This commit is contained in:
@@ -178,6 +178,8 @@ class PasteHtml extends React.Component {
|
|||||||
|
|
||||||
onPaste = (e, data, state) => {
|
onPaste = (e, data, state) => {
|
||||||
if (data.type != 'html') return
|
if (data.type != 'html') return
|
||||||
|
if (data.isShift) return
|
||||||
|
|
||||||
const { document } = serializer.deserialize(data.html)
|
const { document } = serializer.deserialize(data.html)
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
@@ -510,6 +510,13 @@ class Content extends React.Component {
|
|||||||
const key = keycode(which)
|
const key = keycode(which)
|
||||||
const data = {}
|
const data = {}
|
||||||
|
|
||||||
|
// Keep track of an `isShifting` flag, because it's often used to trigger
|
||||||
|
// "Paste and Match Style" commands, but isn't available on the event in a
|
||||||
|
// normal paste event.
|
||||||
|
if (key == 'shift') {
|
||||||
|
this.tmp.isShifting = true
|
||||||
|
}
|
||||||
|
|
||||||
// When composing, these characters commit the composition but also move the
|
// When composing, these characters commit the composition but also move the
|
||||||
// selection before we're able to handle it, so prevent their default,
|
// selection before we're able to handle it, so prevent their default,
|
||||||
// selection-moving behavior.
|
// selection-moving behavior.
|
||||||
@@ -552,6 +559,21 @@ class Content extends React.Component {
|
|||||||
this.props.onKeyDown(event, data)
|
this.props.onKeyDown(event, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On key up, unset the `isShifting` flag.
|
||||||
|
*
|
||||||
|
* @param {Event} event
|
||||||
|
*/
|
||||||
|
|
||||||
|
onKeyUp = (event) => {
|
||||||
|
const { which } = event
|
||||||
|
const key = keycode(which)
|
||||||
|
|
||||||
|
if (key == 'shift') {
|
||||||
|
this.tmp.isShifting = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On paste, determine the type and bubble up.
|
* On paste, determine the type and bubble up.
|
||||||
*
|
*
|
||||||
@@ -566,6 +588,10 @@ class Content extends React.Component {
|
|||||||
const transfer = new Transfer(event.clipboardData)
|
const transfer = new Transfer(event.clipboardData)
|
||||||
const data = transfer.getData()
|
const data = transfer.getData()
|
||||||
|
|
||||||
|
// Attach the `isShift` flag, so that people can use it to trigger "Paste
|
||||||
|
// and Match Style" logic.
|
||||||
|
data.isShift = !!this.tmp.isShifting
|
||||||
|
|
||||||
debug('onPaste', { event, data })
|
debug('onPaste', { event, data })
|
||||||
this.props.onPaste(event, data)
|
this.props.onPaste(event, data)
|
||||||
}
|
}
|
||||||
@@ -712,7 +738,7 @@ class Content extends React.Component {
|
|||||||
onDrop={this.onDrop}
|
onDrop={this.onDrop}
|
||||||
onInput={this.onInput}
|
onInput={this.onInput}
|
||||||
onKeyDown={this.onKeyDown}
|
onKeyDown={this.onKeyDown}
|
||||||
onKeyUp={noop}
|
onKeyUp={this.onKeyUp}
|
||||||
onPaste={this.onPaste}
|
onPaste={this.onPaste}
|
||||||
onSelect={this.onSelect}
|
onSelect={this.onSelect}
|
||||||
spellCheck={spellCheck}
|
spellCheck={spellCheck}
|
||||||
|
Reference in New Issue
Block a user