@@ -5,6 +5,8 @@ import { RectangleSlideEffect } from "@/core/service/feedbackService/effectEngin
55import { ViewFlashEffect } from "@/core/service/feedbackService/effectEngine/concrete/ViewFlashEffect" ;
66import { ViewOutlineFlashEffect } from "@/core/service/feedbackService/effectEngine/concrete/ViewOutlineFlashEffect" ;
77import { Settings } from "@/core/service/Settings" ;
8+ import { Themes } from "@/core/service/Themes" ;
9+ import { StageStyle } from "@/core/service/feedbackService/stageStyle/stageStyle" ;
810import { PenStrokeMethods } from "@/core/stage/stageManager/basicMethods/PenStrokeMethods" ;
911import { ConnectableEntity } from "@/core/stage/stageObject/abstract/ConnectableEntity" ;
1012import { MultiTargetUndirectedEdge } from "@/core/stage/stageObject/association/MutiTargetUndirectedEdge" ;
@@ -591,24 +593,57 @@ export class KeyBindsRegistrar {
591593 } ) ;
592594
593595 // 主题切换相关功能
596+ // 创建一个可以在非React环境中使用的setter函数
597+ const setTheme = ( theme : string ) => {
598+ // 直接使用Settings的原始set方法
599+ Settings . theme = theme ;
600+
601+ // 确保主题CSS立即应用到UI
602+ let styleEl = document . querySelector ( "#pg-theme" ) ;
603+ if ( ! styleEl ) {
604+ styleEl = document . createElement ( "style" ) ;
605+ styleEl . id = "pg-theme" ;
606+ document . head . appendChild ( styleEl ) ;
607+ }
608+ styleEl . innerHTML = `
609+ :root {
610+ ${ Themes . convertThemeToCSS ( Themes . getThemeById ( theme ) ?. content ) }
611+ }
612+ ` ;
613+
614+ // 手动更新StageStyleManager,确保Canvas层样式同步更新
615+ const stageStyleManager = this . project . getService ( "stageStyleManager" ) ;
616+ if ( stageStyleManager ) {
617+ stageStyleManager . currentStyle = StageStyle . styleFromTheme ( theme ) ;
618+ }
619+
620+ // 触发项目重绘,确保Canvas立即更新
621+ this . project . loop ( ) ;
622+ } ;
623+
594624 await this . project . keyBinds . create ( "switchToDarkTheme" , "b l a c k k" , ( ) => {
595- Settings . theme = "dark" ;
625+ toast . info ( "切换到暗黑主题" ) ;
626+ setTheme ( "dark" ) ;
596627 } ) ;
597628
598629 await this . project . keyBinds . create ( "switchToLightTheme" , "w h i t e e" , ( ) => {
599- Settings . theme = "light" ;
630+ toast . info ( "切换到明亮主题" ) ;
631+ setTheme ( "light" ) ;
600632 } ) ;
601633
602634 await this . project . keyBinds . create ( "switchToParkTheme" , "p a r k k" , ( ) => {
603- Settings . theme = "park" ;
635+ toast . info ( "切换到公园主题" ) ;
636+ setTheme ( "park" ) ;
604637 } ) ;
605638
606639 await this . project . keyBinds . create ( "switchToMacaronTheme" , "m k l" , ( ) => {
607- Settings . theme = "macaron" ;
640+ toast . info ( "切换到马卡龙主题" ) ;
641+ setTheme ( "macaron" ) ;
608642 } ) ;
609643
610644 await this . project . keyBinds . create ( "switchToMorandiTheme" , "m l d" , ( ) => {
611- Settings . theme = "morandi" ;
645+ toast . info ( "切换到莫兰迪主题" ) ;
646+ setTheme ( "morandi" ) ;
612647 } ) ;
613648
614649 // 画笔相关快捷键
0 commit comments