Skip to main content

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