Skip to content

Commit

Permalink
feat: ✨ Print extension bind Mod-p keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
Leecason committed May 5, 2020
1 parent 644d3dd commit d231ac9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/extensions/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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);
},
};
}

Expand Down
10 changes: 9 additions & 1 deletion src/utils/print.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EditorView } from 'prosemirror-view';
import Logger from './logger';

function printHtml (dom: Element) {
Expand Down Expand Up @@ -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;
}

0 comments on commit d231ac9

Please sign in to comment.