Skip to content

Commit

Permalink
Merge pull request #949 from wordpress-mobile/fix/android-rich-text-e…
Browse files Browse the repository at this point in the history
…rrors

Fix android rich text errors
  • Loading branch information
Tug authored May 15, 2019
2 parents 92be0c5 + a0240cd commit dee8eca
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 48 deletions.
2 changes: 1 addition & 1 deletion gutenberg
Submodule gutenberg updated 95 files
+1 −1 docs/contributors/readme.md
+1 −1 docs/designers-developers/developers/block-api/block-deprecation.md
+11 −10 docs/designers-developers/developers/internationalization.md
+1 −1 docs/designers-developers/developers/packages.md
+0 −11 docs/designers-developers/readme.md
+1,322 −0 docs/manifest-devhub.json
+6 −17 docs/readme.md
+113 −115 docs/toc.json
+1 −1 docs/tool/index.js
+1 −1 docs/tool/manifest.js
+1 −1 gutenberg.php
+26 −0 lib/compat.php
+1 −0 lib/load.php
+1 −1 package-lock.json
+1 −1 package.json
+0 −1 packages/block-editor/src/components/inserter-list-item/index.js
+11 −4 packages/block-editor/src/components/rich-text/editable.js
+111 −77 packages/block-editor/src/components/rich-text/index.js
+241 −176 packages/block-editor/src/components/rich-text/index.native.js
+8 −4 packages/block-editor/src/components/url-input/index.js
+20 −9 packages/block-editor/src/components/writing-flow/index.js
+44 −35 packages/block-editor/src/store/effects.js
+5 −0 packages/block-library/src/audio/edit.js
+5 −0 packages/block-library/src/column/block.json
+96 −19 packages/block-library/src/column/edit.js
+10 −0 packages/block-library/src/column/index.js
+8 −2 packages/block-library/src/column/save.js
+92 −53 packages/block-library/src/columns/edit.js
+0 −11 packages/block-library/src/columns/editor.scss
+6 −3 packages/block-library/src/columns/style.scss
+229 −0 packages/block-library/src/columns/test/utils.js
+127 −1 packages/block-library/src/columns/utils.js
+13 −55 packages/block-library/src/heading/edit.native.js
+2 −2 packages/block-library/src/legacy-widget/edit/dom-manager.js
+4 −4 packages/block-library/src/legacy-widget/edit/handler.js
+7 −8 packages/block-library/src/legacy-widget/edit/index.js
+2 −2 packages/block-library/src/nextpage/icon.js
+1 −0 packages/block-library/src/paragraph/edit.native.js
+5 −0 packages/block-library/src/video/edit.js
+2 −2 packages/blocks/src/api/parser.js
+21 −0 packages/blocks/src/api/raw-handling/comment-remover.js
+3 −1 packages/blocks/src/api/raw-handling/paste-handler.js
+43 −0 packages/blocks/src/api/raw-handling/test/comment-remover.js
+4 −4 packages/blocks/src/api/validation.js
+7 −1 packages/components/CHANGELOG.md
+1 −1 packages/components/README.md
+1 −1 packages/components/src/button/style.scss
+6 −0 packages/components/src/date-time/style.scss
+1 −1 packages/components/src/disabled/index.js
+9 −3 packages/components/src/range-control/index.js
+4 −0 packages/components/src/range-control/style.scss
+1 −1 packages/components/src/toolbar-button/style.scss
+1 −1 packages/docgen/src/test/fixtures/tags-function/code.js
+6 −2 packages/dom/src/dom.js
+1 −1 packages/e2e-test-utils/src/get-available-block-transforms.js
+4 −1 packages/e2e-test-utils/src/insert-block.js
+2 −2 packages/e2e-test-utils/src/press-key-with-modifier.js
+4 −2 packages/e2e-test-utils/src/transform-block-to.js
+6 −0 packages/e2e-tests/specs/__snapshots__/links.test.js.snap
+6 −0 packages/e2e-tests/specs/__snapshots__/rich-text.test.js.snap
+63 −0 packages/e2e-tests/specs/__snapshots__/rtl.test.js.snap
+26 −0 packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap
+21 −2 packages/e2e-tests/specs/block-hierarchy-navigation.test.js
+43 −0 packages/e2e-tests/specs/links.test.js
+10 −5 packages/e2e-tests/specs/plugins/allowed-blocks.test.js
+4 −1 packages/e2e-tests/specs/plugins/container-blocks.test.js
+4 −1 packages/e2e-tests/specs/plugins/inner-blocks-allowed-blocks.test.js
+15 −0 packages/e2e-tests/specs/rich-text.test.js
+122 −0 packages/e2e-tests/specs/rtl.test.js
+57 −5 packages/e2e-tests/specs/writing-flow.test.js
+7 −1 packages/edit-post/src/components/header/pinned-plugins/style.scss
+1 −1 packages/edit-post/src/hooks/components/media-upload/index.js
+0 −2 packages/editor/src/components/post-publish-panel/style.scss
+36 −25 packages/editor/src/components/table-of-contents/panel.js
+7 −5 packages/editor/src/components/table-of-contents/style.scss
+6 −6 packages/escape-html/src/index.js
+3 −4 packages/format-library/src/link/modal.native.js
+1 −1 packages/redux-routine/src/is-generator.js
+13 −10 packages/rich-text/src/apply-format.js
+0 −83 packages/rich-text/src/apply-format.native.js
+0 −44 packages/rich-text/src/get-active-format.native.js
+11 −6 packages/rich-text/src/register-format-type.js
+5 −6 packages/rich-text/src/remove-format.js
+0 −70 packages/rich-text/src/remove-format.native.js
+11 −0 packages/rich-text/src/test/apply-format.js
+2 −0 packages/rich-text/src/test/remove-format.js
+2 −0 packages/rich-text/src/test/toggle-format.js
+14 −14 packages/token-list/src/index.js
+2 −0 test/integration/blocks-raw-handling.spec.js
+1 −1 test/integration/fixtures/google-docs-in.html
+1 −1 test/integration/fixtures/google-docs-table-in.html
+4 −0 test/integration/fixtures/google-docs-table-with-comments-in.html
+3 −0 test/integration/fixtures/google-docs-table-with-comments-out.html
+4 −0 test/integration/fixtures/google-docs-with-comments-in.html
+35 −0 test/integration/fixtures/google-docs-with-comments-out.html
24 changes: 24 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { NativeModules } from 'react-native';

