@@ -24,6 +24,7 @@ async function tryOnEditContent(e) {
2424 e . preventDefault ( ) ;
2525 showElem ( renderContent ) ;
2626 hideElem ( editContentZone ) ;
27+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
2728 comboMarkdownEditor . dropzoneReloadFiles ( ) ;
2829 } ;
2930
@@ -32,6 +33,7 @@ async function tryOnEditContent(e) {
3233 renderContent . classList . add ( 'is-loading' ) ;
3334 showElem ( renderContent ) ;
3435 hideElem ( editContentZone ) ;
36+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
3537 try {
3638 const params = new URLSearchParams ( {
3739 content : comboMarkdownEditor . value ( ) ,
@@ -82,6 +84,7 @@ async function tryOnEditContent(e) {
8284 // Show write/preview tab and copy raw content as needed
8385 showElem ( editContentZone ) ;
8486 hideElem ( renderContent ) ;
87+ window . addEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
8588
8689 comboMarkdownEditor = getComboMarkdownEditor ( editContentZone . querySelector ( '.combo-markdown-editor' ) ) ;
8790 if ( ! comboMarkdownEditor ) {
@@ -148,6 +151,11 @@ async function tryOnQuoteReply(e) {
148151 editor . moveCursorToEnd ( ) ;
149152}
150153
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+
151159export function initRepoIssueCommentEdit ( ) {
152160 document . addEventListener ( 'click' , ( e ) => {
153161 tryOnEditContent ( e ) ; // Edit issue or comment content
0 commit comments