Skip to content

Commit f7c4ef2

Browse files
authored
Merge pull request #417 from ichizok/fix/timer-feedkeys
Fix job/channel/timer handling
2 parents ca82514 + c8b6fd5 commit f7c4ef2

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/MacVim/MMBackend.m

Lines changed: 40 additions & 1 deletion
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

@@ -679,13 +682,26 @@ - (BOOL)waitForInput:(int)milliseconds
679682

680683
// Only start the run loop if the input queue is empty, otherwise process
681684
// the input first so that the input on queue isn't delayed.
682-
if ([inputQueue count]) {
685+
if ([inputQueue count] || input_available()) {
683686
inputReceived = YES;
684687
} else {
685688
// Wait for the specified amount of time, unless 'milliseconds' is
686689
// negative in which case we wait "forever" (1e6 seconds translates to
687690
// approximately 11 days).
688691
CFTimeInterval dt = (milliseconds >= 0 ? .001*milliseconds : 1e6);
692+
NSTimer *timer = nil;
693+
694+
// Set interval timer which checks for the events of job and channel
695+
// when there is any pending job or channel.
696+
if (dt > 0.1 && (has_any_channel() || has_pending_job())) {
697+
timer = [NSTimer scheduledTimerWithTimeInterval:0.1
698+
target:self
699+
selector:@selector(checkForProcessEvents:)
700+
userInfo:nil
701+
repeats:YES];
702+
[[NSRunLoop currentRunLoop] addTimer:timer
703+
forMode:NSDefaultRunLoopMode];
704+
}
689705

690706
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, dt, true)
691707
== kCFRunLoopRunHandledSource) {
@@ -695,6 +711,11 @@ - (BOOL)waitForInput:(int)milliseconds
695711
dt = 0.0;
696712
inputReceived = YES;
697713
}
714+
715+
if (input_available())
716+
inputReceived = YES;
717+
718+
[timer invalidate];
698719
}
699720

700721
// The above calls may have placed messages on the input queue so process
@@ -3004,6 +3025,24 @@ - (void)bevalCallback:(id)sender
30043025
}
30053026
#endif
30063027

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

30093048

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)