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