From dda9230c6cc8e4dbc5804ad0d04fb8900f680ec2 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 14 Apr 2023 09:56:44 +0100 Subject: [PATCH] [rich text] Add "Insert Citation" and "Insert Cross-reference" buttons (#12529) GitOrigin-RevId: fde2f1a281318afede138ccae12f73ade3fa9f65 --- .../web/frontend/extracted-translations.json | 2 ++ .../components/toolbar/toolbar-items.tsx | 12 ++++++++++++ .../source-editor/extensions/toolbar/commands.ts | 16 ++++++++++++++++ .../source-editor/extensions/toolbar/snippets.ts | 2 ++ services/web/locales/en.json | 2 ++ 5 files changed, 34 insertions(+) diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index b405e945d9..df0b7f20c4 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -867,6 +867,8 @@ "toolbar_format_bold": "", "toolbar_format_italic": "", "toolbar_increase_indent": "", + "toolbar_insert_citation": "", + "toolbar_insert_cross_reference": "", "toolbar_insert_display_math": "", "toolbar_insert_figure": "", "toolbar_insert_inline_math": "", diff --git a/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx b/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx index 2725013d91..63aa9ddba5 100644 --- a/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx +++ b/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx @@ -129,6 +129,18 @@ export const ToolbarItems: FC<{ command={commands.wrapInHref} icon="link" /> + + { return true } +export const insertCite: Command = view => { + const { state, dispatch } = view + const pos = state.selection.main.anchor + const template = snippets.cite + snippet(template)({ state, dispatch }, { label: 'Cite' }, pos, pos) + return true +} + +export const insertRef: Command = view => { + const { state, dispatch } = view + const pos = state.selection.main.anchor + const template = snippets.ref + snippet(template)({ state, dispatch }, { label: 'Ref' }, pos, pos) + return true +} + export const indentDecrease: Command = view => { if (minimumListDepthForSelection(view.state) < 2) { return false diff --git a/services/web/frontend/js/features/source-editor/extensions/toolbar/snippets.ts b/services/web/frontend/js/features/source-editor/extensions/toolbar/snippets.ts index 8cc826436a..f912d05669 100644 --- a/services/web/frontend/js/features/source-editor/extensions/toolbar/snippets.ts +++ b/services/web/frontend/js/features/source-editor/extensions/toolbar/snippets.ts @@ -4,4 +4,6 @@ import { prepareSnippetTemplate } from '../../languages/latex/snippets' export const snippets = { figure: prepareSnippetTemplate(environments.get('figure') as string), table: prepareSnippetTemplate(environments.get('table') as string), + cite: prepareSnippetTemplate('\\cite{${}}'), + ref: prepareSnippetTemplate('\\ref{${}}'), } diff --git a/services/web/locales/en.json b/services/web/locales/en.json index c5b2c15856..a4d747bfba 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -1540,6 +1540,8 @@ "toolbar_format_bold": "Format Bold", "toolbar_format_italic": "Format Italic", "toolbar_increase_indent": "Increase Indent", + "toolbar_insert_citation": "Insert Citation", + "toolbar_insert_cross_reference": "Insert Cross-reference", "toolbar_insert_display_math": "Insert Display Math", "toolbar_insert_figure": "Insert Figure", "toolbar_insert_inline_math": "Insert Inline Math",