File tree Expand file tree Collapse file tree 1 file changed +30
-9
lines changed
Expand file tree Collapse file tree 1 file changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -205,28 +205,49 @@ class Yata {
205205 // 何も表示されない
206206 // †最大の闇†
207207
208- let id = this . cmRefreshTimers . size
209- while ( true ) {
210- ++ id
211- if ( ! this . cmRefreshTimers . has ( id ) ) {
208+ let id = 0
209+ // より安全なID生成方法に変更
210+ for ( let i = 0 ; i <= this . cmRefreshTimers . size + 1 ; i ++ ) {
211+ if ( ! this . cmRefreshTimers . has ( i ) ) {
212+ id = i
212213 break
213214 }
214215 }
216+
215217 let info = new RefreshTimerInfo ( id )
216218 this . log . debug ( `autoRefresh engaged (id: #${ id } )` )
217219 this . cmRefreshTimers . set ( id , info )
218220
219- this . cmRefreshTimers . get ( id ) . realID = setInterval ( ( e ) => {
221+ const timerId = setInterval ( ( ) => {
222+ // infoがまだ存在するか確認
223+ if ( ! this . cmRefreshTimers . has ( id ) ) {
224+ clearInterval ( timerId )
225+ return
226+ }
227+
220228 ++ info . count
221- this . cm . refresh ( )
229+
230+ // CodeMirrorインスタンスが有効か確認
231+ if ( this . cm && typeof this . cm . refresh === 'function' ) {
232+ try {
233+ this . cm . refresh ( )
234+ } catch ( e ) {
235+ this . log . error ( `Failed to refresh CodeMirror: ${ e } ` )
236+ clearInterval ( timerId )
237+ this . cmRefreshTimers . delete ( id )
238+ return
239+ }
240+ }
222241
223242 if ( info . count > 10 ) {
243+ this . log . debug ( `removing autoRefresh timer (id: #${ id } , realID: #${ timerId } )` )
244+ clearInterval ( timerId )
224245 this . cmRefreshTimers . delete ( id )
225-
226- this . log . debug ( `removing autoRefresh timer (id: #${ id } , realID: #${ info . realID } )` )
227- clearInterval ( info . realID )
228246 }
229247 } , 200 )
248+
249+ // タイマーIDを保存
250+ info . realID = timerId
230251 }
231252
232253 onResize ( e ) {
You can’t perform that action at this time.
0 commit comments