diff --git a/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue b/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue index f18ea49ae2..e71adcf620 100644 --- a/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue +++ b/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue @@ -6,6 +6,8 @@ import { NodeViewContent, NodeViewWrapper } from "@/tiptap/vue-3"; import { useTimeout } from "@vueuse/core"; import { computed } from "vue"; import BxBxsCopy from "~icons/bx/bxs-copy"; +import RiArrowDownSFill from "~icons/ri/arrow-down-s-fill"; +import RiArrowRightSFill from "~icons/ri/arrow-right-s-fill"; import IconCheckboxCircle from "~icons/ri/checkbox-circle-line"; import lowlight from "./lowlight"; @@ -33,6 +35,15 @@ const selectedLanguage = computed({ }, }); +const collapsed = computed({ + get: () => { + return props.node.attrs.collapsed || false; + }, + set: (collapsed: boolean) => { + props.updateAttributes({ collapsed: collapsed }); + }, +}); + const { ready, start } = useTimeout(2000, { controls: true, immediate: false }); const handleCopyCode = () => { @@ -44,14 +55,29 @@ const handleCopyCode = () => { }; diff --git a/ui/packages/editor/src/extensions/code-block/code-block.ts b/ui/packages/editor/src/extensions/code-block/code-block.ts index 0ae4d5557c..cb55deab15 100644 --- a/ui/packages/editor/src/extensions/code-block/code-block.ts +++ b/ui/packages/editor/src/extensions/code-block/code-block.ts @@ -105,6 +105,25 @@ export default CodeBlockLowlight.extend< // otherwise the Mod-a shortcut key will be overridden. priority: 110, fakeSelection: true, + + addAttributes() { + return { + ...this.parent?.(), + collapsed: { + default: false, + parseHTML: (element) => !!element.getAttribute("collapsed"), + renderHTML: (attributes) => { + if (attributes.collapsed) { + return { + collapsed: attributes.collapsed, + }; + } + return {}; + }, + }, + }; + }, + addCommands() { return { ...this.parent?.(),