From 6b4ff6a514017e1669457ddcdf888defd87c2db4 Mon Sep 17 00:00:00 2001 From: liu971227-sys <248239659+liu971227-sys@users.noreply.github.com> Date: Mon, 16 Feb 2026 11:11:47 +0800 Subject: [PATCH] fix(editor): distinguish GitHub issue vs PR embed prompt --- src/cloud/components/Editor/index.tsx | 25 ++++++++++++++++--- .../lib/editor/plugins/pasteFormatPlugin.ts | 11 +++++--- src/cloud/lib/hooks/editor/docEditor.ts | 7 ++++-- src/mobile/components/pages/DocEditPage.tsx | 25 ++++++++++++++++--- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/cloud/components/Editor/index.tsx b/src/cloud/components/Editor/index.tsx index 639530cb0a..d7e9726397 100644 --- a/src/cloud/components/Editor/index.tsx +++ b/src/cloud/components/Editor/index.tsx @@ -174,6 +174,7 @@ const Editor = ({ const [shortcodeConvertMenu, setShortcodeConvertMenu] = useState<{ pos: PositionRange cb: Callback + promptLabel?: string } | null>(null) const initialRenderDone = useRef(false) const { docsMap, workspacesMap, loadDoc } = useNav() @@ -392,8 +393,8 @@ const Editor = ({ }, }) pasteFormatPlugin(editor, { - openMenu: (pos, cb) => { - setShortcodeConvertMenu({ pos, cb }) + openMenu: (pos, cb, promptLabel) => { + setShortcodeConvertMenu({ pos, cb, promptLabel }) }, closeMenu: () => { setShortcodeConvertMenu(null) @@ -410,6 +411,8 @@ const Editor = ({ return { replacement: `[[ ${entityType} id="${org}/${repo}#${num}" ]]`, promptMenu: true, + promptLabel: + type === 'pull' ? 'Embed Pull Request?' : 'Embed Issue?', } } } @@ -1031,6 +1034,9 @@ const Editor = ({ + {shortcodeConvertMenu.promptLabel != null && ( +

{shortcodeConvertMenu.promptLabel}

+ )} @@ -1124,6 +1130,19 @@ const StyledShortcodeConvertMenu = styled.div` border-radius: 5px; box-shadow: ${({ theme }) => theme.colors.shadow}; + p { + margin: 0; + width: 200px; + line-height: 25px; + padding: ${({ theme }) => theme.sizes.spaces.xsm}px + ${({ theme }) => theme.sizes.spaces.sm}px; + background-color: ${({ theme }) => theme.colors.background.secondary}; + color: ${({ theme }) => theme.colors.text.primary}; + font-size: ${({ theme }) => theme.sizes.fonts.sm}px; + border-radius: 5px 5px 0 0; + border-bottom: solid 1px ${({ theme }) => theme.colors.border.main}; + } + button { display: block; width: 200px; @@ -1135,7 +1154,7 @@ const StyledShortcodeConvertMenu = styled.div` font-size: ${({ theme }) => theme.sizes.fonts.sm}px; text-align: left; - &:first-child { + &:first-of-type { border-radius: 5px 5px 0 0; } diff --git a/src/cloud/lib/editor/plugins/pasteFormatPlugin.ts b/src/cloud/lib/editor/plugins/pasteFormatPlugin.ts index 2f11aa37b6..c2b5ce1ded 100644 --- a/src/cloud/lib/editor/plugins/pasteFormatPlugin.ts +++ b/src/cloud/lib/editor/plugins/pasteFormatPlugin.ts @@ -14,10 +14,15 @@ export type Callback = (convert: boolean) => void type FormatterResult = { replacement: string | null promptMenu: boolean + promptLabel?: string } interface Config { - openMenu: (position: PositionRange, callback: Callback) => void + openMenu: ( + position: PositionRange, + callback: Callback, + promptLabel?: string + ) => void closeMenu: () => void formatter: (pasted: string[]) => FormatterResult } @@ -53,7 +58,7 @@ export const pasteFormatPlugin = ( return } - const { replacement, promptMenu } = formatter(change.text) + const { replacement, promptMenu, promptLabel } = formatter(change.text) if (replacement === null) { return @@ -78,7 +83,7 @@ export const pasteFormatPlugin = ( close() } - openMenu(posRange, callback) + openMenu(posRange, callback, promptLabel) open = true }) } diff --git a/src/cloud/lib/hooks/editor/docEditor.ts b/src/cloud/lib/hooks/editor/docEditor.ts index afc4f3d860..9f4a672254 100644 --- a/src/cloud/lib/hooks/editor/docEditor.ts +++ b/src/cloud/lib/hooks/editor/docEditor.ts @@ -59,6 +59,7 @@ export function useDocEditor({ const [shortcodeConvertMenu, setShortcodeConvertMenu] = useState<{ pos: PositionRange cb: Callback + promptLabel?: string } | null>(null) const suggestionsRef = useRef([]) const { loadDoc } = useNav() @@ -220,8 +221,8 @@ export function useDocEditor({ }, }) pasteFormatPlugin(editor, { - openMenu: (pos, cb) => { - setShortcodeConvertMenu({ pos, cb }) + openMenu: (pos, cb, promptLabel) => { + setShortcodeConvertMenu({ pos, cb, promptLabel }) }, closeMenu: () => { setShortcodeConvertMenu(null) @@ -238,6 +239,8 @@ export function useDocEditor({ return { replacement: `[[ ${entityType} id="${org}/${repo}#${num}" ]]`, promptMenu: true, + promptLabel: + type === 'pull' ? 'Embed Pull Request?' : 'Embed Issue?', } } } diff --git a/src/mobile/components/pages/DocEditPage.tsx b/src/mobile/components/pages/DocEditPage.tsx index 98d65fda4c..382038b4b3 100644 --- a/src/mobile/components/pages/DocEditPage.tsx +++ b/src/mobile/components/pages/DocEditPage.tsx @@ -99,6 +99,7 @@ const Editor = ({ const [shortcodeConvertMenu, setShortcodeConvertMenu] = useState<{ pos: PositionRange cb: Callback + promptLabel?: string } | null>(null) const initialRenderDone = useRef(false) const titleRef = useRef(null) @@ -277,8 +278,8 @@ const Editor = ({ }, }) pasteFormatPlugin(editor, { - openMenu: (pos, cb) => { - setShortcodeConvertMenu({ pos, cb }) + openMenu: (pos, cb, promptLabel) => { + setShortcodeConvertMenu({ pos, cb, promptLabel }) }, closeMenu: () => { setShortcodeConvertMenu(null) @@ -295,6 +296,8 @@ const Editor = ({ return { replacement: `[[ ${entityType} id="${org}/${repo}#${num}" ]]`, promptMenu: true, + promptLabel: + type === 'pull' ? 'Embed Pull Request?' : 'Embed Issue?', } } } @@ -586,6 +589,9 @@ const Editor = ({ /> {shortcodeConvertMenu !== null && ( + {shortcodeConvertMenu.promptLabel != null && ( +

{shortcodeConvertMenu.promptLabel}

+ )} @@ -649,6 +655,19 @@ const StyledShortcodeConvertMenu = styled.div` margin-top: ${({ theme }) => theme.sizes.spaces.xsm}px; border-radius: 5px; + p { + margin: 0; + width: 200px; + line-height: 25px; + padding: ${({ theme }) => theme.sizes.spaces.xsm}px + ${({ theme }) => theme.sizes.spaces.sm}px; + background-color: ${({ theme }) => theme.colors.variants.primary.base}; + color: ${({ theme }) => theme.colors.variants.primary.text}; + font-size: ${({ theme }) => theme.sizes.fonts.sm}px; + border-radius: 5px 5px 0 0; + border-bottom: solid 1px ${({ theme }) => theme.colors.background.quaternary}; + } + button { display: block; width: 200px; @@ -660,7 +679,7 @@ const StyledShortcodeConvertMenu = styled.div` font-size: ${({ theme }) => theme.sizes.fonts.sm}px; text-align: left; - &:first-child { + &:first-of-type { border-radius: 5px 5px 0 0; }