Repository navigation
script: Add Document selection copy/select all context menu options - #48101
Conversation
|
5db2f65 to
c449629
Compare
|
How does this relate to #48025 ? |
|
Would definitely be nice to integrate the CTRL-A work with this. After checking out this PR, and particularly the implementation of For example: <!doctype html>
<head>
<style>
/* This is selected in Chrome. */
* {
display: block;
}
</style>
</head>
<body bgcolor="white">
<textarea>Nice</textarea>
<p>Awesome</p>
</body> |
c449629 to
7d42444
Compare
|
I've taken Firefox's approach here (mostly) which is to target the body and then fall back to the document element.
<!DOCTYPE html>
abcdef
|
|
Ok, I see. When this lands then I will update my PR to use the logic introduced in this PR. |
|
🔨 Triggering try run (#34988426097) for Linux (WPT) |
|
Test results for linux-wpt from try job (#34988426097): Flaky unexpected result (30)
Stable unexpected results that are known to be intermittent (14)
|
|
✨ Try run (#34988426097) succeeded. |
| if let Ok(editing_context) = EditingContext::try_from(node) { | ||
| return editing_context; | ||
| } | ||
|
|
||
| let mut current_node = UnrootedDom::from_ref(node, no_gc); | ||
| while let Some(parent) = current_node.parent_in_flat_tree(no_gc).into_parent() { | ||
| if let Ok(editing_context) = EditingContext::try_from(&**parent) { | ||
| return editing_context; | ||
| } | ||
| current_node = parent; | ||
| } |
There was a problem hiding this comment.
(A thought in passing, but I recommend no change: it would be possible to deduplicate the two if lets by changing while let to loop and moving the parent lookup to the end of the loop. But it’s not that much duplication and the loop is arguably uglier.)
| pub(crate) fn selection_text(&self) -> Option<String> { | ||
| pub(crate) fn selection(&self) -> Option<String> { |
There was a problem hiding this comment.
Why this rename? An unqualified selection method sounds like it might return a range or a Selection object. If this is anticipating text/html selections that can contain more than text, maybe selection_content?
There was a problem hiding this comment.
Yes, the idea is that eventually this will return other types of data such as rich text and it will set all of the types onto the clipboard (or at least advertise them and then later read them). I think that selection_content is fine as a name, so I've made that rename.
| } | ||
| } | ||
|
|
||
| pub(crate) fn selection(&self, cx: &mut JSContext) -> Option<String> { |
There was a problem hiding this comment.
Same comment as in text_input.rs re: naming of this method
| <div><img src=\"https://servo.org/img.png\" style=\"width: 50px; height: 50px;\"></div> \ | ||
| <div style=\"width: 50px; height: 50px;\"><input type=\"text\"></div> \ | ||
| <div style=\"width: 50px; height: 50px;\"><input type=\"text\" readonly value=\"text\"></div> \ | ||
| <a href=\"https://nested.org\"><img src=\"https://servo.org/nested.png\" style=\"width: 50px; height: 50px;\"></a>", |
There was a problem hiding this comment.
These <img> elements make real HTTP requests over the internet, right? Would it be better to use http://localhost instead of servo.org? Those URLs are 404 so a failed fetch is expected anyway
There was a problem hiding this comment.
I've switched this to be a data URL.
| selection.focusOffset == 1 && \ | ||
| selection.focusNode == document.body", | ||
| ); | ||
| assert_eq!(result, Ok(JSValue::Boolean(true))); |
There was a problem hiding this comment.
Could this test also run ContextMenuAction::Copy and assert the text sent to the "clipboard"?
There was a problem hiding this comment.
Good point. I've added a simple ClipboardDelegate that records the contents of the clipboard and also added a test that copy works here. The test is now called test_contextual_context_menu_select_all_and_copy.
mrobinson
left a comment
There was a problem hiding this comment.
Thank you for the review!
| pub(crate) fn selection_text(&self) -> Option<String> { | ||
| pub(crate) fn selection(&self) -> Option<String> { |
There was a problem hiding this comment.
Yes, the idea is that eventually this will return other types of data such as rich text and it will set all of the types onto the clipboard (or at least advertise them and then later read them). I think that selection_content is fine as a name, so I've made that rename.
| selection.focusOffset == 1 && \ | ||
| selection.focusNode == document.body", | ||
| ); | ||
| assert_eq!(result, Ok(JSValue::Boolean(true))); |
There was a problem hiding this comment.
Good point. I've added a simple ClipboardDelegate that records the contents of the clipboard and also added a test that copy works here. The test is now called test_contextual_context_menu_select_all_and_copy.
| <div><img src=\"https://servo.org/img.png\" style=\"width: 50px; height: 50px;\"></div> \ | ||
| <div style=\"width: 50px; height: 50px;\"><input type=\"text\"></div> \ | ||
| <div style=\"width: 50px; height: 50px;\"><input type=\"text\" readonly value=\"text\"></div> \ | ||
| <a href=\"https://nested.org\"><img src=\"https://servo.org/nested.png\" style=\"width: 50px; height: 50px;\"></a>", |
There was a problem hiding this comment.
I've switched this to be a data URL.
7d42444 to
16f0053
Compare
This change adds initial `Document` selection integration with the context menu so that the user can copy the selection to the clipboard or select the entire `Document` contents. As part of this change a new generic `EditingContext` struct is created to manage integration with the various editing hosts. This will be used for keyboard shortcuts in the future as well. One small change is also made here: paste and cut are disabled for read only form controls. Finally, the context menu unit tests are cleaned up and expanded to more easily add support for testing "select all." Currently there are no unit tests for clipboard integration, so unfortunately there is no test for this. Signed-off-by: Martin Robinson <[email protected]>
16f0053 to
21dc152
Compare
|
Apparently if-let chains in a match is a different feature than if-let chains and the former isn't stabilized in our version of Rust. 🤔 |
…servo#48101) This change adds initial `Document` selection integration with the context menu so that the user can copy the selection to the clipboard or select the entire `Document` contents. As part of this change a new generic `EditingContext` struct is created to manage integration with the various editing hosts. This will be used for keyboard shortcuts in the future as well. One small change is also made here: paste and cut are disabled for read only form controls. Finally, the context menu unit tests are cleaned up and expanded to more easily add support for testing "select all." Currently there are no unit tests for clipboard integration, so unfortunately there is no test for this. Testing: This change adds various embedder API unit tests. Signed-off-by: Martin Robinson <[email protected]>
…servo#48101) This change adds initial `Document` selection integration with the context menu so that the user can copy the selection to the clipboard or select the entire `Document` contents. As part of this change a new generic `EditingContext` struct is created to manage integration with the various editing hosts. This will be used for keyboard shortcuts in the future as well. One small change is also made here: paste and cut are disabled for read only form controls. Finally, the context menu unit tests are cleaned up and expanded to more easily add support for testing "select all." Currently there are no unit tests for clipboard integration, so unfortunately there is no test for this. Testing: This change adds various embedder API unit tests. Signed-off-by: Martin Robinson <[email protected]>
This change adds initial
Documentselection integration with thecontext menu so that the user can copy the selection to the clipboard or
select the entire
Documentcontents. As part of this change a newgeneric
EditingContextstruct is created to manage integration withthe various editing hosts. This will be used for keyboard shortcuts in
the future as well.
One small change is also made here: paste and cut are disabled for read
only form controls.
Finally, the context menu unit tests are cleaned up and expanded to more
easily add support for testing "select all." Currently there are no unit
tests for clipboard integration, so unfortunately there is no test for
this.
Testing: This change adds various embedder API unit tests.