script/dom/execcommand/commands/delete.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use crate::dom::bindings::str::DOMString;
6use crate::dom::execcommand::basecommand::BaseCommand;
7use crate::dom::selection::Selection;
8
9pub(crate) struct DeleteCommand {}
10
11impl BaseCommand for DeleteCommand {
12 /// <https://w3c.github.io/editing/docs/execCommand/#the-delete-command>
13 fn execute(&self, selection: &Selection, _value: DOMString) -> bool {
14 let active_range = selection
15 .active_range()
16 .expect("Must always have an active range");
17 // Step 1. If the active range is not collapsed, delete the selection and return true.
18 if !active_range.collapsed() {
19 self.delete_the_selection(selection, &active_range);
20 return true;
21 }
22 // Step 2. Canonicalize whitespace at the active range's start.
23 // TODO
24
25 // Step 3. Let node and offset be the active range's start node and offset.
26 // TODO
27
28 // Step 4. Repeat the following steps:
29 // TODO
30
31 // Step 5. If node is a Text node and offset is not zero, or if node is
32 // a block node that has a child with index offset − 1 and that child is a br or hr or img:
33 // TODO
34
35 // Step 6. If node is an inline node, return true.
36 // TODO
37
38 // Step 7. If node is an li or dt or dd and is the first child of its parent, and offset is zero:
39 // TODO
40
41 // Step 8. Let start node equal node and let start offset equal offset.
42 // TODO
43
44 // Step 9. Repeat the following steps:
45 // TODO
46
47 // Step 10. If offset is zero, and node has an editable inclusive ancestor in the same editing host that's an indentation element:
48 // TODO
49
50 // Step 11. If the child of start node with index start offset is a table, return true.
51 // TODO
52
53 // Step 12. If start node has a child with index start offset − 1, and that child is a table:
54 // TODO
55
56 // Step 13. If offset is zero; and either the child of start node with index start offset
57 // minus one is an hr, or the child is a br whose previousSibling is either a br or not an inline node:
58 // TODO
59
60 // Step 14. If the child of start node with index start offset is an li or dt or dd, and
61 // that child's firstChild is an inline node, and start offset is not zero:
62 // TODO
63
64 // Step 15. If start node's child with index start offset is an li or dt or dd, and
65 // that child's previousSibling is also an li or dt or dd:
66 // TODO
67
68 // Step 16. While start node has a child with index start offset minus one:
69 // TODO
70
71 // Step 17. Call collapse(start node, start offset) on the context object's selection.
72 // TODO
73
74 // Step 18. Call extend(node, offset) on the context object's selection.
75 // TODO
76
77 // Step 19. Delete the selection, with direction "backward".
78 // TODO
79
80 // Step 20. Return true.
81 true
82 }
83}