-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace first cell content if input while on cell selection #2030
Replace first cell content if input while on cell selection #2030
Conversation
packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/TableCellSelection.ts
Outdated
Show resolved
Hide resolved
if (!this.state.startedSelection) { | ||
this.handleInputEvent(this.editor); | ||
} else { | ||
event.rawEvent.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Input event preventable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we just need to handle keydown event, it will be good enough. I tried to comment out the handling code of input event, and it still works well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue with undo that is mitigated by using the Input method. It only happens if you type one character and do undo, the inputted character and the last written thing will both be undone. This issue is present today and not introduced by this change.
The reason I clear the full cell is that I do not know if select is enough to cover all possible elements in the cell for deletion. And for clearing I want to make sure it is an input and not other keys like caps lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the undo issue, can you provide a full end to end repro step? I want to understand more about it. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, in that case we do need to call addUndoSnapshot() when type with table selection, but only need to do once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think it should be good enough to just select everything inside the table cell when keydown. Because:
- User made a table selection, then type
- User selected everything in a table cell, then type
Both of them should get the same result. So making a selection to the first select cell means we convert 2 to 1, so that is the right operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been trying both selection types, but each have an issue. editor.select with the Td as parameter has the above issue, while editor.select with the table and coordinates as parameter has an issue of replacing everything in the cell when typing. For example if the cell has multiple lines, only the first one is replaced.
packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/keyUtils/handleKeyDownEvent.ts
Outdated
Show resolved
Hide resolved
private handleInputEvent(editor: IEditor) { | ||
// If typing on any cell selection, clear the first cell | ||
const range = editor.getSelectionRangeEx(); | ||
if (range.type == SelectionRangeTypes.TableSelection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I assumed it would retain the selection type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you have called editor.select(), that will change selection type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And because of that, the executing result is correct now. But if line 142-146 are executed, the new typed content will be removed, just because when Input event is triggered, the new typed content is already added into the view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have noticed that, would it work if I did the deletion before the Input event? I would need to add it to PluginEventType.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My feeling is you just need to keep you current code to select the content of first selected cell, (and call addUndoSnapshot() in a proper place), then let browser handle everything else, so no need to handle Input event at all.
Because Input event is triggered after type, so anything there is too late.
And maybe only need to handle character types (you can use isCharacterValue
function to check) so for other keys like caps lock, leave it to browser
@@ -26,7 +26,7 @@ export function handleKeyUpEvent( | |||
!state.preventKeyUp && | |||
IGNORE_KEY_UP_KEYS.indexOf(which) == -1 | |||
) { | |||
clearState(state, editor); | |||
editor.addUndoSnapshot(() => clearState(state, editor)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Arrow Keys, Escape or some other keys that do not add content will add an unneeded undo snapshot here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. In that case, my change in handleKeydownEvent.ts to addUndoSnapshot() is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can use isCharacterValue here to only add the snapshot if it is true.
…u/acampostams/fix-select-cell-replace-text
* Content Model: Improve cache behavior (#1999) * Content Model: Improve cache behavior * fix build * fix comment * Skip Trigger plugin event on plain text paste (#2011) * init * remove unneeded change * Update return type * Fix 218869: Do not allow dragging on readonly content (#2010) * Fix 218869: Do not allow dragging readonly content * fix test * Content Model: Fix 194024 and 220289 (#2012) * Content Model: Fix 221290 Support float for image (#2013) * Content Model: improve formatWithContentModel 1 (#2001) * Content Model: Improve cache behavior * fix build * Content Model: improve formatWithContentModel * Content Model: improve formatWithContentModel 2 (#2002) * Content Model: Improve cache behavior * fix build * Content Model: improve formatWithContentModel * Content Model: improve formatWithContentModel 2 * fix format * WIP * fix handles * MergeModel, do not inherit the styles of table when splitting the param (#2016) * init * init * address comment * update test names * fixes * Demo site: Fix insert link button in Content Model ribbon (#2018) * Content Model: insertEntity API (#1800) * Content Model insertEntity * improve * improve * Content Model: Improve cache behavior * fix build * Content Model: improve formatWithContentModel * Content Model: improve formatWithContentModel 2 * Improve * fix build * fix build * improve * add test * add test * add test * add test * fix dark color * fix test * fix build and test * crop * fix xase * check cell exist * Fix #1752, rename header to heading (#2020) * fix cell empty cells * fix flipped image * Update logic to decide if we need to merge a table on paste. (#2022) * Fix TableSelectionCopy * update unit tests * Fix 2 * address comment * Content Model: Rename a test file (#2029) * Fix Triple clicking a single cell selecting more than one (#2024) * fix triple click, optimisation * Remove `display: flex` style on paste (#2031) * init * Fix * Replace first cell content if input while on cell selection (#2030) * select first cell content and empty, add undo if change * Content Model: Fix 222135 (#2035) * Fix 222135 * fix build * Content Model: Fix 219312 (#2036) * Fix regression when creating the BeforePasteEvent (#2039) * init * fix build * Content Model: Fix 220050 (#2037) * Content Model: Fix 220050 * Fix build * improve * improve * Simplify the domToModel call in `paste.ts` (#2040) * add more changes * fix build * fix test * Content Model: Support vertical-align for image (#2041) * Content Model: Support vertical-align for image * fix build and test --------- Co-authored-by: Bryan Valverde U <[email protected]> * version bump --------- Co-authored-by: Jiuqing Song <[email protected]> Co-authored-by: Bryan Valverde U <[email protected]> Co-authored-by: Júlia Roldi <[email protected]> Co-authored-by: Julia Roldi <[email protected]>
* Content Model: Improve cache behavior (#1999) * Content Model: Improve cache behavior * fix build * fix comment * Skip Trigger plugin event on plain text paste (#2011) * init * remove unneeded change * Update return type * Fix 218869: Do not allow dragging on readonly content (#2010) * Fix 218869: Do not allow dragging readonly content * fix test * Content Model: Fix 194024 and 220289 (#2012) * Content Model: Fix 221290 Support float for image (#2013) * Content Model: improve formatWithContentModel 1 (#2001) * Content Model: Improve cache behavior * fix build * Content Model: improve formatWithContentModel * Content Model: improve formatWithContentModel 2 (#2002) * Content Model: Improve cache behavior * fix build * Content Model: improve formatWithContentModel * Content Model: improve formatWithContentModel 2 * fix format * WIP * fix handles * MergeModel, do not inherit the styles of table when splitting the param (#2016) * init * init * address comment * update test names * fixes * Demo site: Fix insert link button in Content Model ribbon (#2018) * Content Model: insertEntity API (#1800) * Content Model insertEntity * improve * improve * Content Model: Improve cache behavior * fix build * Content Model: improve formatWithContentModel * Content Model: improve formatWithContentModel 2 * Improve * fix build * fix build * improve * add test * add test * add test * add test * fix dark color * fix test * fix build and test * crop * fix xase * check cell exist * Fix #1752, rename header to heading (#2020) * fix cell empty cells * fix flipped image * Update logic to decide if we need to merge a table on paste. (#2022) * Fix TableSelectionCopy * update unit tests * Fix 2 * address comment * Content Model: Rename a test file (#2029) * Fix Triple clicking a single cell selecting more than one (#2024) * fix triple click, optimisation * Remove `display: flex` style on paste (#2031) * init * Fix * Replace first cell content if input while on cell selection (#2030) * select first cell content and empty, add undo if change * Content Model: Fix 222135 (#2035) * Fix 222135 * fix build * Content Model: Fix 219312 (#2036) * Fix regression when creating the BeforePasteEvent (#2039) * init * fix build * Content Model: Fix 220050 (#2037) * Content Model: Fix 220050 * Fix build * improve * improve * Simplify the domToModel call in `paste.ts` (#2040) * add more changes * fix build * fix test * Content Model: Support vertical-align for image (#2041) * Content Model: Support vertical-align for image * fix build and test --------- Co-authored-by: Bryan Valverde U <[email protected]> * Remove deprecated colors from borders, text and background. (#2045) * Support more border styles * init * Revert unrelated change * Fix dependencies * address comments * try fix build * reselection * add space * Content Model: Improve insertEntity (#2047) * Content Model: Improve insertEntity * fix test * Content Model: Fix selection of entity (#2051) * Content Model: Always return size in pt when getFormatState (#2052) * Content Model: trigger ShadowEdit events (#2053) * Content Model: trigger ShadowEdit events * improve * Content Model: Add solid paragraph in new table cell (#2055) * Content Model: Do color transform for entity when copy/paste (#2056) * Content Model: Do color transform for entity when copy/paste * Call normalizeContentModel * Content Model: Paste plain text applies current format (#2057) * Content Model: Paste plain text applies current format * fix build * Content Model: Fix a regression of shadow edit (#2058) * Update versions * Fix double import * Double import 2 --------- Co-authored-by: Jiuqing Song <[email protected]> Co-authored-by: Bryan Valverde U <[email protected]> Co-authored-by: Júlia Roldi <[email protected]> Co-authored-by: Julia Roldi <[email protected]> Co-authored-by: Andres-CT98 <[email protected]>
Description:
Fix of #2023
Writing on a selected cell, or group of cells, does not replace the content of the first cell as expected.
Fix
On the TableCellSelection plugin, the handle key down event used to end the cell selection when typing. Now it makes only the first cell selected and creates a new selection of all its children.
Cases tested:
Before: The place where the cursor was placed is where the typed text will be inserted.
After: The first cell in the selection, top left one, will be cleared and the typed text will be inserted.
Warnings and implications