From d231ac9f06aa5149e538c6583a4f6f21a9a86db4 Mon Sep 17 00:00:00 2001 From: leecason Date: Tue, 5 May 2020 09:34:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20`Print`=20extension=20bind?= =?UTF-8?q?=20`Mod-p`=20keymap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extensions/print.ts | 18 +++++++++++------- src/utils/print.ts | 10 +++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/extensions/print.ts b/src/extensions/print.ts index bb85acc7..8dbb23e6 100644 --- a/src/extensions/print.ts +++ b/src/extensions/print.ts @@ -2,8 +2,8 @@ import { Extension, MenuData } from 'tiptap'; import { CommandFunction } from 'tiptap-commands'; import { MenuBtnView } from '@/../types'; import { t } from '@/i18n/index'; +import { printEditorContent } from '@/utils/print'; import CommandButton from '@/components/MenuCommands/CommandButton.vue'; -import printHtml from '../utils/print'; export default class Print extends Extension implements MenuBtnView { get name () { @@ -12,12 +12,16 @@ export default class Print extends Extension implements MenuBtnView { commands () { return (): CommandFunction => (_state, _dispatch, view) => { - const editorContent = view.dom.closest('.el-tiptap-editor__content'); - if (editorContent) { - printHtml(editorContent); - return true; - } - return false; + return printEditorContent(view); + }; + } + + keys () { + return { + // @ts-ignore + 'Mod-p': (_state, _dispatch, view) => { + return printEditorContent(view); + }, }; } diff --git a/src/utils/print.ts b/src/utils/print.ts index d7715da2..b0919dd5 100644 --- a/src/utils/print.ts +++ b/src/utils/print.ts @@ -1,3 +1,4 @@ +import { EditorView } from 'prosemirror-view'; import Logger from './logger'; function printHtml (dom: Element) { @@ -45,4 +46,11 @@ function printHtml (dom: Element) { } } -export default printHtml; +export function printEditorContent (view: EditorView) { + const editorContent = view.dom.closest('.el-tiptap-editor__content'); + if (editorContent) { + printHtml(editorContent); + return true; + } + return false; +}