Skip to content

Commit db23cf1

Browse files
committed
feat(clear): add confirmation dialog before clearing
1 parent 2358e31 commit db23cf1

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) {

src/js/editor/jsonEditor.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff 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

src/js/ui/editorToolbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) => {

0 commit comments

Comments
 (0)