mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 09:04:31 +02:00
expose onKeyUp (#1026)
* expose onKeyUp to be used by plugin * Update plugin.md
This commit is contained in:
committed by
Ian Storm Taylor
parent
b0d481978b
commit
2076cdbc99
@@ -33,6 +33,7 @@ The top-level React component that renders the Slate editor itself.
|
|||||||
- [`onCut`](#oncut)
|
- [`onCut`](#oncut)
|
||||||
- [`onDrop`](#ondrop)
|
- [`onDrop`](#ondrop)
|
||||||
- [`onKeyDown`](#onkeydown)
|
- [`onKeyDown`](#onkeydown)
|
||||||
|
- [`onKeyUp`](#onkeyup)
|
||||||
- [`onPaste`](#onpaste)
|
- [`onPaste`](#onpaste)
|
||||||
- [`onSelect`](#onselect)
|
- [`onSelect`](#onselect)
|
||||||
- [`schema`](#schema)
|
- [`schema`](#schema)
|
||||||
@@ -197,6 +198,7 @@ const plugins = [
|
|||||||
### `onCut`
|
### `onCut`
|
||||||
### `onDrop`
|
### `onDrop`
|
||||||
### `onKeyDown`
|
### `onKeyDown`
|
||||||
|
### `onKeyUp`
|
||||||
### `onPaste`
|
### `onPaste`
|
||||||
### `onSelect`
|
### `onSelect`
|
||||||
### `schema`
|
### `schema`
|
||||||
|
@@ -16,6 +16,7 @@ When the editor needs to resolve a plugin-related handler, it will loop through
|
|||||||
- [`onCut`](#oncut)
|
- [`onCut`](#oncut)
|
||||||
- [`onDrop`](#ondrop)
|
- [`onDrop`](#ondrop)
|
||||||
- [`onKeyDown`](#onkeydown)
|
- [`onKeyDown`](#onkeydown)
|
||||||
|
- [`onKeyUp`](#onkeyup)
|
||||||
- [`onPaste`](#onpaste)
|
- [`onPaste`](#onpaste)
|
||||||
- [`onSelect`](#onselect)
|
- [`onSelect`](#onselect)
|
||||||
- [Other Properties](#other-properties)
|
- [Other Properties](#other-properties)
|
||||||
@@ -49,6 +50,7 @@ export default function MySlatePlugin(options) {
|
|||||||
onCut: Function,
|
onCut: Function,
|
||||||
onDrop: Function,
|
onDrop: Function,
|
||||||
onKeyDown: Function,
|
onKeyDown: Function,
|
||||||
|
onKeyUp: Function,
|
||||||
onPaste: Function,
|
onPaste: Function,
|
||||||
onSelect: Function
|
onSelect: Function
|
||||||
}
|
}
|
||||||
@@ -163,6 +165,13 @@ The `isLine` and `isWord` booleans represent whether the "line modifier" or "wor
|
|||||||
|
|
||||||
Make sure to `event.preventDefault()` (and return `state`) if you do not want the default insertion behavior to occur! If no other plugin handles this event, it will be handled by the [Core plugin](./core.md).
|
Make sure to `event.preventDefault()` (and return `state`) if you do not want the default insertion behavior to occur! If no other plugin handles this event, it will be handled by the [Core plugin](./core.md).
|
||||||
|
|
||||||
|
### `onKeyUp`
|
||||||
|
`Function onKeUp(event: Event, data: Object, state: State, editor: Editor) => State || Void`
|
||||||
|
|
||||||
|
This handler is called when any key is released in the `contenteditable` element.
|
||||||
|
|
||||||
|
The `data` object contains the same information as the `data` object of `onKeyDown`.
|
||||||
|
|
||||||
### `onPaste`
|
### `onPaste`
|
||||||
`Function onPaste(event: Event, data: Object, state: State, editor: Editor) => State || Void`
|
`Function onPaste(event: Event, data: Object, state: State, editor: Editor) => State || Void`
|
||||||
|
|
||||||
|
@@ -54,6 +54,7 @@ class Content extends React.Component {
|
|||||||
onDrop: Types.func.isRequired,
|
onDrop: Types.func.isRequired,
|
||||||
onFocus: Types.func.isRequired,
|
onFocus: Types.func.isRequired,
|
||||||
onKeyDown: Types.func.isRequired,
|
onKeyDown: Types.func.isRequired,
|
||||||
|
onKeyUp: Types.func.isRequired,
|
||||||
onPaste: Types.func.isRequired,
|
onPaste: Types.func.isRequired,
|
||||||
onSelect: Types.func.isRequired,
|
onSelect: Types.func.isRequired,
|
||||||
readOnly: Types.bool.isRequired,
|
readOnly: Types.bool.isRequired,
|
||||||
@@ -686,12 +687,29 @@ class Content extends React.Component {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
onKeyUp = (event) => {
|
onKeyUp = (event) => {
|
||||||
const { which } = event
|
const { altKey, ctrlKey, metaKey, shiftKey, which } = event
|
||||||
const key = keycode(which)
|
const key = keycode(which)
|
||||||
|
const data = {}
|
||||||
|
|
||||||
if (key == 'shift') {
|
if (key == 'shift') {
|
||||||
this.tmp.isShifting = false
|
this.tmp.isShifting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add helpful properties for handling hotkeys to the data object.
|
||||||
|
data.code = which
|
||||||
|
data.key = key
|
||||||
|
data.isAlt = altKey
|
||||||
|
data.isCmd = IS_MAC ? metaKey && !altKey : false
|
||||||
|
data.isCtrl = ctrlKey && !altKey
|
||||||
|
data.isLine = IS_MAC ? metaKey : false
|
||||||
|
data.isMeta = metaKey
|
||||||
|
data.isMod = IS_MAC ? metaKey && !altKey : ctrlKey && !altKey
|
||||||
|
data.isModAlt = IS_MAC ? metaKey && altKey : ctrlKey && altKey
|
||||||
|
data.isShift = shiftKey
|
||||||
|
data.isWord = IS_MAC ? altKey : ctrlKey
|
||||||
|
|
||||||
|
debug('onKeyUp', { event, data })
|
||||||
|
this.props.onKeyUp(event, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,6 +30,7 @@ const EVENT_HANDLERS = [
|
|||||||
'onCut',
|
'onCut',
|
||||||
'onDrop',
|
'onDrop',
|
||||||
'onKeyDown',
|
'onKeyDown',
|
||||||
|
'onKeyUp',
|
||||||
'onPaste',
|
'onPaste',
|
||||||
'onSelect',
|
'onSelect',
|
||||||
]
|
]
|
||||||
|
@@ -27,6 +27,7 @@ const EVENT_HANDLER_METHODS = [
|
|||||||
'onCut',
|
'onCut',
|
||||||
'onDrop',
|
'onDrop',
|
||||||
'onKeyDown',
|
'onKeyDown',
|
||||||
|
'onKeyUp',
|
||||||
'onPaste',
|
'onPaste',
|
||||||
'onSelect',
|
'onSelect',
|
||||||
]
|
]
|
||||||
|
@@ -953,6 +953,7 @@ function Plugin(options = {}) {
|
|||||||
onCut={editor.onCut}
|
onCut={editor.onCut}
|
||||||
onDrop={editor.onDrop}
|
onDrop={editor.onDrop}
|
||||||
onKeyDown={editor.onKeyDown}
|
onKeyDown={editor.onKeyDown}
|
||||||
|
onKeyUp={editor.onKeyUp}
|
||||||
onPaste={editor.onPaste}
|
onPaste={editor.onPaste}
|
||||||
onSelect={editor.onSelect}
|
onSelect={editor.onSelect}
|
||||||
readOnly={props.readOnly}
|
readOnly={props.readOnly}
|
||||||
|
Reference in New Issue
Block a user