@@ -56,6 +56,7 @@ import {
5656 pastedPathQueryLength ,
5757} from "~/composer-logic" ;
5858import { useStableCallback } from "~/hooks/useStableCallback" ;
59+ import { caretLineDirection , ComposerTextDirectionExtension } from "~/composer-text-direction" ;
5960import {
6061 collectComposerPromptInlineTokens ,
6162 selectionTouchesMentionBoundary ,
@@ -264,6 +265,7 @@ function ComposerMentionNodeView({ node }: NodeViewProps) {
264265 const chip = (
265266 < ContextChip
266267 kind = "mention"
268+ dir = "ltr"
267269 render = { < button type = "button" /> }
268270 onClick = { ( ) => actions . openMention ( path ) }
269271 aria-label = { `Preview ${ path } ` }
@@ -727,6 +729,7 @@ const ComposerMarkerPlugin = new Plugin({
727729function decorationsForSelection ( state : EditorState ) : DecorationSet {
728730 const { doc, selection } = state ;
729731 const caretSide = caretTakesMarksBefore ( state ) ? 3 : 0 ;
732+ const rtl = caretLineDirection ( state ) === "rtl" ;
730733 const decorations : Decoration [ ] = [ ] ;
731734 if ( ! selection . empty ) {
732735 doc . nodesBetween ( selection . from , selection . to , ( node , pos ) => {
@@ -750,8 +753,19 @@ function decorationsForSelection(state: EditorState): DecorationSet {
750753 marker . className = "composer-rich-marker" ;
751754 marker . textContent = text ;
752755 marker . setAttribute ( "aria-hidden" , "true" ) ;
756+ // Inline code is isolated left to right. In a right-to-left line its
757+ // opening backtick joins the closing one inside the isolate, or the line
758+ // would put both on the same side of the code.
759+ const codeMarks =
760+ rtl && baseSide === - 1 && / ^ ` + $ / . test ( text )
761+ ? doc . resolve ( at ) . nodeAfter ?. marks . filter ( ( mark ) => mark . type . spec . code )
762+ : undefined ;
753763 decorations . push (
754- Decoration . widget ( at , marker , { side, key : `marker-${ at } -${ side } -${ marker . textContent } ` } ) ,
764+ Decoration . widget ( at , marker , {
765+ side,
766+ key : `marker-${ at } -${ side } -${ marker . textContent } ` ,
767+ ...( codeMarks ?. length ? { marks : codeMarks } : { } ) ,
768+ } ) ,
755769 ) ;
756770 }
757771 }
@@ -852,6 +866,7 @@ function createComposerExtensions(richText: boolean) {
852866 ...( richText ? { } : { bold : false , strike : false } ) ,
853867 } ) ,
854868 ComposerUndoGroupingExtension ,
869+ ComposerTextDirectionExtension ,
855870 ComposerMentionExtension ,
856871 ComposerSkillExtension ,
857872 ComposerCitationExtension ,
@@ -1146,6 +1161,8 @@ function ComposerPromptEditorTiptapInner(
11461161 editorProps : {
11471162 attributes : editorAttributes ,
11481163 handleKeyDown : ( view , event ) => {
1164+ // In a right-to-left line the start is on the right.
1165+ const backArrow = caretLineDirection ( view . state ) === "rtl" ? "ArrowRight" : "ArrowLeft" ;
11491166 const boundary = event . metaKey
11501167 ? event . key === "ArrowLeft" || event . key === "ArrowRight"
11511168 ? "lineboundary"
@@ -1171,7 +1188,7 @@ function ComposerPromptEditorTiptapInner(
11711188 event . preventDefault ( ) ;
11721189 event . stopPropagation ( ) ;
11731190 const backward =
1174- event . key === "Home" || event . key === "ArrowLeft " || event . key === "ArrowUp" ;
1191+ event . key === "Home" || event . key === "ArrowUp " || event . key === backArrow ;
11751192 selection . modify (
11761193 event . shiftKey ? "extend" : "move" ,
11771194 backward ? "backward" : "forward" ,
@@ -1206,7 +1223,7 @@ function ComposerPromptEditorTiptapInner(
12061223 view . state . selection . empty
12071224 ) {
12081225 const { $from } = view . state . selection ;
1209- const direction = event . key === "ArrowLeft " || event . key === "ArrowUp" ? - 1 : 1 ;
1226+ const direction = event . key === "ArrowUp " || event . key === backArrow ? - 1 : 1 ;
12101227 const horizontal = event . key === "ArrowLeft" || event . key === "ArrowRight" ;
12111228 // At the document's ends, native Up/Down can cross a marker without
12121229 // changing the document position. Record the stop so DOM selection
0 commit comments