diff --git a/docs/walkthroughs/adding-event-handlers.md b/docs/walkthroughs/adding-event-handlers.md index f8ee95002..d3baa1074 100644 --- a/docs/walkthroughs/adding-event-handlers.md +++ b/docs/walkthroughs/adding-event-handlers.md @@ -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 diff --git a/docs/walkthroughs/applying-custom-formatting.md b/docs/walkthroughs/applying-custom-formatting.md index b30908463..f79f943bc 100644 --- a/docs/walkthroughs/applying-custom-formatting.md +++ b/docs/walkthroughs/applying-custom-formatting.md @@ -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') diff --git a/docs/walkthroughs/defining-custom-block-nodes.md b/docs/walkthroughs/defining-custom-block-nodes.md index 601c7f392..21ca55f3c 100644 --- a/docs/walkthroughs/defining-custom-block-nodes.md +++ b/docs/walkthroughs/defining-custom-block-nodes.md @@ -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') diff --git a/docs/walkthroughs/using-plugins.md b/docs/walkthroughs/using-plugins.md index 072d60c3d..25034a8a9 100644 --- a/docs/walkthroughs/using-plugins.md +++ b/docs/walkthroughs/using-plugins.md @@ -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)