Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement indexed access on select elements #13066
Conversation
highfive
commented
Aug 26, 2016
|
Heads up! This PR modifies the following files:
|
|
r? @KiChjang |
| } | ||
| } | ||
| } else if value > length { // add new blank option elements | ||
| let document = node.GetOwnerDocument(); |
This comment has been minimized.
This comment has been minimized.
| let appended = node.AppendChild(element.upcast()); | ||
| match appended { | ||
| Ok(_) => {}, | ||
| Err(e) => println!("error appending child of HTML Select: {:?}", e), |
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 26, 2016
Member
if let Err(e) = node.AppendChild(element.upcast()) {
println!("error appending child of HTMLSelectElement: {:?}", e);
}| fn Item(&self, index: u32) -> Option<Root<Element>> { | ||
| let node = self.upcast::<Node>(); | ||
| let item = node.traverse_preorder().filter_map(Root::downcast::<HTMLOptionElement>).nth(index as usize); | ||
| if item.is_some() { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 26, 2016
•
Member
Actually, we can even do this:
item.map(|i| Root::from_ref(i.upcast()))
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 27, 2016
•
Member
Or, if you don't mind chaining up functions:
self.upcast::<Node>()
.traverse_preorder()
.filter_map(Root::downcast::<HTMLOptionElement>)
.nth(index as usize)
.map(|item| Root::from_ref(item.upcast()))| let node = self.upcast::<Node>(); | ||
| if value < length { // truncate the number of option elements | ||
| for _ in 0..(length - value) { | ||
| let lastChild = node.GetLastChild(); |
This comment has been minimized.
This comment has been minimized.
KiChjang
Aug 27, 2016
Member
I think we can just use node.descending_last_children().take(length - value) here.
This comment has been minimized.
This comment has been minimized.
mskrzypkows
Sep 10, 2016
Author
For some reason
for child in node.descending_last_children().take((length - value) as usize) {
if let Err(e) = node.RemoveChild(&child) {
println!("error removing child of HTML Select: {:?}", e);
}
}
doesn't work. I'll check it and upload next commit.
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 10, 2016
•
Member
let mut iter = node.descending_last_children().take((length - value) as usize);
while let Some(child) = iter.next() {
if let Err(e) = node.RemoveChild(&child) {
println!("Error removing child of HTMLSelectElement: {:?}", e);
}
}
This comment has been minimized.
This comment has been minimized.
|
Any updates? If you need help, just ask! |
|
I'll update today, sorry for the delay, I was busy recently. |
|
No problem :) |
10138ca
to
a3134fc
| let node = self.upcast::<Node>(); | ||
| if value < length { // truncate the number of option elements | ||
| for _ in 0..(length - value) { | ||
| if let Some(lastChild) = node.GetLastChild() { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
mskrzypkows
Sep 17, 2016
Author
I didn't ignore your comment, check my reply to your previous comment. It doesn't work as you mentioned children nodes aren't deleted.
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 17, 2016
Member
Sorry, descending_last_children is incorrect. Use rev_children instead.
This comment has been minimized.
This comment has been minimized.
|
|
||
| // https://html.spec.whatwg.org/multipage/#dom-select-length | ||
| fn Length(&self) -> u32 { | ||
| let node = self.upcast::<Node>(); |
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 16, 2016
Member
This can be melded into the following line without a let-binding to node.
| let node = self.upcast::<Node>(); | ||
| if value < length { // truncate the number of option elements | ||
| for _ in 0..(length - value) { | ||
| if let Some(lastChild) = node.GetLastChild() { |
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 17, 2016
Member
Sorry, descending_last_children is incorrect. Use rev_children instead.
| @@ -1,18 +1,2 @@ | |||
| [common-HTMLOptionsCollection.html] | |||
| type: testharness | |||
This comment has been minimized.
This comment has been minimized.
a3134fc
to
e9d5615
|
Squash! |
e9d5615
to
920f42b
|
|
|
920f42b
to
670693b
|
Strange build error, it seems not related to my changes. |
|
@bors-servo r+ |
|
|
Implement indexed access on select elements <!-- Please describe your changes on the following line: --> Added methods for indexed access on select: SetLength, Length, Item, IndexedGetter --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11763 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13066) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
Implement indexed access on select elements <!-- Please describe your changes on the following line: --> Added methods for indexed access on select: SetLength, Length, Item, IndexedGetter --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11763 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13066) <!-- Reviewable:end -->
|
|
mskrzypkows commentedAug 26, 2016
•
edited by larsbergstrom
Added methods for indexed access on select: SetLength, Length, Item, IndexedGetter
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is