Skip to content

Commit 28f88ac

Browse files
authored
Merge pull request #406 from ichizok/fix/timer-feedkeys
Fix #401
2 parents 0b0e6b0 + a6d11c7 commit 28f88ac

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/MacVim/MMBackend.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ - (void)handleGesture:(NSData *)data;
198198
#ifdef FEAT_BEVAL
199199
- (void)bevalCallback:(id)sender;
200200
#endif
201+
#ifdef MESSAGE_QUEUE
202+
- (void)checkForProcessEvents:(NSTimer *)timer;
203+
#endif
201204
@end
202205

203206

@@ -682,6 +685,20 @@ - (BOOL)waitForInput:(int)milliseconds
682685
if ([inputQueue count]) {
683686
inputReceived = YES;
684687
} else {
688+
NSTimer *timer = nil;
689+
690+
// Set interval timer which checks for the events of job and channel
691+
// when there is any pending job or channel.
692+
if (has_any_channel() || has_pending_job()) {
693+
timer = [NSTimer scheduledTimerWithTimeInterval:0.1
694+
target:self
695+
selector:@selector(checkForProcessEvents:)
696+
userInfo:nil
697+
repeats:YES];
698+
[[NSRunLoop currentRunLoop] addTimer:timer
699+
forMode:NSDefaultRunLoopMode];
700+
}
701+
685702
// Wait for the specified amount of time, unless 'milliseconds' is
686703
// negative in which case we wait "forever" (1e6 seconds translates to
687704
// approximately 11 days).
@@ -695,6 +712,11 @@ - (BOOL)waitForInput:(int)milliseconds
695712
dt = 0.0;
696713
inputReceived = YES;
697714
}
715+
716+
if (input_available())
717+
inputReceived = YES;
718+
719+
[timer invalidate];
698720
}
699721

700722
// The above calls may have placed messages on the input queue so process
@@ -3004,6 +3026,22 @@ - (void)bevalCallback:(id)sender
30043026
}
30053027
#endif
30063028

3029+
#ifdef MESSAGE_QUEUE
3030+
- (void)checkForProcessEvents:(NSTimer *)timer
3031+
{
3032+
# ifdef FEAT_TIMERS
3033+
did_add_timer = FALSE;
3034+
# endif
3035+
3036+
parse_queued_messages();
3037+
3038+
# ifdef FEAT_TIMERS
3039+
if (did_add_timer || input_available())
3040+
CFRunLoopStop(CFRunLoopGetCurrent());
3041+
# endif
3042+
}
3043+
#endif
3044+
30073045
@end // MMBackend (Private)
30083046

30093047

src/MacVim/gui_macvim.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,21 @@
407407
[[MMBackend sharedInstance] flushQueue:YES];
408408

409409
#ifdef MESSAGE_QUEUE
410+
# ifdef FEAT_TIMERS
411+
did_add_timer = FALSE;
412+
# endif
413+
410414
parse_queued_messages();
415+
416+
# ifdef FEAT_TIMERS
417+
if (did_add_timer)
418+
return FAIL;
419+
# endif
411420
#endif
412421

422+
if (input_available())
423+
return OK;
424+
413425
return [[MMBackend sharedInstance] waitForInput:wtime];
414426
}
415427

src/testdir/test_channel.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ function MyExitTimeCb(job, status)
13961396
endfunction
13971397

13981398
func Test_exit_callback_interval()
1399-
if !has('job') || has('gui_macvim')
1399+
if !has('job')
14001400
return
14011401
endif
14021402

0 commit comments

Comments
 (0)