Text alignment
Align paragraphs, headings, or other configured blocks.
Text alignment adds the textAlign attribute to chosen block types. The default alignment values are left, center, right, and justify.
Try it
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-text-alignExample
Section titled “Example”Enable alignment on paragraphs in the Quickstart editor configuration. text_align(["paragraph"]) uses this formatter by default.
use gpdoc::{EditorConfig, PluginViewExt};use gpdoc_plugin_text_align::{text_align, text_align_format};use gpdoc_plugin_paragraph::paragraph;
let config = EditorConfig::builder() .plugin(paragraph()) .plugin(text_align(["paragraph"]).with_view(|| text_align_format(["paragraph"]))) .build() .expect("configure editor");Place the caret in a paragraph and press Command + Shift + E on macOS or Ctrl + Shift + E on Windows and Linux. The paragraph moves to the center.
Settings
Section titled “Settings”text_align(types) and text_align_with_options(types, options: TextAlignOptions) both create a text alignment plugin.
Choose which blocks can store alignment. Supply an iterator of names (impl IntoIterator<Item = impl Into<String>>) for block types registered with your config. To align headings, register the Heading plugin and include "heading" in the array.
let alignment = gpdoc_plugin_text_align::text_align(["paragraph", "heading"]);alignments
Section titled “alignments”Restrict the menu to supported values with TextAlignOptions::alignments (Vec<String>). Defaults to left, center, right, and justify.
use gpdoc_plugin_text_align::{text_align_with_options, TextAlignOptions};
let alignment = text_align_with_options(["paragraph"], TextAlignOptions { alignments: vec!["left".into(), "center".into()], ..Default::default()});default_alignment
Section titled “default_alignment”Set the initial alignment and the value restored by reset. The default is None (Option<String>), stored as null on the block.
use gpdoc_plugin_text_align::{text_align_with_options, TextAlignOptions};
let alignment = text_align_with_options(["paragraph"], TextAlignOptions { default_alignment: Some("left".into()), ..Default::default()});Commands
Section titled “Commands”editor.run returns Result<CommandOutcome, Error>. Set and toggle return NotApplicable for a missing or unsupported textAlign string. All three return NotApplicable if the selection contains no configured block.
setTextAlign
Section titled “setTextAlign”Apply the requested alignment to each eligible block in the selection.
editor.run(gpdoc_plugin_text_align::Set("center".into()))?;toggleTextAlign
Section titled “toggleTextAlign”Restore the default if the requested alignment covers the selection. Otherwise apply it.
editor.run(gpdoc_plugin_text_align::Toggle("center".into()))?;unsetTextAlign
Section titled “unsetTextAlign”Restore the configured default on eligible blocks.
editor.run(gpdoc_plugin_text_align::Unset)?;Keyboard shortcuts
Section titled “Keyboard shortcuts”Hold Command + Shift on macOS or Ctrl + Shift on Windows and Linux, then press L for left, E for center, R for right, or J for justified alignment.