Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cloud/components/DocPreview/DocPreviewRealtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const DocPreviewRealtime = ({
Dismiss
</button>
<button onClick={() => shortcodeConvertMenu.cb(true)}>
Create embed
{shortcodeConvertMenu.actionLabel ?? 'Create embed'}
</button>
</StyledShortcodeConvertMenu>
)}
Expand Down
9 changes: 6 additions & 3 deletions src/cloud/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const Editor = ({
const [shortcodeConvertMenu, setShortcodeConvertMenu] = useState<{
pos: PositionRange
cb: Callback
actionLabel?: string
} | null>(null)
const initialRenderDone = useRef(false)
const { docsMap, workspacesMap, loadDoc } = useNav()
Expand Down Expand Up @@ -392,8 +393,8 @@ const Editor = ({
},
})
pasteFormatPlugin(editor, {
openMenu: (pos, cb) => {
setShortcodeConvertMenu({ pos, cb })
openMenu: (pos, cb, actionLabel) => {
setShortcodeConvertMenu({ pos, cb, actionLabel })
},
closeMenu: () => {
setShortcodeConvertMenu(null)
Expand All @@ -410,6 +411,8 @@ const Editor = ({
return {
replacement: `[[ ${entityType} id="${org}/${repo}#${num}" ]]`,
promptMenu: true,
actionLabel:
type === 'pull' ? 'Embed pull request' : 'Embed issue',
}
}
}
Expand Down Expand Up @@ -1035,7 +1038,7 @@ const Editor = ({
Dismiss
</button>
<button onClick={() => shortcodeConvertMenu.cb(true)}>
Create embed
{shortcodeConvertMenu.actionLabel ?? 'Create embed'}
</button>
</StyledShortcodeConvertMenu>
)}
Expand Down
11 changes: 8 additions & 3 deletions src/cloud/lib/editor/plugins/pasteFormatPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ export type Callback = (convert: boolean) => void
type FormatterResult = {
replacement: string | null
promptMenu: boolean
actionLabel?: string
}

interface Config {
openMenu: (position: PositionRange, callback: Callback) => void
openMenu: (
position: PositionRange,
callback: Callback,
actionLabel?: string
) => void
closeMenu: () => void
formatter: (pasted: string[]) => FormatterResult
}
Expand Down Expand Up @@ -53,7 +58,7 @@ export const pasteFormatPlugin = (
return
}

const { replacement, promptMenu } = formatter(change.text)
const { replacement, promptMenu, actionLabel } = formatter(change.text)

if (replacement === null) {
return
Expand All @@ -78,7 +83,7 @@ export const pasteFormatPlugin = (
close()
}

openMenu(posRange, callback)
openMenu(posRange, callback, actionLabel)
open = true
})
}
7 changes: 5 additions & 2 deletions src/cloud/lib/hooks/editor/docEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function useDocEditor({
const [shortcodeConvertMenu, setShortcodeConvertMenu] = useState<{
pos: PositionRange
cb: Callback
actionLabel?: string
} | null>(null)
const suggestionsRef = useRef<Hint[]>([])
const { loadDoc } = useNav()
Expand Down Expand Up @@ -220,8 +221,8 @@ export function useDocEditor({
},
})
pasteFormatPlugin(editor, {
openMenu: (pos, cb) => {
setShortcodeConvertMenu({ pos, cb })
openMenu: (pos, cb, actionLabel) => {
setShortcodeConvertMenu({ pos, cb, actionLabel })
},
closeMenu: () => {
setShortcodeConvertMenu(null)
Expand All @@ -238,6 +239,8 @@ export function useDocEditor({
return {
replacement: `[[ ${entityType} id="${org}/${repo}#${num}" ]]`,
promptMenu: true,
actionLabel:
type === 'pull' ? 'Embed pull request' : 'Embed issue',
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/mobile/components/pages/DocEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const Editor = ({
const [shortcodeConvertMenu, setShortcodeConvertMenu] = useState<{
pos: PositionRange
cb: Callback
actionLabel?: string
} | null>(null)
const initialRenderDone = useRef(false)
const titleRef = useRef<HTMLInputElement>(null)
Expand Down Expand Up @@ -277,8 +278,8 @@ const Editor = ({
},
})
pasteFormatPlugin(editor, {
openMenu: (pos, cb) => {
setShortcodeConvertMenu({ pos, cb })
openMenu: (pos, cb, actionLabel) => {
setShortcodeConvertMenu({ pos, cb, actionLabel })
},
closeMenu: () => {
setShortcodeConvertMenu(null)
Expand All @@ -295,6 +296,8 @@ const Editor = ({
return {
replacement: `[[ ${entityType} id="${org}/${repo}#${num}" ]]`,
promptMenu: true,
actionLabel:
type === 'pull' ? 'Embed pull request' : 'Embed issue',
}
}
}
Expand Down Expand Up @@ -590,7 +593,7 @@ const Editor = ({
Dismiss
</button>
<button onClick={() => shortcodeConvertMenu.cb(true)}>
Create embed
{shortcodeConvertMenu.actionLabel ?? 'Create embed'}
</button>
</StyledShortcodeConvertMenu>
)}
Expand Down