Files
HelixNotes/tests/table-scroll.test.mjs
Yuri Karamian 77164427f1 fix: keep table horizontal scrolling when notes open read-only
TipTap registers the table node view together with column resizing only when the editor starts editable. Opening a note in View mode therefore left tables without their .tableWrapper, so wide tables could not scroll horizontally until the app was restarted in Edit mode.

Keep the table view plugin installed for read-only editors; its resize handlers still ignore non-editable views.

Add a regression test that the table node view is registered when the initial editor is read-only. (Discord report)
2026-11-05 01:27:11 +04:00

51 lines
2.0 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { Table } from '@tiptap/extension-table';
import { columnResizingPluginKey, tableEditingKey, tableNodes } from '@tiptap/pm/tables';
import { EditorState } from '@tiptap/pm/state';
import { Schema } from '@tiptap/pm/model';
import { AlwaysResizableTable } from '../src/lib/editor/tableExtension.ts';
test('the table wrapper is registered even when the editor starts read-only', () => {
const options = {
...Table.options,
resizable: true,
};
const plugins = AlwaysResizableTable.config.addProseMirrorPlugins.call({
options,
editor: { isEditable: false },
});
const keys = new Set(plugins.map((plugin) => plugin.key));
assert.ok(keys.has(columnResizingPluginKey.key), 'missing table node view / column resizing plugin');
assert.ok(keys.has(tableEditingKey.key), 'missing table editing plugin');
// The column-resizing plugin registers the table node view when its state starts. That node
// view is what creates .tableWrapper, which owns the horizontal scrollbar.
const resizing = plugins.find((plugin) => plugin.key === columnResizingPluginKey.key);
const nodes = tableNodes({ tableGroup: 'block', cellContent: 'inline*', cellAttributes: {} });
const schema = new Schema({
nodes: {
doc: { content: 'block+' },
text: { group: 'inline' },
paragraph: { content: 'inline*', group: 'block' },
...nodes,
},
});
EditorState.create({ schema, plugins });
assert.equal(typeof resizing.spec.props.nodeViews.table, 'function');
});
test('a non-resizable table still gets table editing', () => {
const options = {
...Table.options,
resizable: false,
};
const plugins = AlwaysResizableTable.config.addProseMirrorPlugins.call({
options,
editor: { isEditable: false },
});
const keys = new Set(plugins.map((plugin) => plugin.key));
assert.equal(keys.has(columnResizingPluginKey.key), false);
assert.ok(keys.has(tableEditingKey.key));
});