Skip to content

Commit

Permalink
Add a link to ICU regex syntax from advanced paste
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Apr 19, 2016
1 parent 2e863ae commit 47f9c2e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 18 deletions.
45 changes: 27 additions & 18 deletions Interfaces/iTermPasteSpecialViewController.xib
Expand Up @@ -16,6 +16,7 @@
<outlet property="_delayBetweenChunksLabel" destination="l9P-RY-F8r" id="EMT-5p-KWq"/>
<outlet property="_delayBetweenChunksSlider" destination="sHW-Ak-i7W" id="a8I-OM-vZc"/>
<outlet property="_escapeShellCharsWithBackslash" destination="jfQ-7z-viz" id="nXK-uy-Mmm"/>
<outlet property="_icuRegexHelpLabel" destination="omm-tD-wpW" id="5Io-oV-tOL"/>
<outlet property="_regex" destination="CaF-jG-U6l" id="gi2-21-Rqr"/>
<outlet property="_removeControlCodes" destination="ILq-w8-PQn" id="Ceg-XA-Wrd"/>
<outlet property="_removeNewlines" destination="I7q-KH-dfd" id="Woc-VB-aQf"/>
Expand All @@ -31,11 +32,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="444" height="322"/>
<rect key="frame" x="0.0" y="0.0" width="444" height="335"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jfQ-7z-viz">
<rect key="frame" x="235" y="215" width="207" height="18"/>
<rect key="frame" x="235" y="228" width="207" height="18"/>
<buttonCell key="cell" type="check" title="Escape shell characters with \" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="geX-hg-c5A">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -45,7 +46,7 @@
</connections>
</button>
<button toolTip="Both DOS and UNIX newlines are generally not used as input. CR is standard." fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FKu-pE-gGN">
<rect key="frame" x="-2" y="215" width="195" height="18"/>
<rect key="frame" x="-2" y="228" width="195" height="18"/>
<buttonCell key="cell" type="check" title="Convert CRLF and LF to CR" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="YGo-el-jcx">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -55,7 +56,7 @@
</connections>
</button>
<button toolTip="Both DOS and UNIX newlines are generally not used as input. CR is standard." fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="I7q-KH-dfd">
<rect key="frame" x="-2" y="195" width="130" height="18"/>
<rect key="frame" x="-2" y="208" width="130" height="18"/>
<buttonCell key="cell" type="check" title="Remove newlines" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="TcS-Fq-kZn">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -65,7 +66,7 @@
</connections>
</button>
<button toolTip="Tab, line feed, form feed, and carriage return are the only “safe” control codes." fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ILq-w8-PQn">
<rect key="frame" x="-2" y="175" width="206" height="18"/>
<rect key="frame" x="-2" y="188" width="206" height="18"/>
<buttonCell key="cell" type="check" title="Remove unsafe control codes" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Nc9-bk-vWI">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -75,7 +76,7 @@
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uDr-nK-EPv">
<rect key="frame" x="-2" y="155" width="124" height="18"/>
<rect key="frame" x="-2" y="168" width="124" height="18"/>
<buttonCell key="cell" type="check" title="Base-64 encode" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="YXc-NP-geE">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -85,7 +86,7 @@
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Y21-ws-jIs">
<rect key="frame" x="-2" y="130" width="71" height="18"/>
<rect key="frame" x="-2" y="143" width="71" height="18"/>
<buttonCell key="cell" type="check" title="Replace" bezelStyle="regularSquare" imagePosition="left" inset="2" id="65A-9c-omm">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -105,7 +106,7 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XlA-dp-B6g">
<rect key="frame" x="-2" y="305" width="78" height="17"/>
<rect key="frame" x="-2" y="318" width="78" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Transforms" id="IOU-ld-y0b">
<font key="font" metaFont="systemBold"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -207,7 +208,7 @@
</textFieldCell>
</textField>
<matrix verticalHuggingPriority="750" fixedFrame="YES" allowsEmptySelection="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kjR-IP-sQB">
<rect key="frame" x="0.0" y="239" width="171" height="58"/>
<rect key="frame" x="0.0" y="252" width="171" height="58"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
<size key="cellSize" width="171" height="18"/>
<size key="intercellSpacing" width="4" height="2"/>
Expand Down Expand Up @@ -236,7 +237,7 @@
</connections>
</matrix>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6tG-RX-FWF">
<rect key="frame" x="235" y="175" width="162" height="18"/>
<rect key="frame" x="235" y="188" width="162" height="18"/>
<string key="toolTip">This is enabled when the running app has sent an escape code to turn on “bracketed paste mode.” The pasted string will be “bracketed” by escape codes indicating the text within is from a paste operation.</string>
<buttonCell key="cell" type="check" title="Bracketed paste mode" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="vTr-f3-LoJ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -255,7 +256,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jbp-75-WqZ">
<rect key="frame" x="174" y="258" width="31" height="22"/>
<rect key="frame" x="174" y="271" width="31" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="100" drawsBackground="YES" id="sRn-9b-46B">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -266,14 +267,14 @@
</connections>
</textField>
<stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5qb-Ed-U2o">
<rect key="frame" x="205" y="255" width="19" height="27"/>
<rect key="frame" x="205" y="268" width="19" height="27"/>
<stepperCell key="cell" continuous="YES" alignment="left" maxValue="100" id="G1E-SH-fLO"/>
<connections>
<action selector="stepperDidChange:" target="-2" id="7bw-dG-m6K"/>
</connections>
</stepper>
<button toolTip="Converts various forms of quotation marks and dashes to their ASCII equivalents." fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="C2O-DY-y76">
<rect key="frame" x="235" y="195" width="203" height="18"/>
<rect key="frame" x="235" y="208" width="203" height="18"/>
<buttonCell key="cell" type="check" title="Convert Unicode punctuation" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="a6z-Q5-O3y">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -291,15 +292,15 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="23L-N3-gDK">
<rect key="frame" x="227" y="132" width="30" height="17"/>
<rect key="frame" x="227" y="145" width="30" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="with" id="M1n-rk-o3M">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="CaF-jG-U6l">
<rect key="frame" x="68" y="129" width="158" height="22"/>
<rect key="frame" x="68" y="142" width="158" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="Regular Expression" drawsBackground="YES" id="Qmg-L3-fKu">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -310,7 +311,7 @@
</connections>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vp8-x8-EjQ">
<rect key="frame" x="258" y="129" width="178" height="22"/>
<rect key="frame" x="258" y="142" width="178" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="Substitution" drawsBackground="YES" id="hpt-tW-eP7">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -321,15 +322,23 @@
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Cx6-wX-Vh5">
<rect key="frame" x="256" y="116" width="182" height="11"/>
<rect key="frame" x="256" y="129" width="182" height="11"/>
<textFieldCell key="cell" controlSize="mini" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Use $1, $2, etc. for capture groups" id="tpG-Jk-bWC">
<font key="font" metaFont="miniSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="omm-tD-wpW">
<rect key="frame" x="66" y="128" width="182" height="12"/>
<textFieldCell key="cell" controlSize="mini" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="ICU regular expression syntax" id="Iuq-a0-6jh">
<font key="font" metaFont="miniSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<point key="canvasLocation" x="183" y="315"/>
<point key="canvasLocation" x="183" y="321.5"/>
</customView>
</objects>
</document>
6 changes: 6 additions & 0 deletions sources/NSTextField+iTerm.h
Expand Up @@ -19,4 +19,10 @@
- (int)separatorTolerantIntValue;
- (NSUInteger)separatorTolerantUnsignedIntegerValue;

