@@ -2898,7 +2898,7 @@ export default class PluginSnippets extends Plugin {
28982898 void await this . saveSnippetsList ( this . snippetsList ) ;
28992899
29002900 this . setMenuSnippetCount ( ) ;
2901- this . removeSnippetElement ( id , snippetType ) ;
2901+ void this . removeSnippetElement ( id , snippetType ) ;
29022902 this . applySnippetUIChange ( snippet , false ) ;
29032903
29042904 // 广播代码片段数据更新到其他窗口
@@ -2925,7 +2925,7 @@ export default class PluginSnippets extends Plugin {
29252925
29262926 if ( ! previewState ) {
29272927 // 广播窗口没有预览该代码片段的情况下,才移除元素
2928- this . removeSnippetElement ( snippetId , snippetType ) ;
2928+ void this . removeSnippetElement ( snippetId , snippetType ) ;
29292929 }
29302930
29312931 const snippet = this . snippetsList . find ( ( s : Snippet ) => s . id === snippetId ) ;
@@ -3147,13 +3147,18 @@ export default class PluginSnippets extends Plugin {
31473147 * @param snippetId 代码片段 ID
31483148 * @param snippetType 代码片段类型
31493149 */
3150- private removeSnippetElement ( snippetId : string , snippetType : string ) {
3150+ private async removeSnippetElement ( snippetId : string , snippetType : string ) {
31513151 if ( ! snippetId || ! snippetType ) return ;
31523152 // 如果当前窗口正在预览代码片段,则不移除元素
31533153 if ( this . isPreviewingSnippet ( snippetId , snippetType ) ) return ;
31543154
31553155 const elementId = `snippet${ snippetType . toUpperCase ( ) } ${ snippetId } ` ;
31563156 const element = document . getElementById ( elementId ) ;
3157+ // 删除 JS 代码片段需要弹出消息提示:有旧代码 && 旧代码有效
3158+ if ( snippetType === "js" && element && element . innerHTML && this . isValidJavaScriptCode ( element . innerHTML ) ) {
3159+ this . showNotification ( "reloadUIAfterModifyJS" , 4000 ) ;
3160+ await this . setReloadUIButtonBreathing ( ) ;
3161+ }
31573162 element ?. remove ( ) ;
31583163 }
31593164
@@ -3163,7 +3168,7 @@ export default class PluginSnippets extends Plugin {
31633168 */
31643169 private removeSnippetElementSync ( data : { snippetId : string ; snippetType : string } ) {
31653170 const { snippetId, snippetType } = data ;
3166- this . removeSnippetElement ( snippetId , snippetType ) ;
3171+ void this . removeSnippetElement ( snippetId , snippetType ) ;
31673172 }
31683173
31693174 /**
@@ -3661,7 +3666,7 @@ export default class PluginSnippets extends Plugin {
36613666 if ( snippet . type === "css" ) {
36623667 // 退出预览操作,新建的代码片段需要移除元素,已有的代码片段需要恢复原始元素 https://github.com/TCOTC/snippets/issues/26
36633668 if ( isNew ) {
3664- this . removeSnippetElement ( snippet . id , snippet . type ) ;
3669+ void this . removeSnippetElement ( snippet . id , snippet . type ) ;
36653670 // 发送广播消息,在其他窗口调用 this.removeSnippetElementSync() 移除代码片段元素
36663671 this . broadcastMessage ( "snippet_element_remove" , {
36673672 snippetId : snippet . id ,
0 commit comments