Skip to content

Text Direction Plugin

The TextDirectionPlugin adds block-level text direction (dir attribute) to paragraphs, headings, and other directable block types. It exposes commands and a toolbar dropdown for switching between LTR, RTL, and auto direction, registers a Mod-Shift-D keymap, and (on Windows/Linux) attaches a Ctrl+Shift direction handler.

For inline <bdi> isolation see Bidi Isolation. For automatic direction detection / inheritance / preservation see Text Direction Auto.

import { TextDirectionPlugin } from '@notectl/core/plugins/text-direction';
new TextDirectionPlugin();
new TextDirectionPlugin({ directableTypes: ['paragraph', 'heading'] });
interface TextDirectionConfig {
/** Block types that support direction. Default: paragraph, heading, title, subtitle, table_cell, blockquote, list_item */
readonly directableTypes: readonly string[];
/** Custom locale for toolbar labels and announcements. */
readonly locale?: TextDirectionLocale;
}
new TextDirectionPlugin({
directableTypes: ['paragraph', 'heading', 'blockquote'],
});

The plugin patches existing NodeSpecs for directable block types to add a dir attribute. This controls the overall text direction of the entire block.

AttributeTypeDefaultRenders As
dir'ltr' | 'rtl' | 'auto''auto'dir="rtl" on the block element
CommandDescriptionReturns
setDirectionLTRSet block direction to left-to-rightboolean
setDirectionRTLSet block direction to right-to-leftboolean
setDirectionAutoSet block direction to automaticboolean
toggleDirectionCycle direction: auto → rtl → ltr → autoboolean
editor.executeCommand('setDirectionRTL');
editor.executeCommand('toggleDirection');
ShortcutAction
Ctrl+Shift+D / Cmd+Shift+DToggle block direction (cycles auto → rtl → ltr → auto)

Windows/Linux only:

ShortcutAction
Ctrl + Left Shift keySet direction to LTR
Ctrl + Right Shift keySet direction to RTL

The plugin renders a Text Direction toolbar dropdown (block group) with LTR, RTL, and Auto options. The icon updates to reflect the current block’s direction.

When this plugin loads it registers a TextDirectionService (via TEXT_DIRECTION_SERVICE_KEY) so other plugins can read the current direction without coupling to internals:

interface TextDirectionService {
readonly directableTypes: ReadonlySet<string>;
getBlockDir(block: BlockNode): TextDirection;
}

TextDirectionAutoPlugin requires this service. BidiIsolationPlugin consumes it optionally for the toggleBidiIsolation cycle UX.

  • Screen reader announcements for all direction changes via context.announce()
  • Keyboard-accessible shortcuts with platform-aware mappings (Mac vs. Windows/Linux)
  • ARIA-friendly toolbar dropdowns
  • Uses the semantic HTML dir attribute for proper assistive technology support

Ships with translations for 9 languages:

LanguageLoader
EnglishBuilt-in (TEXT_DIRECTION_LOCALE_EN)
ArabicloadTextDirectionLocale('ar')
GermanloadTextDirectionLocale('de')
SpanishloadTextDirectionLocale('es')
FrenchloadTextDirectionLocale('fr')
HindiloadTextDirectionLocale('hi')
PortugueseloadTextDirectionLocale('pt')
RussianloadTextDirectionLocale('ru')
ChineseloadTextDirectionLocale('zh')

Custom locales can be provided via the locale config option. See the Internationalization guide for details.