Skip to content

Commit c9609f2

Browse files
committed
WebHistoryController: Refactor menu search to be recursive
This way it doesn't matter where in an element you click, as long as one of its parents has the required attributes, you get the menu
1 parent 47e182a commit c9609f2

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

PBWebHistoryController.m

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ - (NSArray *) webView:(WebView *)sender
7676
{
7777
DOMNode *node = [element valueForKey:@"WebElementDOMNode"];
7878

79-
// If clicked on the text, select the containing div
80-
if ([[node className] isEqualToString:@"DOMText"])
81-
node = [node parentNode];
82-
83-
// Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref.
84-
if (![[node className] hasPrefix:@"refs "])
85-
return defaultMenuItems;
79+
while (node) {
80+
// Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref.
81+
if ([[node className] hasPrefix:@"refs "]) {
82+
NSString *selectedRefString = [[[node childNodes] item:0] textContent];
83+
for (PBGitRef *ref in historyController.webCommit.refs)
84+
{
85+
if ([[ref shortName] isEqualToString:selectedRefString])
86+
return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit];
87+
}
88+
NSLog(@"Could not find selected ref!");
89+
return defaultMenuItems;
90+
}
8691

87-
NSString *selectedRefString = [[[node childNodes] item:0] textContent];
88-
for (PBGitRef *ref in historyController.webCommit.refs)
89-
{
90-
if ([[ref shortName] isEqualToString:selectedRefString])
91-
return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit];
92+
node = [node parentNode];
9293
}
93-
NSLog(@"Could not find selected ref!");
9494

9595
return defaultMenuItems;
9696
}

0 commit comments

Comments
 (0)