jest.mock( '../react-native-gutenberg-bridge', () => {
return {
addEventListener: jest.fn(),
Expand Down Expand Up @@ -36,3 +41,22 @@ if ( ! global.window.matchMedia ) {
removeListener: () => {},
} );
}

// Overwrite some native module mocks from `react-native` jest preset:
// https://github.com/facebook/react-native/blob/master/jest/setup.js
// to fix issue "TypeError: Cannot read property 'Commands' of undefined"
// raised when calling focus or blur on a native component
const mockNativeModules = {
UIManager: {
...NativeModules.UIManager,
getViewManagerConfig: jest.fn( () => ( { Commands: {} } ) ),
},
};

Object.keys( mockNativeModules ).forEach( ( module ) => {
try {
jest.doMock( module, () => mockNativeModules[ module ] ); // needed by FacebookSDK-test
} catch ( error ) {
jest.doMock( module, () => mockNativeModules[ module ], { virtual: true } );
}
} );
2 changes: 1 addition & 1 deletion react-native-aztec/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
wordpressUtilsVersion = '1.22'
espressoVersion = '3.0.1'

aztecVersion = 'v1.3.26'
aztecVersion = 'gb-stray-selection-fix-try1'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class ReactAztecText extends AztecText {
public ReactAztecText(ThemedReactContext reactContext) {
super(reactContext);

setGutenbergMode(true);

// don't auto-focus when Aztec becomes visible.
// Needed on rotation and multiple Aztec instances to avoid losing the exact care position.
setFocusOnVisible(false);
Expand Down
59 changes: 20 additions & 39 deletions src/block-management/block-holder.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { addAction, removeAction, hasAction } from '@wordpress/hooks';
import { getBlockType } from '@wordpress/blocks';
import { BlockEdit } from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -124,39 +123,6 @@ export class BlockHolder extends React.Component<PropsType, StateType> {
}
};

mergeBlocks = ( forward: boolean = false ) => {
const {
clientId,
getPreviousBlockClientId,
getNextBlockClientId,
mergeBlocks,
} = this.props;

const previousBlockClientId = getPreviousBlockClientId( clientId );
const nextBlockClientId = getNextBlockClientId( clientId );

// Do nothing when it's the first block.
if (
( ! forward && ! previousBlockClientId ) ||
( forward && ! nextBlockClientId )
) {
return;
}

if ( forward ) {
mergeBlocks( clientId, nextBlockClientId );
} else {
const name = this.props.getBlockName( previousBlockClientId );
const blockType = getBlockType( name );
// The default implementation does only focus the previous block if it's not mergeable
// We don't want to move the focus for now, just keep for and caret at the beginning of the current block.
if ( ! blockType.merge ) {
return;
}
mergeBlocks( previousBlockClientId, clientId );
}
};

renderToolbar() {
if ( ! this.props.isSelected ) {
return null;
Expand All @@ -182,7 +148,7 @@ export class BlockHolder extends React.Component<PropsType, StateType> {
onFocus={ this.onFocus }
onReplace={ this.props.onReplace }
insertBlocksAfter={ this.insertBlocksAfter }
mergeBlocks={ this.mergeBlocks }
mergeBlocks={ this.props.mergeBlocks }
onCaretVerticalPositionChange={ this.props.onCaretVerticalPositionChange }
clientId={ this.props.clientId }
/>
Expand Down Expand Up @@ -256,9 +222,8 @@ export default compose( [
name,
};
} ),
withDispatch( ( dispatch, { clientId, rootClientId } ) => {
withDispatch( ( dispatch, { clientId, rootClientId }, { select } ) => {
const {
clearSelectedBlock,
insertBlocks,
mergeBlocks,
moveBlocksDown,
Expand All @@ -270,7 +235,24 @@ export default compose( [
} = dispatch( 'core/block-editor' );

return {
mergeBlocks,
mergeBlocks( forward ) {
const {
getPreviousBlockClientId,
getNextBlockClientId,
} = select( 'core/block-editor' );

if ( forward ) {
const nextBlockClientId = getNextBlockClientId( clientId );
if ( nextBlockClientId ) {
mergeBlocks( clientId, nextBlockClientId );
}
} else {
const previousBlockClientId = getPreviousBlockClientId( clientId );
if ( previousBlockClientId ) {
mergeBlocks( previousBlockClientId, clientId );
}
}
},
moveBlockDown() {
moveBlocksDown( clientId );
},
Expand All @@ -284,7 +266,6 @@ export default compose( [
insertBlocks( blocks, index, rootClientId );
},
onSelect: ( selectedClientId: string ) => {
clearSelectedBlock();
selectBlock( selectedClientId );
},
onChange: ( attributes: Object ) => {
Expand Down
10 changes: 3 additions & 7 deletions src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type PropsType = {
rootClientId: ?string,
blockClientIds: Array<string>,
blockCount: number,
focusBlock: ( clientId: string ) => void,
selectBlock: ( clientId: string ) => void,
insertBlock: ( block: BlockType, position: number ) => void,
replaceBlock: ( string, BlockType ) => mixed,
getBlockName: string => string,
Expand Down Expand Up @@ -123,7 +123,7 @@ export class BlockManager extends React.Component<PropsType, StateType> {
}

// now set the focus
this.props.focusBlock( newBlock.clientId );
this.props.selectBlock( newBlock.clientId );
}

onSafeAreaInsetsUpdate( result: Object ) {
Expand Down Expand Up @@ -378,18 +378,14 @@ export default compose( [
} ),
withDispatch( ( dispatch ) => {
const {
clearSelectedBlock,
insertBlock,
replaceBlock,
selectBlock,
} = dispatch( 'core/block-editor' );

return {
insertBlock,
focusBlock: ( clientId ) => {
clearSelectedBlock();
selectBlock( clientId );
},
selectBlock,
replaceBlock,
};
} ),
Expand Down

0 comments on commit dee8eca

Please sign in to comment.