Fix remove row when physical and visual rows indexes don't match #11644
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
core.alter('remove_row')doesn't correctly handle cases where the visual and physical row counts don't match (eg. the table has trimmed rows)Row removal is eventually handled by
DataMap.removeRow(index, amount, source)which usesDataMap.visualRowsToPhysical(visualRowIndex, amount)to convert the passed range of visual rows to an array of physical row indexes.visualRowsToPhysical()attempts to:indexandamountparameters based on the size of the tableThe existing logic for step 1 is incorrectly normalizing the passed arguments using the physical number of rows in the columns instead of the visual number of rows. This pull request fixes the normalization to use
countRows()instead ofcountSourceRows(). It also renames the incorrectly namedphysicRowvariable tovisualRowsince it contains the current visual row index during loop iteration.How has this been tested?
This has been tested by using verifying the behavior demonstrated by the codesandbox provided with #11643 works as expected regardless of whether the table contains trimmed rows or not.
It is also worth nothing that the fixed normalization logic in
visualRowsToPhysical()is now consistent withvisualColumnsToPhysical()which provides the same functionality but for columns (although, it too suffers from an incorrectly namedphysicalColvariable).Types of changes
Related issue(s):
Affected project(s):
handsontable@handsontable/angular@handsontable/react@handsontable/react-wrapper@handsontable/vue@handsontable/vue3Checklist: