@@ -7,6 +7,7 @@ import Placeholder from "@tiptap/extension-placeholder";
77import Link from "@tiptap/extension-link" ;
88import { Extension , type KeyboardShortcutCommand } from "@tiptap/core" ;
99import { Plugin , Selection , TextSelection } from "@tiptap/pm/state" ;
10+ import type { ResolvedPos } from "@tiptap/pm/model" ;
1011
1112import {
1213 hasPrimaryShortcutModifier ,
@@ -35,6 +36,24 @@ import {
3536} from "./codeBlockExtensions" ;
3637import { SpoilerMark } from "./spoilerMark" ;
3738
39+ function hardBreakLineBounds ( $from : ResolvedPos ) {
40+ const parentStart = $from . start ( ) ;
41+ let start = parentStart ;
42+ let end = parentStart + $from . parent . content . size ;
43+
44+ $from . parent . forEach ( ( node , offset ) => {
45+ if ( node . type . name !== "hardBreak" ) return ;
46+ const breakPosition = parentStart + offset ;
47+ if ( breakPosition < $from . pos ) {
48+ start = breakPosition + node . nodeSize ;
49+ } else if ( breakPosition >= $from . pos && end > breakPosition ) {
50+ end = breakPosition ;
51+ }
52+ } ) ;
53+
54+ return { end, start } ;
55+ }
56+
3857/**
3958 * Plain-text edit descriptor returned by autocomplete hooks
4059 * (mentions / channel links / emoji). Offsets are in plain-text space —
@@ -243,8 +262,8 @@ export function useRichTextEditor({
243262 link : false ,
244263 } ) ,
245264 // macOS text fields traditionally support a small set of Emacs-style
246- // Control shortcuts. ProseMirror already handles Ctrl-A/E/H/D on macOS;
247- // these fill in the common movement and kill- line gaps for the composer .
265+ // Control shortcuts. Keep movement and kill-line scoped to the current
266+ // hard-break-delimited line rather than the whole ProseMirror block .
248267 Extension . create ( {
249268 name : "macEmacsTextShortcuts" ,
250269 addKeyboardShortcuts ( ) {
@@ -254,6 +273,20 @@ export function useRichTextEditor({
254273 }
255274
256275 return {
276+ "Ctrl-a" : ( { editor : ed } ) => {
277+ const { $from } = ed . state . selection ;
278+ if ( ! $from . parent . inlineContent ) return false ;
279+ return ed . commands . setTextSelection (
280+ hardBreakLineBounds ( $from ) . start ,
281+ ) ;
282+ } ,
283+ "Ctrl-e" : ( { editor : ed } ) => {
284+ const { $from } = ed . state . selection ;
285+ if ( ! $from . parent . inlineContent ) return false ;
286+ return ed . commands . setTextSelection (
287+ hardBreakLineBounds ( $from ) . end ,
288+ ) ;
289+ } ,
257290 "Ctrl-b" : ( { editor : ed } ) => {
258291 const { empty, from } = ed . state . selection ;
259292 if ( ! empty || from <= 0 ) return false ;
@@ -272,6 +305,21 @@ export function useRichTextEditor({
272305 return ed . commands . deleteSelection ( ) ;
273306 }
274307
308+ if ( $from . parent . inlineContent ) {
309+ const lineEnd = hardBreakLineBounds ( $from ) . end ;
310+ if ( from < lineEnd ) {
311+ return ed . commands . deleteRange ( { from, to : lineEnd } ) ;
312+ }
313+
314+ const nodeAfter = $from . nodeAfter ;
315+ if ( nodeAfter ?. type . name === "hardBreak" ) {
316+ return ed . commands . deleteRange ( {
317+ from,
318+ to : from + nodeAfter . nodeSize ,
319+ } ) ;
320+ }
321+ }
322+
275323 const blockEnd = $from . end ( ) ;
276324 if ( from < blockEnd ) {
277325 return ed . commands . deleteRange ( { from, to : blockEnd } ) ;
@@ -460,6 +508,30 @@ export function useRichTextEditor({
460508 // command/caret logic, fires regardless of selection state, and works
461509 // the same across browser engines. Returning `true` consumes the key.
462510 handleKeyDown : ( view , event ) => {
511+ // Chromium handles Ctrl-A/E as whole-content movement before the
512+ // keymap on macOS. Claim them at the raw DOM layer so hard breaks
513+ // behave like actual line boundaries.
514+ if (
515+ isMacPlatform ( ) &&
516+ event . ctrlKey &&
517+ ! event . metaKey &&
518+ ! event . altKey &&
519+ ! event . shiftKey &&
520+ ( event . key . toLowerCase ( ) === "a" || event . key . toLowerCase ( ) === "e" )
521+ ) {
522+ const { $from } = view . state . selection ;
523+ if ( ! $from . parent . inlineContent ) return false ;
524+ const bounds = hardBreakLineBounds ( $from ) ;
525+ const position =
526+ event . key . toLowerCase ( ) === "a" ? bounds . start : bounds . end ;
527+ view . dispatch (
528+ view . state . tr . setSelection (
529+ TextSelection . create ( view . state . doc , position ) ,
530+ ) ,
531+ ) ;
532+ return true ;
533+ }
534+
463535 // ⌘K / Ctrl+K → link editor. The formatting toolbar has always
464536 // advertised this shortcut on its link button; bind it here so it
465537 // actually works. Kept alongside the ArrowUp handling below rather
0 commit comments