@@ -41,6 +41,24 @@ export default class CommitViewController {
4141
4242 this . subscriptions = new CompositeDisposable ( ) ;
4343 etch . initialize ( this ) ;
44+ this . subscriptions . add (
45+ this . props . workspace . onDidAddTextEditor ( ( { textEditor} ) => {
46+ if ( textEditor . getPath ( ) === this . getCommitMessagePath ( ) ) {
47+ const grammar = this . props . grammars . grammarForScopeName ( COMMIT_GRAMMAR_SCOPE ) ;
48+ if ( grammar ) {
49+ textEditor . setGrammar ( grammar ) ;
50+ }
51+ }
52+ etch . update ( this ) ;
53+ } ) ,
54+ this . props . workspace . onDidDestroyPaneItem ( async ( { item} ) => {
55+ if ( item . getPath ( ) === this . getCommitMessagePath ( ) && this . getCommitMessageEditors ( ) . length === 0 ) {
56+ // we closed the last editor pointing to the commit message file
57+ this . regularCommitMessage = await readFile ( this . getCommitMessagePath ( ) ) ;
58+ etch . update ( this ) ;
59+ }
60+ } ) ,
61+ ) ;
4462 }
4563
4664 update ( props ) {
@@ -80,15 +98,15 @@ export default class CommitViewController {
8098 onChangeMessage = { this . handleMessageChange }
8199 didMoveUpOnFirstLine = { this . props . didMoveUpOnFirstLine }
82100 openCommitEditor = { this . openCommitEditor }
83- deactivateCommitBox = { ! ! this . commitEditor }
101+ deactivateCommitBox = { ! ! this . getCommitMessageEditors ( ) . length > 0 }
84102 />
85103 ) ;
86104 }
87105
88106 @autobind
89107 async commit ( message ) {
90108 try {
91- if ( this . commitEditor ) {
109+ if ( this . getCommitMessageEditors ( ) . length > 0 ) {
92110 await this . props . commit ( { filePath : this . getCommitMessagePath ( ) } ) ;
93111 } else {
94112 await this . props . commit ( message ) ;
@@ -125,50 +143,49 @@ export default class CommitViewController {
125143 etch . update ( this ) ;
126144 }
127145
146+ getCommitMessageEditors ( ) {
147+ if ( ! this . props . repository . isPresent ( ) ) {
148+ return [ ] ;
149+ }
150+ return this . props . workspace . getTextEditors ( ) . filter ( editor => editor . getPath ( ) === this . getCommitMessagePath ( ) ) ;
151+ }
152+
128153 activateCommitEditor ( ) {
129154 const panes = this . props . workspace . getPanes ( ) ;
155+ let editor ;
130156 const paneWithEditor = panes . find ( pane => {
131- const editor = pane . getItems ( ) . find ( item => item === this . commitEditor ) ;
157+ editor = pane . getItems ( ) . find ( item => item . getPath && item . getPath ( ) === this . getCommitMessagePath ( ) ) ;
132158 return ! ! editor ;
133159 } ) ;
134160 paneWithEditor . activate ( ) ;
135- paneWithEditor . activateItem ( this . commitEditor ) ;
161+ paneWithEditor . activateItem ( editor ) ;
136162 }
137163
138164 @autobind
139165 async openCommitEditor ( messageFromBox ) {
140- if ( this . commitEditor ) {
166+ if ( this . getCommitMessageEditors ( ) . length > 0 ) {
141167 this . activateCommitEditor ( ) ;
142168 return ;
143169 }
144170
145- this . commitEditor = await this . props . workspace . open ( this . getCommitMessagePath ( ) ) ;
146- this . commitEditor . setText ( messageFromBox ) ;
171+ const commitEditor = await this . props . workspace . open ( this . getCommitMessagePath ( ) ) ;
172+ commitEditor . setText ( messageFromBox ) ;
147173
148174 const grammar = this . props . grammars . grammarForScopeName ( COMMIT_GRAMMAR_SCOPE ) ;
149175 if ( grammar ) {
150- this . commitEditor . setGrammar ( grammar ) ;
176+ commitEditor . setGrammar ( grammar ) ;
151177 } else {
152178 this . grammarSubscription = this . props . grammars . onDidAddGrammar ( this . grammarAdded ) ;
153179 this . subscriptions . add ( this . grammarSubscription ) ;
154180 }
155181 etch . update ( this ) ;
156-
157- this . editorSubscription = this . commitEditor . onDidDestroy ( async ( ) => {
158- this . commitEditor = null ;
159- const contents = await readFile ( this . getCommitMessagePath ( ) ) ;
160- this . regularCommitMessage = contents ;
161- this . editorSubscription . dispose ( ) ;
162- etch . update ( this ) ;
163- } ) ;
164- this . subscriptions . add ( this . editorSubscription ) ;
165182 }
166183
167184 @autobind
168185 grammarAdded ( grammar ) {
169186 if ( grammar . scopeName !== COMMIT_GRAMMAR_SCOPE ) { return ; }
170187
171- this . commitEditor . setGrammar ( grammar ) ;
188+ this . getCommitMessageEditors ( ) . forEach ( editor => editor . setGrammar ( grammar ) ) ;
172189 this . grammarSubscription . dispose ( ) ;
173190 }
174191
0 commit comments