@@ -7,12 +7,14 @@ import {
77 getAllEditor ,
88 openTab ,
99 getAllModels ,
10+ Custom ,
1011} from "siyuan" ;
1112import "@/index.scss" ;
1213import PluginInfoString from '@/../plugin.json' ;
1314import {
1415 getImageSizeFromBase64 ,
1516 locatePNGtEXt ,
17+ insertPNGpHYs ,
1618 replaceSubArray ,
1719 arrayToBase64 ,
1820 base64ToArray ,
@@ -22,6 +24,7 @@ import {
2224 dataURLToBlob ,
2325 HTMLToElement ,
2426} from "./utils" ;
27+ import { matchHotKey } from "./utils/hotkey" ;
2528import defaultImageContent from "@/default.json" ;
2629
2730let PluginInfo = {
@@ -444,11 +447,52 @@ export default class DrawioPlugin extends Plugin {
444447 } )
445448 }
446449
450+ private getActiveCustomTab ( type : string ) : Custom {
451+ const allCustoms = getAllModels ( ) . custom ;
452+ const activeTabElement = document . querySelector ( ".layout__wnd--active .item--focus" ) ;
453+ if ( activeTabElement ) {
454+ const tabId = activeTabElement . getAttribute ( "data-id" ) ;
455+ for ( const custom of allCustoms as any [ ] ) {
456+ if ( custom . type == this . name + type && custom . tab . headElement ?. getAttribute ( 'data-id' ) == tabId ) {
457+ return custom ;
458+ } ;
459+ }
460+ }
461+ return null ;
462+ }
463+
464+ private tabHotKeyEventHandler = ( event : KeyboardEvent , custom ?: Custom ) => {
465+ // 自定义处理方式的快捷键
466+ const isFullscreenHotKey = matchHotKey ( window . siyuan . config . keymap . editor . general . fullscreen . custom , event ) ;
467+ const isCloseTabHotKey = matchHotKey ( window . siyuan . config . keymap . general . closeTab . custom , event ) ;
468+ if ( isFullscreenHotKey || isCloseTabHotKey ) {
469+ if ( ! custom ) custom = this . getActiveCustomTab ( this . EDIT_TAB_TYPE ) ;
470+ if ( custom ) {
471+ event . preventDefault ( ) ;
472+ event . stopPropagation ( ) ;
473+
474+ if ( isFullscreenHotKey ) {
475+ if ( document . fullscreenElement ) {
476+ document . exitFullscreen ( ) ;
477+ } else {
478+ custom . element . requestFullscreen ( ) ;
479+ }
480+ }
481+ if ( isCloseTabHotKey ) {
482+ custom . tab . close ( ) ;
483+ }
484+ }
485+ }
486+ } ;
487+
447488 private globalKeyDownHandler = ( event : KeyboardEvent ) => {
448489 // 如果是在代码编辑器里使用快捷键,则阻止冒泡 https://github.com/YuxinZhaozyx/siyuan-embed-tikz/issues/1
449490 if ( document . activeElement . closest ( ".b3-dialog--open .drawio-edit-dialog" ) ) {
450491 event . stopPropagation ( ) ;
451492 }
493+
494+ // 快捷键
495+ this . tabHotKeyEventHandler ( event ) ;
452496 } ;
453497
454498 public setupEditTab ( ) {
@@ -486,6 +530,7 @@ export default class DrawioPlugin extends Plugin {
486530 postMessage ( {
487531 action : 'export' ,
488532 format : `xml${ imageInfo . format } ` ,
533+ // scale: 1,
489534 } ) ;
490535 }
491536
@@ -544,17 +589,8 @@ export default class DrawioPlugin extends Plugin {
544589 }
545590 } ;
546591
547- const switchFullscreen = ( ) => {
548- if ( document . fullscreenElement ) {
549- document . exitFullscreen ( ) ;
550- } else {
551- this . element . requestFullscreen ( ) ;
552- }
553- }
554592 const keydownEventHandleer = ( event : KeyboardEvent ) => {
555- if ( event . key . toLowerCase ( ) === 'y' && ( event . altKey || event . metaKey ) ) {
556- switchFullscreen ( ) ;
557- }
593+ that . tabHotKeyEventHandler ( event , this ) ;
558594 } ;
559595
560596 window . addEventListener ( "message" , messageEventHandler ) ;
@@ -842,6 +878,13 @@ export default class DrawioPlugin extends Plugin {
842878 base64String = unicodeToBase64 ( svgContent ) ;
843879 imageDataURL = `data:image/svg+xml;base64,${ base64String } ` ;
844880 }
881+ // 设置PNG DPI
882+ // if (imageDataURL.startsWith('data:image/png')) {
883+ // let binaryArray = base64ToArray(imageDataURL.split(',').pop());
884+ // binaryArray = insertPNGpHYs(binaryArray, 96 * 2);
885+ // const base64String = arrayToBase64(binaryArray);
886+ // imageDataURL = `data:image/png;base64,${base64String}`;
887+ // }
845888 // 当图像为空时,使用默认的占位图
846889 const imageSize = getImageSizeFromBase64 ( imageDataURL ) ;
847890 if ( imageSize && imageSize . width <= 1 && imageSize . height <= 1 ) {
0 commit comments