File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ const App = {
156156 this . activeEditor ?. copyToClipboard ( ) ;
157157 } ,
158158 clear ( ) {
159- this . activeEditor ?. clear ( ) ;
159+ this . activeEditor ?. confirmClear ( ) ;
160160 } ,
161161
162162 switchMode ( mode ) {
Original file line number Diff line number Diff line change @@ -589,8 +589,31 @@ class JsonEditor {
589589 }
590590 }
591591
592+ async confirmClear ( ) {
593+ const content = this . getValue ( ) ;
594+ if ( ! content || content . trim ( ) === '' || content . trim ( ) === '{}' || content . trim ( ) === '[]' ) {
595+ this . clear ( ) ;
596+ return ;
597+ }
598+
599+ if ( window . Modal ) {
600+ const confirmed = await Modal . confirm (
601+ 'Are you sure you want to clear the editor? This action cannot be undone.' ,
602+ 'Clear Editor'
603+ ) ;
604+ if ( confirmed ) {
605+ this . clear ( ) ;
606+ }
607+ } else {
608+ // Fallback if Modal is not available
609+ if ( confirm ( 'Are you sure you want to clear the editor?' ) ) {
610+ this . clear ( ) ;
611+ }
612+ }
613+ }
614+
592615 clear ( ) {
593- this . setValue ( '' ) ;
616+ this . setValue ( '{\n} ' ) ;
594617 }
595618}
596619
Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ class EditorToolbar {
9494 on ( '.btn-undo' , ( ) => this . editor . undo ( ) ) ;
9595 on ( '.btn-redo' , ( ) => this . editor . redo ( ) ) ;
9696 on ( '.btn-copy' , ( ) => this . editor . copyToClipboard ( ) ) ;
97- on ( '.btn-clear' , ( ) => this . editor . clear ( ) ) ;
97+ on ( '.btn-clear' , ( ) => this . editor . confirmClear ( ) ) ;
9898
9999 // Mode tabs
100100 this . element . querySelectorAll ( '.mode-tab' ) . forEach ( ( tab ) => {
You can’t perform that action at this time.
0 commit comments