File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import cssText from './style.css?inline';
1515
1616import type { PluginInterface , PluginInterfaceCtx } from '../types/any-menu' ;
1717
18+ let cache_ctx : PluginInterfaceCtx | undefined
19+
1820export default class ExamplePluginSimple implements PluginInterface {
1921 metadata = {
2022 id : 'example-plugin-simple' ,
@@ -32,12 +34,23 @@ export default class ExamplePluginSimple implements PluginInterface {
3234 }
3335
3436 onUnload ( ) : void {
37+ if ( cache_ctx ) cache_ctx . api . unregisterSubPanel ( 'example-plugin-simple-panel' )
3538 console . log ( '[ExamplePluginSimple] Plugin unloaded' ) ;
3639 }
3740
3841 async run ( ctx : PluginInterfaceCtx ) : Promise < void > {
39- const selected = ctx . env . selectedText ;
42+ // 注册面板示例
43+ if ( ! cache_ctx ) {
44+ cache_ctx = ctx
45+ const newPanel = document . createElement ( 'div' ) ; newPanel . innerText = 'New Panel Content' ;
46+ ctx . api . registerSubPanel ( {
47+ id : 'example-plugin-simple-panel' ,
48+ el : newPanel
49+ } )
50+ }
4051
52+ // 文本输出示例
53+ const selected = ctx . env . selectedText ;
4154 if ( selected ) {
4255 // 如果有选中文本,在其后追加问候
4356 ctx . api . sendText ( `${ selected } — Hello World!` ) ;
You can’t perform that action at this time.
0 commit comments