@@ -13,10 +13,10 @@ async function tryOnEditContent(e: DOMEvent<MouseEvent>) {
13
13
if ( ! clickTarget ) return ;
14
14
15
15
e . preventDefault ( ) ;
16
- const segment = clickTarget . closest ( '.comment-header' ) . nextElementSibling ;
17
- const editContentZone = segment . querySelector ( '.edit-content-zone' ) ;
18
- const renderContent = segment . querySelector ( '.render-content' ) ;
19
- const rawContent = segment . querySelector ( '.raw-content' ) ;
16
+ const commentContent = clickTarget . closest ( '.comment-header' ) . nextElementSibling ;
17
+ const editContentZone = commentContent . querySelector ( '.edit-content-zone' ) ;
18
+ let renderContent = commentContent . querySelector ( '.render-content' ) ;
19
+ const rawContent = commentContent . querySelector ( '.raw-content' ) ;
20
20
21
21
let comboMarkdownEditor : ComboMarkdownEditor ;
22
22
@@ -47,30 +47,32 @@ async function tryOnEditContent(e: DOMEvent<MouseEvent>) {
47
47
48
48
const response = await POST ( editContentZone . getAttribute ( 'data-update-url' ) , { data : params } ) ;
49
49
const data = await response . json ( ) ;
50
- if ( response . status === 400 ) {
51
- showErrorToast ( data . errorMessage ) ;
50
+ if ( ! response . ok ) {
51
+ showErrorToast ( data ? .errorMessage ?? window . config . i18n . error_occurred ) ;
52
52
return ;
53
53
}
54
+
54
55
reinitializeAreYouSure ( editContentZone . querySelector ( 'form' ) ) ; // the form is no longer dirty
55
56
editContentZone . setAttribute ( 'data-content-version' , data . contentVersion ) ;
56
- if ( ! data . content ) {
57
- renderContent . innerHTML = document . querySelector ( '#no-content' ) . innerHTML ;
58
- rawContent . textContent = '' ;
59
- } else {
60
- renderContent . innerHTML = data . content ;
61
- rawContent . textContent = comboMarkdownEditor . value ( ) ;
62
- const refIssues = renderContent . querySelectorAll < HTMLElement > ( 'p .ref-issue' ) ;
63
- attachRefIssueContextPopup ( refIssues ) ;
64
- }
65
- const content = segment ;
66
- if ( ! content . querySelector ( '.dropzone-attachments' ) ) {
57
+
58
+ // replace the render content with new one, to trigger re-initialization of all features
59
+ const newRenderContent = renderContent . cloneNode ( false ) as HTMLElement ;
60
+ newRenderContent . innerHTML = data . content ;
61
+ renderContent . replaceWith ( newRenderContent ) ;
62
+ renderContent = newRenderContent ;
63
+
64
+ rawContent . textContent = comboMarkdownEditor . value ( ) ;
65
+ const refIssues = renderContent . querySelectorAll < HTMLElement > ( 'p .ref-issue' ) ;
66
+ attachRefIssueContextPopup ( refIssues ) ;
67
+
68
+ if ( ! commentContent . querySelector ( '.dropzone-attachments' ) ) {
67
69
if ( data . attachments !== '' ) {
68
- content . insertAdjacentHTML ( 'beforeend' , data . attachments ) ;
70
+ commentContent . insertAdjacentHTML ( 'beforeend' , data . attachments ) ;
69
71
}
70
72
} else if ( data . attachments === '' ) {
71
- content . querySelector ( '.dropzone-attachments' ) . remove ( ) ;
73
+ commentContent . querySelector ( '.dropzone-attachments' ) . remove ( ) ;
72
74
} else {
73
- content . querySelector ( '.dropzone-attachments' ) . outerHTML = data . attachments ;
75
+ commentContent . querySelector ( '.dropzone-attachments' ) . outerHTML = data . attachments ;
74
76
}
75
77
comboMarkdownEditor . dropzoneSubmitReload ( ) ;
76
78
} catch ( error ) {
0 commit comments