1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-23 23:02:08 +03:00

WYSIWYG: Code & table fixes

- Fixed new code block insertion to remove selection area instead of
  just adding after.
- Added default table column widths to not be collapsed
- Updated table dom export to not duplicate colgroups.
This commit is contained in:
Dan Brown
2024-10-05 12:42:47 +01:00
parent 9b2520aa0c
commit c314a60a16
5 changed files with 40 additions and 30 deletions

View File

@@ -3,7 +3,7 @@ import {$createTextNode, $getSelection, $insertNodes, LexicalEditor, LexicalNode
import {
$getBlockElementNodesInSelection,
$getNodeFromSelection,
$insertNewBlockNodeAtSelection, $selectionContainsNodeType,
$insertNewBlockNodeAtSelection, $selectionContainsNodeType, $selectSingleNode,
$toggleSelectionBlockNodeType,
getLastSelection
} from "./selection";
@@ -65,9 +65,19 @@ export function formatCodeBlock(editor: LexicalEditor) {
editor.update(() => {
const codeBlock = $createCodeBlockNode();
codeBlock.setCode(selection?.getTextContent() || '');
$insertNewBlockNodeAtSelection(codeBlock, true);
const selectionNodes = $getBlockElementNodesInSelection(selection);
const firstSelectionNode = selectionNodes[0];
const extraNodes = selectionNodes.slice(1);
if (firstSelectionNode) {
firstSelectionNode.replace(codeBlock);
extraNodes.forEach(n => n.remove());
} else {
$insertNewBlockNodeAtSelection(codeBlock, true);
}
$openCodeEditorForNode(editor, codeBlock);
codeBlock.selectStart();
$selectSingleNode(codeBlock);
});
} else {
$openCodeEditorForNode(editor, codeBlock);