Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichText: only ignore input types that insert HTML #13914

Merged
merged 3 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export {
RichTextShortcut,
RichTextToolbarButton,
RichTextInserterItem,
RichTextInputEvent,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RichTextInputEvent was included in 5.1 RC1 (#13833, #13908). Do we need to cherry-pick this into 5.1 final? Or do a full deprecation?

cc @noisysocks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's meant to be included before the release. I don't mind not doing it, but atm this is more meant to be an internal thing and I'd rather not have it seen documented as stable API. Only thought about it after merge, sorry :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include this in 5.1 and avoid deprecations.

UnstableRichTextInputEvent,
} from './rich-text';
export { default as ServerSideRender } from './server-side-render';
export { default as MediaPlaceholder } from './media-placeholder';
Expand Down
21 changes: 18 additions & 3 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ import { RemoveBrowserShortcuts } from './remove-browser-shortcuts';

const { getSelection } = window;

/**
* All inserting input types that would insert HTML into the DOM.
*
* @see https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes
*
* @type {Set}
*/
const INSERTION_INPUT_TYPES_TO_IGNORE = new Set( [
'insertParagraph',
'insertOrderedList',
'insertUnorderedList',
'insertHorizontalRule',
'insertLink',
] );

export class RichText extends Component {
constructor( { value, onReplace, multiline } ) {
super( ...arguments );
Expand Down Expand Up @@ -354,12 +369,12 @@ export class RichText extends Component {
if ( event ) {
const { inputType } = event.nativeEvent;

// The browser formatted something or tried to insert a list.
// The browser formatted something or tried to insert HTML.
// Overwrite it. It will be handled later by the format library if
// needed.
if (
inputType.indexOf( 'format' ) === 0 ||
( inputType.indexOf( 'insert' ) === 0 && inputType !== 'insertText' )
INSERTION_INPUT_TYPES_TO_IGNORE.has( inputType )
) {
this.applyRecord( this.getRecord() );
return;
Expand Down Expand Up @@ -1150,4 +1165,4 @@ export default RichTextContainer;
export { RichTextShortcut } from './shortcut';
export { RichTextToolbarButton } from './toolbar-button';
export { RichTextInserterItem } from './inserter-list-item';
export { RichTextInputEvent } from './input-event';
export { UnstableRichTextInputEvent } from './input-event';
2 changes: 1 addition & 1 deletion packages/editor/src/components/rich-text/input-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { Component } from '@wordpress/element';

export class RichTextInputEvent extends Component {
export class UnstableRichTextInputEvent extends Component {
constructor() {
super( ...arguments );

Expand Down
4 changes: 2 additions & 2 deletions packages/format-library/src/bold/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { toggleFormat } from '@wordpress/rich-text';
import { RichTextToolbarButton, RichTextShortcut, RichTextInputEvent } from '@wordpress/editor';
import { RichTextToolbarButton, RichTextShortcut, UnstableRichTextInputEvent } from '@wordpress/editor';

const name = 'core/bold';

Expand Down Expand Up @@ -32,7 +32,7 @@ export const bold = {
shortcutType="primary"
shortcutCharacter="b"
/>
<RichTextInputEvent
<UnstableRichTextInputEvent
inputType="formatBold"
onInput={ onToggle }
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/format-library/src/italic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { toggleFormat } from '@wordpress/rich-text';
import { RichTextToolbarButton, RichTextShortcut, RichTextInputEvent } from '@wordpress/editor';
import { RichTextToolbarButton, RichTextShortcut, UnstableRichTextInputEvent } from '@wordpress/editor';

const name = 'core/italic';

Expand Down Expand Up @@ -32,7 +32,7 @@ export const italic = {
shortcutType="primary"
shortcutCharacter="i"
/>
<RichTextInputEvent
<UnstableRichTextInputEvent
inputType="formatItalic"
onInput={ onToggle }
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/format-library/src/underline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { toggleFormat } from '@wordpress/rich-text';
import { RichTextShortcut, RichTextInputEvent } from '@wordpress/editor';
import { RichTextShortcut, UnstableRichTextInputEvent } from '@wordpress/editor';

const name = 'core/underline';

Expand Down Expand Up @@ -34,7 +34,7 @@ export const underline = {
character="u"
onUse={ onToggle }
/>
<RichTextInputEvent
<UnstableRichTextInputEvent
inputType="formatUnderline"
onInput={ onToggle }
/>
Expand Down