-
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
Changes from 1 commit
20c86c2
cd3c3cb
ab657cb
75c4cde
ce2b15e
699fd15
257ad98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,13 @@ export default class TableCellSelection implements EditorPlugin { | |
event.rawEvent.preventDefault(); | ||
} | ||
break; | ||
case PluginEventType.Input: | ||
if (!this.state.startedSelection) { | ||
this.handleInputEvent(this.editor); | ||
} else { | ||
event.rawEvent.preventDefault(); | ||
} | ||
break; | ||
case PluginEventType.Scroll: | ||
if (this.state.startedSelection) { | ||
handleScrollEvent(this.state, this.editor); | ||
|
@@ -127,4 +134,18 @@ export default class TableCellSelection implements EditorPlugin { | |
editor.select(selection.table, null); | ||
} | ||
} | ||
|
||
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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 |
||
const row = range.ranges[0]; | ||
const firstCell = row.startContainer.childNodes[row.startOffset]; | ||
firstCell.childNodes.forEach(node => { | ||
node.remove(); | ||
}); | ||
} | ||
// Add undo snapshot after content deletion | ||
editor.addUndoSnapshot(); | ||
} | ||
Andres-CT98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
Notice that the typed character and the last filled value are both undone. The only one undone should be the typed one.
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:
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.