Skip to main content

script/dom/execcommand/commands/
subscript.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 js::context::JSContext;
6
7use crate::dom::document::Document;
8use crate::dom::execcommand::basecommand::CommandName;
9use crate::dom::selection::Selection;
10
11/// <https://w3c.github.io/editing/docs/execCommand/#the-subscript-command>
12pub(crate) fn execute_subscript_command(
13    cx: &mut JSContext,
14    document: &Document,
15    selection: &Selection,
16) -> bool {
17    // Step 1. Call queryCommandState("subscript"), and let state be the result.
18    let state = CommandName::Subscript.current_state(cx, document);
19    // Step 2. Set the selection's value to null.
20    selection.set_the_selection_value(cx, None, CommandName::Subscript, document);
21    // Step 3. If state is false, set the selection's value to "subscript".
22    if state.is_none_or(|state| !state) {
23        selection.set_the_selection_value(
24            cx,
25            Some("subscript".into()),
26            CommandName::Subscript,
27            document,
28        );
29    }
30    // Step 4. Return true.
31    true
32}