forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkTrigger.m
90 lines (75 loc) · 2.19 KB
/
MarkTrigger.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// MarkTrigger.m
// iTerm
//
// Created by George Nachman on 4/22/14.
//
//
#import "MarkTrigger.h"
#import "PTYScrollView.h"
#import "PTYSession.h"
#import "SessionView.h"
// Whether to stop scrolling.
typedef enum {
kMarkTriggerParamTagKeepScrolling,
kMarkTriggerParamTagStopScrolling,
} MarkTriggerParam;
@implementation MarkTrigger
+ (NSString *)title {
return @"Set Mark";
}
- (NSString *)triggerOptionalParameterPlaceholderWithInterpolation:(BOOL)interpolation {
return @"";
}
- (BOOL)takesParameter {
return YES;
}
- (BOOL)paramIsPopupButton {
return YES;
}
- (NSInteger)indexForObject:(id)object {
int i = 0;
for (NSNumber *n in [self objectsSortedByValueInDict:[self menuItemsForPoupupButton]]) {
if ([n isEqual:object]) {
return i;
}
i++;
}
return -1;
}
- (id)objectAtIndex:(NSInteger)index {
int i = 0;
for (NSNumber *n in [self objectsSortedByValueInDict:[self menuItemsForPoupupButton]]) {
if (i == index) {
return n;
}
i++;
}
return nil;
}
- (NSDictionary *)menuItemsForPoupupButton
{
return @{ @(kMarkTriggerParamTagKeepScrolling): @"Keep Scrolling",
@(kMarkTriggerParamTagStopScrolling): @"Stop Scrolling" };
}
- (BOOL)shouldStopScrolling {
return [self.param intValue] == kMarkTriggerParamTagStopScrolling;
}
- (BOOL)performActionWithCapturedStrings:(NSString *const *)capturedStrings
capturedRanges:(const NSRange *)capturedRanges
captureCount:(NSInteger)captureCount
inSession:(PTYSession *)aSession
onString:(iTermStringLine *)stringLine
atAbsoluteLineNumber:(long long)lineNumber
useInterpolation:(BOOL)useInterpolation
stop:(BOOL *)stop {
[aSession.screen terminalSaveScrollPositionWithArgument:@"saveCursorLine"];
if ([self shouldStopScrolling]) {
[[aSession.view.scrollview ptyVerticalScroller] setUserScroll:YES];
}
return YES;
}
- (int)defaultIndex {
return [self indexForObject:@(kMarkTriggerParamTagKeepScrolling)];
}
@end