Skip to content

Commit

Permalink
Don't attempt to extract a URL from invalid coordinates (-1,-1) if co…
Browse files Browse the repository at this point in the history
…ntext menu is opened from the session titlebar (#434)
  • Loading branch information
anthroid authored and gnachman committed Jan 25, 2021
1 parent 7102048 commit b2ab082
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions sources/iTermTextViewContextMenuHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,18 @@ - (NSMenu *)menuAtCoord:(VT100GridCoord)coord {
@"Context menu")
action:@selector(copy:) keyEquivalent:@""];

iTermTextExtractor *extractor = [self.delegate contextMenuTextExtractor:self];
NSString *urlID;
NSURL *url = [extractor urlOfHypertextLinkAt:coord urlId:&urlID];
if (url) {
NSMenuItem *item = [theMenu addItemWithTitle:@"Copy Link Address" action:@selector(copyLinkAddress:) keyEquivalent:@""];
item.target = self;
item.representedObject = url;
// Don't attempt to extract a URL from invalid coordinates (-1,-1) if opened from the session titlebar
if (coord.x >= 0 && coord.y >= 0) {
iTermTextExtractor *extractor = [self.delegate contextMenuTextExtractor:self];
NSString *urlID;
NSURL *url = [extractor urlOfHypertextLinkAt:coord urlId:&urlID];
if (url) {
NSMenuItem *item = [theMenu addItemWithTitle:@"Copy Link Address" action:@selector(copyLinkAddress:) keyEquivalent:@""];
item.target = self;
item.representedObject = url;
}
}

[theMenu addItemWithTitle:NSLocalizedStringFromTableInBundle(@"Paste",
@"iTerm",
[NSBundle bundleForClass: [self class]],
Expand Down

0 comments on commit b2ab082

Please sign in to comment.