Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
}
}

this.state.mouseDisposer?.();
this.state.mouseDisposer = editor.attachDomEvent({
mousemove: {
beforeDispatch: this.onMouseMove,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,83 @@ describe('SelectionPlugin handle table selection', () => {
} as any,
});

plugin.onPluginEvent!({
eventType: 'mouseDown',
rawEvent: {
button: 0,
target: td,
} as any,
});

expect(state).toEqual({
selection: null,
tableSelection: {
table: table,
parsedTable: [[td]],
firstCo: { row: 0, col: 0 },
startNode: td,
},
mouseDisposer: mouseMoveDisposer,
imageSelectionBorderColor: DEFAULT_SELECTION_BORDER_COLOR,
imageSelectionBorderColorDark: DEFAULT_SELECTION_BORDER_COLOR,
tableCellSelectionBackgroundColor: DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR,
tableCellSelectionBackgroundColorDark: DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR,
});
expect(mouseDispatcher).toBeDefined();
});

it('MouseDown - clean and re-attach mouse move event handler if mouseDown event triggered twice', () => {
const state = plugin.getState();
const table = document.createElement('table');
table.setAttribute('contenteditable', 'true');
const tr = document.createElement('tr');
const td = document.createElement('td');
const div = document.createElement('div');

tr.appendChild(td);
table.appendChild(tr);
contentDiv.appendChild(table);
contentDiv.appendChild(div);

spyOn(editor, 'attachDomEvent').and.callThrough();

getDOMSelectionSpy.and.returnValue({
type: 'table',
});

plugin.onPluginEvent!({
eventType: 'mouseDown',
rawEvent: {
button: 0,
target: div,
} as any,
});

expect(state).toEqual({
selection: null,
tableSelection: null,
imageSelectionBorderColor: DEFAULT_SELECTION_BORDER_COLOR,
imageSelectionBorderColorDark: DEFAULT_SELECTION_BORDER_COLOR,
tableCellSelectionBackgroundColor: DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR,
tableCellSelectionBackgroundColorDark: DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR,
});

plugin.onPluginEvent!({
eventType: 'mouseDown',
rawEvent: {
button: 0,
target: td,
} as any,
});

plugin.onPluginEvent!({
eventType: 'mouseDown',
rawEvent: {
button: 0,
target: td,
} as any,
});

expect(state).toEqual({
selection: null,
tableSelection: {
Expand All @@ -891,6 +968,8 @@ describe('SelectionPlugin handle table selection', () => {
tableCellSelectionBackgroundColorDark: DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR,
});
expect(mouseDispatcher).toBeDefined();
expect(mouseMoveDisposer).toHaveBeenCalledTimes(1);
expect(editor.attachDomEvent).toHaveBeenCalledTimes(2);
});

it('MouseDown - do not save a table selection when left click, table is not editable', () => {
Expand Down
Loading