@@ -633,40 +633,42 @@ export function initRepoIssueBranchSelect() {
633633export function initSingleCommentEditor ( $commentForm ) {
634634 // pages:
635635 // * normal new issue/pr page, no status-button
636- // * issue/pr view page, with comment form, has status button, and status dropdown
636+ // * issue/pr view page, with comment form, has status button, and/or status dropdown
637637 const $statusButton = $commentForm . find ( '.status-button' ) ;
638638 const $statusDropdown = $commentForm . find ( '.status-dropdown' ) ;
639+ let comboMarkdownEditor ;
639640
640641 // update the status-button's text according to the editor's content
641- const updateStatusButtonByEditor = ( editor ) => {
642- if ( ! editor || ! $statusButton . length ) return ;
643- $statusButton . text ( $statusButton . attr ( editor . value ( ) . trim ( ) ? 'data-status-and-comment' : 'data-status' ) ) ;
642+ const updateStatusButtonText = ( ) => {
643+ if ( ! comboMarkdownEditor || ! $statusButton . length ) return ;
644+ $statusButton . text ( $statusButton . attr ( comboMarkdownEditor . value ( ) . trim ( ) ? 'data-status-and-comment' : 'data-status' ) ) ;
644645 } ;
645646
646647 // update the status-button's text and value according to the selected dropdown's value (close status)
647- const updateStatusButtonByDropdown = ( val ) => {
648+ const updateStatusButtonByCloseStatus = ( val ) => {
648649 if ( ! $statusButton . length ) return ;
649650 const $item = $statusDropdown . dropdown ( 'get item' ) ;
650651 $statusButton . attr ( 'data-status' , $item . attr ( 'data-status' ) ) ;
651652 $statusButton . attr ( 'data-status-and-comment' , $item . attr ( 'data-status-and-comment' ) ) ;
652653 $statusButton . value = val === '-1' ? 'reopen' : 'close' ;
653- const editor = getComboMarkdownEditor ( $ ( '#comment-form .combo-markdown-editor' ) ) ;
654- updateStatusButtonByEditor ( editor ) ;
654+ updateStatusButtonText ( ) ;
655655 } ;
656656
657657 if ( $statusDropdown . length ) {
658658 $statusDropdown . dropdown ( 'setting' , {
659659 selectOnKeydown : false ,
660660 allowReselection : true ,
661- onChange : updateStatusButtonByDropdown ,
661+ onChange : updateStatusButtonByCloseStatus ,
662662 } ) ;
663663 const selectedValue = $statusDropdown . find ( 'input[type=hidden]' ) . val ( ) ;
664664 $statusDropdown . dropdown ( 'set selected' , selectedValue ) ;
665- updateStatusButtonByDropdown ( selectedValue ) ;
665+ updateStatusButtonByCloseStatus ( selectedValue ) ;
666666 }
667667
668- const editorOpts = { onContentChanged : updateStatusButtonByEditor } ;
669- initComboMarkdownEditor ( $commentForm . find ( '.combo-markdown-editor' ) , editorOpts ) . then ( updateStatusButtonByEditor ) ;
668+ const editorOpts = { onContentChanged : updateStatusButtonText } ;
669+ initComboMarkdownEditor ( $commentForm . find ( '.combo-markdown-editor' ) , editorOpts ) . then ( ( editor ) => {
670+ comboMarkdownEditor = editor ;
671+ } ) ;
670672}
671673
672674export function initIssueTemplateCommentEditors ( $commentForm ) {
0 commit comments