script/dom/execcommand/commands/
underline.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::execcommand::execcommands::DocumentExecCommandSupport;
10use crate::dom::selection::Selection;
11
12/// <https://w3c.github.io/editing/docs/execCommand/#the-underline-command>
13pub(crate) fn execute_underline_command(
14    cx: &mut JSContext,
15    document: &Document,
16    selection: &Selection,
17) -> bool {
18    // > If queryCommandState("underline") returns true, set the selection's value to null.
19    // > Otherwise set the selection's value to "underline". Either way, return true.
20    let value = Some("underline".into())
21        .filter(|_| !document.command_state_for_command(cx, "underline".into()));
22    selection.set_the_selection_value(cx, value, CommandName::Underline, document);
23
24    true
25}