@@ -889,16 +889,20 @@ func swapVisualOrder(subline Line) {
889889 }
890890}
891891
892- // computeBidiOrdering resolves the [VisualIndex] of each run.
893- func computeBidiOrdering (dir di.Direction , finalLine Line ) {
892+ // ComputeBidiOrdering resolves the [VisualIndex] of each run.
893+ //
894+ // [paragraphDirection] describes the text layout of the overall paragraph, rather than
895+ // individual runs of text.
896+ func (finalLine Line ) ComputeBidiOrdering (paragraphDirection di.Direction ) {
897+ progression := paragraphDirection .Progression ()
894898 bidiStart := - 1
895899 for idx , run := range finalLine {
896900 basePosition := idx
897- if dir . Progression () == di .TowardTopLeft {
901+ if progression == di .TowardTopLeft {
898902 basePosition = len (finalLine ) - 1 - idx
899903 }
900904 finalLine [idx ].VisualIndex = int32 (basePosition )
901- if run .Direction == dir {
905+ if run .Direction . Progression () == progression {
902906 if bidiStart != - 1 {
903907 swapVisualOrder (finalLine [bidiStart :idx ])
904908 bidiStart = - 1
@@ -914,7 +918,7 @@ func computeBidiOrdering(dir di.Direction, finalLine Line) {
914918
915919func (l * LineWrapper ) postProcessLine (finalLine Line , done bool ) (WrappedLine , bool ) {
916920 if len (finalLine ) > 0 {
917- computeBidiOrdering (l .config .Direction , finalLine )
921+ finalLine . ComputeBidiOrdering (l .config .Direction )
918922 if ! l .config .DisableTrailingWhitespaceTrim {
919923 // Here we find the last visual run in the line.
920924 goalIdx := len (finalLine ) - 1
@@ -975,7 +979,7 @@ func (l *LineWrapper) postProcessLine(finalLine Line, done bool) (WrappedLine, b
975979 truncator .Runes .Offset = l .lineStartRune
976980 finalLine = append (finalLine , truncator )
977981 // We've just modified the line, we need to recompute the bidi ordering.
978- computeBidiOrdering (l .config .Direction , finalLine )
982+ finalLine . ComputeBidiOrdering (l .config .Direction )
979983 }
980984 }
981985
0 commit comments