mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-21 05:42:00 +02:00
add preventDefault to all examples
This commit is contained in:
parent
da10eaeca9
commit
77ffcaae66
@ -87,15 +87,15 @@ class App extends React.Component {
|
||||
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
|
||||
|
||||
// Prevent the ampersand character from being inserted.
|
||||
event.preventDefault()
|
||||
|
||||
// Otherwise, transform the state by inserting "and" at the cursor's position.
|
||||
// Transform the state by inserting "and" at the cursor's position.
|
||||
const newState = state
|
||||
.transform()
|
||||
.insertText('and')
|
||||
.apply()
|
||||
|
||||
// Prevent the ampersand character from being inserted.
|
||||
event.preventDefault()
|
||||
|
||||
// Return the new state, which will cause the editor to update it.
|
||||
return newState
|
||||
|
@ -29,6 +29,7 @@ class App extends React.Component {
|
||||
|
||||
onKeyDown = (event, data, state) => {
|
||||
if (event.which != 192 || !event.metaKey) return
|
||||
event.preventDefault()
|
||||
const isCode = state.blocks.some(block => block.type == 'code')
|
||||
|
||||
return state
|
||||
@ -77,6 +78,7 @@ class App extends React.Component {
|
||||
switch (event.which) {
|
||||
// When "B" is pressed, add a "bold" mark to the text.
|
||||
case 66: {
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.addMark('bold')
|
||||
@ -85,6 +87,7 @@ class App extends React.Component {
|
||||
// When "`" is pressed, keep our existing code block logic.
|
||||
case 192: {
|
||||
const isCode = state.blocks.some(block => block.type == 'code')
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.setBlock(isCode ? 'paragraph' : 'code')
|
||||
@ -151,6 +154,7 @@ class App extends React.Component {
|
||||
|
||||
switch (event.which) {
|
||||
case 66: {
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.toggleMark('bold')
|
||||
@ -158,6 +162,7 @@ class App extends React.Component {
|
||||
}
|
||||
case 192: {
|
||||
const isCode = state.blocks.some(block => block.type == 'code')
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.setBlock(isCode ? 'paragraph' : 'code')
|
||||
|
@ -24,6 +24,8 @@ class App extends React.Component {
|
||||
|
||||
onKeyDown = (event, data, state) => {
|
||||
if (event.which != 55 || !event.shiftKey) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
const newState = state
|
||||
.transform()
|
||||
@ -90,6 +92,8 @@ class App extends React.Component {
|
||||
|
||||
onKeyDown = (event, data, state) => {
|
||||
if (event.which != 55 || !event.shiftKey) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
const newState = state
|
||||
.transform()
|
||||
@ -139,6 +143,9 @@ class App extends React.Component {
|
||||
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
|
||||
|
||||
// Prevent the "`" from being inserted by default.
|
||||
event.preventDefault()
|
||||
|
||||
// Otherwise, set the currently selected blocks type to "code".
|
||||
return state
|
||||
@ -187,6 +194,8 @@ class App extends React.Component {
|
||||
|
||||
onKeyDown = (event, data, state) => {
|
||||
if (event.which != 192 || !event.metaKey) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
// Determine whether any of the currently selected blocks are code blocks.
|
||||
const isCode = state.blocks.some(block => block.type == 'code')
|
||||
|
@ -31,6 +31,7 @@ class App extends React.Component {
|
||||
|
||||
onKeyDown = (event, data, state) => {
|
||||
if (!event.metaKey || event.which != 66) return
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.toggleMark('bold')
|
||||
@ -76,6 +77,9 @@ function MarkHotkey(options) {
|
||||
// Check that the key pressed matches our `code` option.
|
||||
if (!event.metaKey || event.which != code) return
|
||||
|
||||
// Prevent the default characters from being inserted.
|
||||
event.preventDefault()
|
||||
|
||||
// Toggle the mark `type`.
|
||||
return state
|
||||
.transform()
|
||||
@ -214,6 +218,7 @@ function MarkHotkey(options) {
|
||||
onKeyDown(event, data, state) {
|
||||
// Change the comparison to use the key name.
|
||||
if (!event.metaKey || keycode(event.which) != key) return
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.toggleMark(type)
|
||||
|
Loading…
x
Reference in New Issue
Block a user