From ca4af7c860c193d1f9dd8d5b5332fb321d9ac8c7 Mon Sep 17 00:00:00 2001 From: iseulde Date: Thu, 23 Aug 2018 15:28:17 +0200 Subject: [PATCH] Revert part of 19b7cb3a8fb1ab6b761a92c73ab6a22fe7ca3f8e --- packages/block-library/src/table/edit.js | 40 +++++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/table/edit.js b/packages/block-library/src/table/edit.js index bce19972c215df..f733d988138ae5 100644 --- a/packages/block-library/src/table/edit.js +++ b/packages/block-library/src/table/edit.js @@ -107,8 +107,14 @@ export default class TableEdit extends Component { * @param {Array} content A RichText content value. */ onChange( content ) { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, rowIndex, columnIndex } = this.state.selectedCell; + const { section, rowIndex, columnIndex } = selectedCell; setAttributes( updateCellContent( attributes, { section, @@ -124,8 +130,14 @@ export default class TableEdit extends Component { * @param {number} delta Offset for selected row index at which to insert. */ onInsertRow( delta ) { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, rowIndex } = this.state.selectedCell; + const { section, rowIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( insertRow( attributes, { @@ -152,8 +164,14 @@ export default class TableEdit extends Component { * Deletes the currently selected row. */ onDeleteRow() { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, rowIndex } = this.state.selectedCell; + const { section, rowIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( deleteRow( attributes, { section, rowIndex } ) ); @@ -165,8 +183,14 @@ export default class TableEdit extends Component { * @param {number} delta Offset for selected column index at which to insert. */ onInsertColumn( delta = 0 ) { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, columnIndex } = this.state.selectedCell; + const { section, columnIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( insertColumn( attributes, { @@ -193,8 +217,14 @@ export default class TableEdit extends Component { * Deletes the currently selected column. */ onDeleteColumn() { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, columnIndex } = this.state.selectedCell; + const { section, columnIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( deleteColumn( attributes, { section, columnIndex } ) );