// Remove this text field from the view hierarchy and replace it with an identical one that is a
// clickable hyperlink. This works around a bug where changing a text field's attributed string to
// have an underline shifts it down by one point in OS 10.11 (and maybe other versions, I didn't
// check).
- (NSTextField *)replaceWithHyperlinkTo:(NSURL *)url;

@end
26 changes: 26 additions & 0 deletions sources/NSTextField+iTerm.m
Expand Up @@ -46,4 +46,30 @@ - (NSUInteger)separatorTolerantUnsignedIntegerValue {
return [digits iterm_unsignedIntegerValue];
}

- (NSTextField *)replaceWithHyperlinkTo:(NSURL *)url {
NSTextField *link = [[[NSTextField alloc] initWithFrame:self.frame] autorelease];
link.editable = self.editable;
link.drawsBackground = self.drawsBackground;
link.bordered = self.bordered;

// According to Apple these two are needed to make it clickable.
link.allowsEditingTextAttributes = YES;
link.selectable = YES;
NSDictionary *attributes = @{ NSUnderlineStyleAttributeName: @(NSSingleUnderlineStyle),
NSForegroundColorAttributeName: [NSColor colorWithCalibratedRed:0 green:0 blue:0.93 alpha:1],
NSCursorAttributeName: [NSCursor pointingHandCursor],
NSLinkAttributeName: url };
NSMutableAttributedString *attributedString = [[self.attributedStringValue mutableCopy] autorelease];
for (NSString *key in attributes) {
[attributedString addAttribute:key value:attributes[key] range:NSMakeRange(0, [attributedString length])];
}
link.attributedStringValue = attributedString;

NSView *superview = self.superview;
[self removeFromSuperview];
[superview addSubview:link];

return link;
}

@end
5 changes: 5 additions & 0 deletions sources/iTermPasteSpecialViewController.m
Expand Up @@ -7,6 +7,7 @@
//

#import "iTermPasteSpecialViewController.h"
#import "NSTextField+iTerm.h"
#import "PasteEvent.h"

typedef struct {
Expand Down Expand Up @@ -68,6 +69,7 @@ @implementation iTermPasteSpecialViewController {
IBOutlet NSTextField *_chunkSizeLabel;
IBOutlet NSTextField *_delayBetweenChunksLabel;
IBOutlet NSStepper *_stepper;
IBOutlet NSTextField *_icuRegexHelpLabel; // Warning: this gets removed from superview in awakeFromNib.
}

- (instancetype)init {
Expand All @@ -84,6 +86,9 @@ - (void)awakeFromNib {

self.delayBetweenChunks = kDelayRange.visualCenter;
self.chunkSize = kChunkSizeRange.visualCenter;

[_icuRegexHelpLabel replaceWithHyperlinkTo:[NSURL URLWithString:@"https://iterm2.com/regex"]];
_icuRegexHelpLabel = nil;
}

// TODO: When 10.7 support is dropped use NSByteCountFormatter
Expand Down

0 comments on commit 47f9c2e

Please sign in to comment.