1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 10:29:48 +02:00

update keydown handler signature (#254)

* update keydown handler signature

* Update applying-custom-formatting.md

* Update defining-custom-block-nodes.md

* Update saving-to-a-database.md

* Update using-plugins.md
This commit is contained in:
Ian Storm Taylor
2016-08-18 09:40:18 -07:00
committed by GitHub
parent 6f5cdf49dc
commit cb0b9b9095
5 changed files with 24 additions and 24 deletions

View File

@@ -46,13 +46,13 @@ class App extends React.Component {
<Editor
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
// Define a new handler which prints the key code that was pressed.
onKeyDown(event, state) {
onKeyDown(event, data, state) {
console.log(event.which)
}
@@ -77,12 +77,12 @@ class App extends React.Component {
<Editor
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
// Return with no changes if it's not the "7" key with shift pressed.
if (event.which != 55 || !event.shiftKey) return

View File

@@ -29,12 +29,12 @@ class App extends React.Component {
state={this.state.state}
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={e, state => this.onKeyDown(e, state)}
onKeyDown={e, data, state => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
if (event.which != 192 || !event.metaKey) return
const isCode = state.blocks.some(block => block.type == 'code')
@@ -68,12 +68,12 @@ class App extends React.Component {
schema={this.state.schema}
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
if (!event.metaKey) return
// Decide what to do based on the key code...
@@ -141,12 +141,12 @@ class App extends React.Component {
schema={this.state.schema}
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
if (!event.metaKey) return
switch (event.which) {

View File

@@ -23,12 +23,12 @@ class App extends React.Component {
<Editor
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
if (event.which != 55 || !event.shiftKey) return
const newState = state
@@ -87,12 +87,12 @@ class App extends React.Component {
schema={this.state.schema}
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={e, state => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
if (event.which != 55 || !event.shiftKey) return
const newState = state
@@ -130,12 +130,12 @@ class App extends React.Component {
schema={this.state.schema}
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={e, state => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
// Return with no changes if it's not the "`" key with cmd/ctrl pressed.
if (event.which != 192 || !event.metaKey) return
@@ -176,12 +176,12 @@ class App extends React.Component {
schema={this.state.schema}
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={e, state => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
if (event.which != 192 || !event.metaKey) return
// Determine whether any of the currently selected blocks are code blocks.

View File

@@ -135,7 +135,7 @@ class App extends React.Component {
<Editor
state={this.state.state}
onChange={state => this.onChange(state)}
onDocumentChange={state => this.onDocumentChange(document, state)}
onDocumentChange={(document, state) => this.onDocumentChange(document, state)}
/>
)
}
@@ -182,7 +182,7 @@ class App extends React.Component {
<Editor
state={this.state.state}
onChange={state => this.onChange(state)}
onDocumentChange={state => this.onDocumentChange(document, state)}
onDocumentChange={(document, state) => this.onDocumentChange(document, state)}
/>
)
}

View File

@@ -31,12 +31,12 @@ class App extends React.Component {
schema={this.state.schema}
state={this.state.state}
onChange={state => this.setState({ state })}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onKeyDown={(e, data, state) => this.onKeyDown(e, data, state)}
/>
)
}
onKeyDown(event, state) {
onKeyDown(event, data, state) {
if (!event.metaKey || event.which != 66) return
return state
.transform()
@@ -68,7 +68,7 @@ function MarkHotkey(options) {
// Return our "plugin" object, containing the `onKeyDown` handler.
return {
onKeyDown(event, state) {
onKeyDown(event, data, state) {
// Check that the key pressed matches our `code` option.
if (!event.metaKey || event.which != code) return
@@ -199,7 +199,7 @@ function MarkHotkey(options) {
const { type, key } = options
return {
onKeyDown(event, state) {
onKeyDown(event, data, state) {
// Change the comparison to use the key name.
if (!event.metaKey || keycode(event.which) != key) return
return state