-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7572 from ckeditor/i/7454
Fix (table): The table structure should not be changed while removing the heading row. Closes #7454. Closes #7601. Fix (table): Merging cells of multiple whole rows or columns should not crash the editor. MINOR BREAKING CHANGE (table): The `removeEmptyRows()` and `removeEmptyRowsColumns()` ulitiy functions does not require `batch` parameter any more. MINOR BREAKING CHANGE (table): The `downcastTableHeadingRowsChange()` downcast converter has been removed. It is no longer possible to override `headingRows` attribute change in single converter. This behavior can be customized using a table downcast converter. See #7601.
- Loading branch information
Showing
12 changed files
with
203 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/ckeditor5-table/src/converters/table-heading-rows-refresh-post-fixer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module table/converters/table-heading-rows-refresh-post-fixer | ||
*/ | ||
|
||
/** | ||
* Injects a table post-fixer into the model which marks the table in the differ to have it re-rendered. | ||
* | ||
* Table heading rows are represented in the model by a `headingRows` attribute. However, in the view, it's represented as separate | ||
* sections of the table (`<thead>` or `<tbody>`) and changing `headingRows` attribute requires moving table rows between two sections. | ||
* This causes problems with structural changes in a table (like adding and removing rows) thus atomic converters cannot be used. | ||
* | ||
* When table `headingRows` attribute changes, the entire table is re-rendered. | ||
* | ||
* @param {module:engine/model/model~Model} model | ||
*/ | ||
export default function injectTableHeadingRowsRefreshPostFixer( model ) { | ||
model.document.registerPostFixer( () => tableHeadingRowsRefreshPostFixer( model ) ); | ||
} | ||
|
||
function tableHeadingRowsRefreshPostFixer( model ) { | ||
const differ = model.document.differ; | ||
|
||
// Stores tables to be refreshed so the table will be refreshed once for multiple changes. | ||
const tablesToRefresh = new Set(); | ||
|
||
for ( const change of differ.getChanges() ) { | ||
if ( change.type != 'attribute' ) { | ||
continue; | ||
} | ||
|
||
const element = change.range.start.nodeAfter; | ||
|
||
if ( element && element.is( 'table' ) && change.attributeKey == 'headingRows' ) { | ||
tablesToRefresh.add( element ); | ||
} | ||
} | ||
|
||
if ( tablesToRefresh.size ) { | ||
// @if CK_DEBUG_TABLE // console.log( `Post-fixing table: refreshing heading rows (${ tablesToRefresh.size }).` ); | ||
|
||
for ( const table of tablesToRefresh.values() ) { | ||
differ.refreshItem( table ); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.