@@ -24,6 +24,7 @@ async function tryOnEditContent(e) {
24
24
e . preventDefault ( ) ;
25
25
showElem ( renderContent ) ;
26
26
hideElem ( editContentZone ) ;
27
+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
27
28
comboMarkdownEditor . dropzoneReloadFiles ( ) ;
28
29
} ;
29
30
@@ -32,6 +33,7 @@ async function tryOnEditContent(e) {
32
33
renderContent . classList . add ( 'is-loading' ) ;
33
34
showElem ( renderContent ) ;
34
35
hideElem ( editContentZone ) ;
36
+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
35
37
try {
36
38
const params = new URLSearchParams ( {
37
39
content : comboMarkdownEditor . value ( ) ,
@@ -82,6 +84,7 @@ async function tryOnEditContent(e) {
82
84
// Show write/preview tab and copy raw content as needed
83
85
showElem ( editContentZone ) ;
84
86
hideElem ( renderContent ) ;
87
+ window . addEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
85
88
86
89
comboMarkdownEditor = getComboMarkdownEditor ( editContentZone . querySelector ( '.combo-markdown-editor' ) ) ;
87
90
if ( ! comboMarkdownEditor ) {
@@ -148,6 +151,11 @@ async function tryOnQuoteReply(e) {
148
151
editor . moveCursorToEnd ( ) ;
149
152
}
150
153
154
+ // Show a warning message when the user tries to navigate, even though he is currently editing
155
+ function showUserHintOnNavigate ( e : BeforeUnloadEvent ) {
156
+ e . preventDefault ( ) ;
157
+ }
158
+
151
159
export function initRepoIssueCommentEdit ( ) {
152
160
document . addEventListener ( 'click' , ( e ) => {
153
161
tryOnEditContent ( e ) ; // Edit issue or comment content
0 commit comments