| @@ -168,15 +168,12 @@ | ||
| 168 | 168 | * Note that this does currently not take into account hidden rows! |
| 169 | 169 | * |
| 170 | 170 | * This is e.g. used to give feedback in the context menu and "Combine/Merge" button. |
| 171 | 171 | * |
| 172 | - * @param {string} errors Whether errors should also be alert()ed. | |
| 173 | 172 | * @param {Object} error_message Call-by-reference object for the error message. |
| 174 | 173 | * @return {boolean} Whether the merge is allowed or not. |
| 175 | 174 | */ |
| 176 | -tp.helpers.cell_merge_allowed = function ( errors, error_message = {} ) { | |
| 177 | - const alertOnError = ( 'alert' === errors ); | |
| 178 | - | |
| 175 | +tp.helpers.cell_merge_allowed = function ( error_message = {} ) { | |
| 179 | 176 | const first_selected_row_idx = tp.helpers.selection.rows[0]; |
| 180 | 177 | const last_selected_row_idx = tp.helpers.selection.rows[ tp.helpers.selection.rows.length - 1 ]; |
| 181 | 178 | |
| 182 | 179 | const first_body_row_idx = tp.table.options.table_head; |
| @@ -185,12 +182,8 @@ | ||
| 185 | 182 | // If table header rows are used and the "Enable Visitor Features" option is active, cell merging is only allowed in the table header and footer rows. |
| 186 | 183 | if ( tp.table.options.table_head > 0 && tp.table.options.use_datatables && ! ( first_selected_row_idx < first_body_row_idx && last_selected_row_idx < first_body_row_idx ) && ! ( first_selected_row_idx > last_body_row_idx && last_selected_row_idx > last_body_row_idx ) ) { |
| 187 | 184 | error_message.text = sprintf( __( 'You can not combine these cells, because the “%1$s” checkbox in the “%2$s” section is checked.', 'tablepress' ), __( 'Enable Visitor Features', 'tablepress' ), __( 'Table Features for Site Visitors', 'tablepress' ) ) + |
| 188 | 185 | ' ' + __( 'When the Table Features for Site Visitors are used, merging is only allowed in the table header and footer rows.', 'tablepress' ); |
| 189 | - if ( alertOnError ) { | |
| 190 | - // This alert can not be replaced by the `Alert` component, as that does not pause the code execution. | |
| 191 | - window.alert( error_message.text ); | |
| 192 | - } | |
| 193 | 186 | return false; |
| 194 | 187 | } |
| 195 | 188 | |
| 196 | 189 | // If table header rows are used, and a header row and at least one adjacent body row are selected, disable merging cells. |
| @@ -195,12 +188,8 @@ | ||
| 195 | 188 | |
| 196 | 189 | // If table header rows are used, and a header row and at least one adjacent body row are selected, disable merging cells. |
| 197 | 190 | if ( first_selected_row_idx < first_body_row_idx && last_selected_row_idx >= first_body_row_idx ) { |
| 198 | 191 | error_message.text = sprintf( __( 'You can not combine these cells, because the “%1$s” setting in the “%2$s” section is active.', 'tablepress' ), __( 'Table Header', 'tablepress' ), __( 'Table Options', 'tablepress' ) ); |
| 199 | - if ( alertOnError ) { | |
| 200 | - // This alert can not be replaced by the `Alert` component, as that does not pause the code execution. | |
| 201 | - window.alert( error_message.text ); | |
| 202 | - } | |
| 203 | 192 | return false; |
| 204 | 193 | } |
| 205 | 194 | |
| 206 | 195 | // If table footer rows are used, and a footer row and at least one adjacent body row are selected, disable merging cells. |
| @@ -205,12 +194,8 @@ | ||
| 205 | 194 | |
| 206 | 195 | // If table footer rows are used, and a footer row and at least one adjacent body row are selected, disable merging cells. |
| 207 | 196 | if ( first_selected_row_idx <= last_body_row_idx && last_selected_row_idx > last_body_row_idx ) { |
| 208 | 197 | error_message.text = sprintf( __( 'You can not combine these cells, because the “%1$s” setting in the “%2$s” section is active.', 'tablepress' ), __( 'Table Footer', 'tablepress' ), __( 'Table Options', 'tablepress' ) ); |
| 209 | - if ( alertOnError ) { | |
| 210 | - // This alert can not be replaced by the `Alert` component, as that does not pause the code execution. | |
| 211 | - window.alert( error_message.text ); | |
| 212 | - } | |
| 213 | 198 | return false; |
| 214 | 199 | } |
| 215 | 200 | |
| 216 | 201 | // Otherwise allow the merge. |
| @@ -481,9 +466,9 @@ | ||
| 481 | 466 | title: wp.media.view.l10n.addMedia, |
| 482 | 467 | multiple: true, |
| 483 | 468 | } ); |
| 484 | 469 | const cell_name = jexcel.getColumnNameFromId( [ tp.helpers.selection.columns[0], tp.helpers.selection.rows[0] ] ); |
| 485 | - document.querySelector( '#media-frame-title h1' ).textContent = sprintf( __( 'Add media to cell %1$s', 'tablepress' ), cell_name ); | |
| 470 | + document.querySelector( '.media-frame-title h1' ).textContent = sprintf( __( 'Add media to cell %1$s', 'tablepress' ), cell_name ); | |
| 486 | 471 | jexcel.current = null; // This is necessary to prevent problems with the focus when the "Insert Link" dialog is called from the context menu. |
| 487 | 472 | }; |
| 488 | 473 | |
| 489 | 474 | tp.callbacks.advanced_editor = {}; |
| @@ -569,11 +554,11 @@ | ||
| 569 | 554 | insert_function( data, shifted_roc_idx, position_bool ); |
| 570 | 555 | } ); |
| 571 | 556 | tp.helpers.unsaved_changes.set(); |
| 572 | 557 | |
| 573 | - // Select both inserted/duplicated rows/columns if more than one were selected. | |
| 558 | + // Select both the inserted and the selected rows/columns if more than one were selected or when duplicating, otherwise select just the original row/column. | |
| 574 | 559 | const num_selected_rocs = tp.helpers.selection[ type ].length; |
| 575 | - if ( num_selected_rocs > 1 ) { | |
| 560 | + if ( num_selected_rocs > 1 || duplicating ) { | |
| 576 | 561 | tp.editor.updateSelectionFromCoords( |
| 577 | 562 | tp.helpers.selection.columns[0], |
| 578 | 563 | tp.helpers.selection.rows[0], |
| 579 | 564 | handling_rows ? tp.helpers.selection.columns[ tp.helpers.selection.columns.length - 1 ] : tp.helpers.selection.columns[ tp.helpers.selection.columns.length - 1 ] + num_selected_rocs, |
| @@ -578,8 +563,22 @@ | ||
| 578 | 563 | tp.helpers.selection.rows[0], |
| 579 | 564 | handling_rows ? tp.helpers.selection.columns[ tp.helpers.selection.columns.length - 1 ] : tp.helpers.selection.columns[ tp.helpers.selection.columns.length - 1 ] + num_selected_rocs, |
| 580 | 565 | handling_rows ? tp.helpers.selection.rows[ tp.helpers.selection.rows.length - 1 ] + num_selected_rocs : tp.helpers.selection.rows[ tp.helpers.selection.rows.length - 1 ] |
| 581 | 566 | ); |
| 567 | + } else { | |
| 568 | + // eslint-disable-next-line no-lonely-if | |
| 569 | + if ( 'before' === position ) { | |
| 570 | + tp.editor.updateSelectionFromCoords( | |
| 571 | + handling_rows ? tp.helpers.selection.columns[0] : tp.helpers.selection.columns[0] + num_selected_rocs, | |
| 572 | + handling_rows ? tp.helpers.selection.rows[0] + num_selected_rocs : tp.helpers.selection.rows[0], | |
| 573 | + handling_rows ? tp.helpers.selection.columns[ tp.helpers.selection.columns.length - 1 ] : tp.helpers.selection.columns[ tp.helpers.selection.columns.length - 1 ] + num_selected_rocs, | |
| 574 | + handling_rows ? tp.helpers.selection.rows[ tp.helpers.selection.rows.length - 1 ] + num_selected_rocs : tp.helpers.selection.rows[ tp.helpers.selection.rows.length - 1 ] | |
| 575 | + ); | |
| 576 | + } else { | |
| 577 | + // Call not needed, as the selection is still set when inserting after the selected (single!) row/column. | |
| 578 | + // tp.helpers.editor.reselect(); | |
| 579 | + } | |
| 580 | + | |
| 582 | 581 | } |
| 583 | 582 | }; |
| 584 | 583 | |
| 585 | 584 | /** |
| @@ -589,9 +588,8 @@ | ||
| 589 | 588 | */ |
| 590 | 589 | tp.callbacks.remove = function ( type ) { |
| 591 | 590 | const handling_rows = 'rows' === type; |
| 592 | 591 | const num_cors = handling_rows ? tp.editor.options.columns.length : tp.editor.options.data.length; |
| 593 | - const last_roc_idx = handling_rows ? tp.editor.options.data.length - 1 : tp.editor.options.columns.length - 1; | |
| 594 | 592 | |
| 595 | 593 | // Visibility meta information has to be deleted manually, as otherwise the Jspreadsheet meta information can get out of sync. |
| 596 | 594 | if ( tp.editor.options.meta ) { |
| 597 | 595 | tp.helpers.selection[ type ].forEach( function ( roc_idx ) { |
| @@ -605,14 +603,24 @@ | ||
| 605 | 603 | const delete_function = handling_rows ? tp.editor.deleteRow : tp.editor.deleteColumn; |
| 606 | 604 | delete_function( tp.helpers.selection[ type ][0], tp.helpers.selection[ type ].length ); |
| 607 | 605 | tp.helpers.unsaved_changes.set(); |
| 608 | 606 | |
| 607 | + let first_row_idx = tp.helpers.selection.rows[0]; | |
| 608 | + let first_col_idx = tp.helpers.selection.columns[0]; | |
| 609 | + let last_row_idx = tp.helpers.selection.rows[ tp.helpers.selection.rows.length - 1 ]; | |
| 610 | + let last_col_idx = tp.helpers.selection.columns[ tp.helpers.selection.columns.length - 1 ]; | |
| 611 | + const last_roc_idx = handling_rows ? tp.editor.options.data.length : tp.editor.options.columns.length; // Index of last row/column AFTER deletion! | |
| 609 | 612 | // Reselect last visible row/column, if last rows/columns were deleted. |
| 610 | 613 | if ( last_roc_idx === tp.helpers.selection[ type ][ tp.helpers.selection[ type ].length - 1 ] ) { |
| 611 | - const col_idx = handling_rows ? tp.helpers.selection.columns[0] : tp.helpers.selection.columns[0] - 1; | |
| 612 | - const row_idx = handling_rows ? tp.helpers.selection.rows[0] - 1 : tp.helpers.selection.rows[0]; | |
| 613 | - tp.editor.updateSelectionFromCoords( col_idx, row_idx, col_idx, row_idx ); | |
| 614 | + if ( handling_rows ) { | |
| 615 | + first_row_idx = Math.max( 0, first_row_idx - 1 ); | |
| 616 | + last_row_idx = Math.max( 0, last_row_idx - 1 ); | |
| 617 | + } else { | |
| 618 | + first_col_idx = Math.max( 0, first_col_idx - 1 ); | |
| 619 | + last_col_idx = Math.max( 0, last_col_idx - 1 ); | |
| 620 | + } | |
| 614 | 621 | } |
| 622 | + tp.editor.updateSelectionFromCoords( first_col_idx, first_row_idx, last_col_idx, last_row_idx ); | |
| 615 | 623 | }; |
| 616 | 624 | |
| 617 | 625 | /** |
| 618 | 626 | * Appends rows or columns at the bottom or right end of the table. |