in packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/TableCellSelection.ts [280:341]
private handleMouseDownEvent(event: PluginMouseDownEvent) {
const { which, shiftKey } = event.rawEvent;
if (which == RIGHT_CLICK && this.tableSelection) {
//If the user is right clicking To open context menu
const td = this.editor.getElementAtCursor(TABLE_CELL_SELECTOR);
if (td?.classList.contains(TABLE_CELL_SELECTED)) {
this.firstTarget = null;
this.lastTarget = null;
this.editor.queryElements('td.' + TABLE_CELL_SELECTED, node => {
this.firstTarget = this.firstTarget || node;
this.lastTarget = node;
});
const selection = this.editor.getDocument().defaultView.getSelection();
selection.setBaseAndExtent(this.firstTarget, 0, this.lastTarget, 0);
highlight(this.vTable);
return;
}
}
this.editor.getDocument().addEventListener('mouseup', this.onMouseUp, true /*setCapture*/);
if (which == LEFT_CLICK && !shiftKey) {
this.clearState();
this.editor
.getDocument()
.addEventListener('mousemove', this.onMouseMove, true /*setCapture*/);
this.startedSelection = true;
}
if (which == LEFT_CLICK && shiftKey) {
this.editor.runAsync(editor => {
const sel = editor.getDocument().defaultView.getSelection();
const first = getCellAtCursor(editor, sel.anchorNode);
const last = getCellAtCursor(editor, sel.focusNode);
const firstTable = getTableAtCursor(editor, first);
const targetTable = getTableAtCursor(editor, first);
if (
firstTable! == targetTable! &&
safeInstanceOf(first, 'HTMLTableCellElement') &&
safeInstanceOf(last, 'HTMLTableCellElement')
) {
this.vTable = new VTable(first);
const firstCord = getCellCoordinates(this.vTable, first);
const lastCord = getCellCoordinates(this.vTable, last);
this.vTable.selection = {
firstCell: firstCord,
lastCell: lastCord,
};
this.firstTarget = first;
this.lastTarget = last;
highlight(this.vTable);
this.tableRange = this.vTable.selection;
this.tableSelection = true;
this.firstTable = firstTable as HTMLTableElement;
this.targetTable = targetTable;
updateSelection(editor, first, 0);
}
});
}
}