|
23 | 23 |
|
24 | 24 | static constexpr NSInteger CONTEXT_MENU_EDIT_NODE_TAG = 1;
|
25 | 25 | static constexpr NSInteger CONTEXT_MENU_REMOVE_ATTRIBUTE_TAG = 2;
|
| 26 | +static constexpr NSInteger CONTEXT_MENU_COPY_ATTRIBUTE_VALUE_TAG = 3; |
26 | 27 |
|
27 | 28 | @interface Inspector ()
|
28 | 29 | {
|
@@ -98,15 +99,23 @@ - (instancetype)init:(Tab*)tab
|
98 | 99 | return;
|
99 | 100 | }
|
100 | 101 |
|
| 102 | + static constexpr size_t MAX_ATTRIBUTE_VALUE_LENGTH = 32; |
| 103 | + |
101 | 104 | auto edit_attribute_text = MUST(String::formatted("Edit attribute \"{}\"", attribute.name));
|
102 | 105 | auto remove_attribute_text = MUST(String::formatted("Remove attribute \"{}\"", attribute.name));
|
| 106 | + auto copy_attribute_value_text = MUST(String::formatted("Copy attribute value \"{:.{}}{}\"", |
| 107 | + attribute.value, MAX_ATTRIBUTE_VALUE_LENGTH, |
| 108 | + attribute.value.bytes_as_string_view().length() > MAX_ATTRIBUTE_VALUE_LENGTH ? "..."sv : ""sv)); |
103 | 109 |
|
104 | 110 | auto* edit_node_menu_item = [strong_self.dom_node_attribute_context_menu itemWithTag:CONTEXT_MENU_EDIT_NODE_TAG];
|
105 | 111 | [edit_node_menu_item setTitle:Ladybird::string_to_ns_string(edit_attribute_text)];
|
106 | 112 |
|
107 | 113 | auto* remove_attribute_menu_item = [strong_self.dom_node_attribute_context_menu itemWithTag:CONTEXT_MENU_REMOVE_ATTRIBUTE_TAG];
|
108 | 114 | [remove_attribute_menu_item setTitle:Ladybird::string_to_ns_string(remove_attribute_text)];
|
109 | 115 |
|
| 116 | + auto* copy_attribute_value_menu_item = [strong_self.dom_node_attribute_context_menu itemWithTag:CONTEXT_MENU_COPY_ATTRIBUTE_VALUE_TAG]; |
| 117 | + [copy_attribute_value_menu_item setTitle:Ladybird::string_to_ns_string(copy_attribute_value_text)]; |
| 118 | + |
110 | 119 | auto* event = Ladybird::create_context_menu_mouse_event(strong_self.web_view, position);
|
111 | 120 | [NSMenu popUpContextMenu:strong_self.dom_node_attribute_context_menu withEvent:event forView:strong_self.web_view];
|
112 | 121 | };
|
@@ -172,6 +181,11 @@ - (void)removeDOMAttribute:(id)sender
|
172 | 181 | m_inspector_client->context_menu_remove_dom_node_attribute();
|
173 | 182 | }
|
174 | 183 |
|
| 184 | +- (void)copyDOMAttributeValue:(id)sender |
| 185 | +{ |
| 186 | + m_inspector_client->context_menu_copy_dom_node_attribute_value(); |
| 187 | +} |
| 188 | + |
175 | 189 | #pragma mark - Properties
|
176 | 190 |
|
177 | 191 | - (NSMenu*)dom_node_text_context_menu
|
@@ -234,6 +248,12 @@ - (NSMenu*)dom_node_attribute_context_menu
|
234 | 248 | [remove_attribute_menu_item setTag:CONTEXT_MENU_REMOVE_ATTRIBUTE_TAG];
|
235 | 249 | [_dom_node_attribute_context_menu addItem:remove_attribute_menu_item];
|
236 | 250 |
|
| 251 | + auto* copy_attribute_value_menu_item = [[NSMenuItem alloc] initWithTitle:@"Copy attribute value" |
| 252 | + action:@selector(copyDOMAttributeValue:) |
| 253 | + keyEquivalent:@""]; |
| 254 | + [copy_attribute_value_menu_item setTag:CONTEXT_MENU_COPY_ATTRIBUTE_VALUE_TAG]; |
| 255 | + [_dom_node_attribute_context_menu addItem:copy_attribute_value_menu_item]; |
| 256 | + |
237 | 257 | [_dom_node_attribute_context_menu addItem:[NSMenuItem separatorItem]];
|
238 | 258 |
|
239 | 259 | [_dom_node_attribute_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Add attribute"
|
|
0 commit comments