From 10f31572587a1929a6aea7f8372c5efa3b33921d Mon Sep 17 00:00:00 2001 From: Takagi <1103069291@qq.com> Date: Mon, 17 Jun 2024 21:48:50 +0800 Subject: [PATCH 1/9] fix: ensure pasted content auto-generates title id (#6059) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area editor /milestone 2.17.x #### What this PR does / why we need it: 当前在编辑器中粘贴内容后,如果不修改任意标题或新增标题,则无法为当前标题自动生成标题 ID,进而导致锚点失效。 本 PR 将在编辑器触发内容更改后,如果是粘贴的内容,则直接触发生成标题 ID。 #### How to test it? 新建一篇文章并粘贴一段带标题的内容后直接发布。 查看发布后的文章是否可以在主题端使用锚点跳转。 #### Which issue(s) this PR fixes: Fixes #6056 #### Does this PR introduce a user-facing change? ```release-note 解决在默认编辑器中粘贴的内容无法生成标题 ID 的问题 ``` --- ui/packages/editor/src/extensions/heading/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/packages/editor/src/extensions/heading/index.ts b/ui/packages/editor/src/extensions/heading/index.ts index 4452b69fad..82235d2ea1 100644 --- a/ui/packages/editor/src/extensions/heading/index.ts +++ b/ui/packages/editor/src/extensions/heading/index.ts @@ -290,6 +290,9 @@ const Blockquote = TiptapHeading.extend({ return true; } if (transaction.docChanged) { + if (transaction.getMeta("paste")) { + return true; + } beforeComposition = composition; const selection = transaction.selection; const { $from } = selection; From 1e37768b358450a37271ee19fa8bae2bd6cca723 Mon Sep 17 00:00:00 2001 From: Takagi <1103069291@qq.com> Date: Tue, 18 Jun 2024 14:00:52 +0800 Subject: [PATCH 2/9] pref: improve code block styling in editor (#6089) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /area editor #### What this PR does / why we need it: 优化编辑器代码块样式。 before: image after: image #### How to test it? 测试复制功能是否正常。 #### Does this PR introduce a user-facing change? ```release-note 优化默认编辑器代码块样式 ``` --- .../code-block/CodeBlockViewRenderer.vue | 63 ++++++++++++++----- .../src/extensions/code-block/code-block.ts | 6 +- ui/packages/editor/src/index.ts | 2 +- ui/packages/editor/src/locales/en.yaml | 5 +- ui/packages/editor/src/locales/zh-CN.yaml | 5 +- ui/packages/editor/src/styles/base.scss | 2 +- ui/packages/editor/src/styles/index.scss | 1 + .../editor/src/styles/node-select.scss | 9 +++ 8 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 ui/packages/editor/src/styles/node-select.scss diff --git a/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue b/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue index d6ba2639f8..e6f675c84d 100644 --- a/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue +++ b/ui/packages/editor/src/extensions/code-block/CodeBlockViewRenderer.vue @@ -4,6 +4,10 @@ import type { Editor, Node } from "@/tiptap/vue-3"; import { NodeViewContent, NodeViewWrapper } from "@/tiptap/vue-3"; import lowlight from "./lowlight"; import { computed } from "vue"; +import BxBxsCopy from "~icons/bx/bxs-copy"; +import IconCheckboxCircle from "~icons/ri/checkbox-circle-line"; +import { useTimeout } from "@vueuse/core"; +import { i18n } from "@/locales"; const props = defineProps<{ editor: Editor; @@ -28,24 +32,53 @@ const selectedLanguage = computed({ props.updateAttributes({ language: language }); }, }); + +const { ready, start } = useTimeout(2000, { controls: true, immediate: false }); + +const handleCopyCode = () => { + if (!ready.value) return; + const code = props.node.textContent; + navigator.clipboard.writeText(code).then(() => { + start(); + }); +};