Skip to main content

script/dom/execcommand/commands/
bold.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-bold-command>
14pub(crate) fn execute_bold_command(
15    cx: &mut JSContext,
16    document: &Document,
17    selection: &Selection,
18) -> bool {
19    // > If queryCommandState("bold") returns true, set the selection's value to "normal".
20    // > Otherwise set the selection's value to "bold". Either way, return true.
21    let value = if document.command_state_for_command(cx, DOMString::from_static("bold")) {
22        Some(DOMString::from_static("normal"))
23    } else {
24        Some(DOMString::from_static("bold"))
25    };
26    selection.set_the_selection_value(cx, value, CommandName::Bold, document);
27
28    true
29}