@@ -7,7 +7,7 @@ import assert from 'assert';
77import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js' ;
88import { Position } from '../../../common/core/position.js' ;
99import { Range } from '../../../common/core/range.js' ;
10- import { EndOfLineSequence , PositionAffinity } from '../../../common/model.js' ;
10+ import { EndOfLineSequence , PositionAffinity , TextDirection } from '../../../common/model.js' ;
1111import { ViewEventHandler } from '../../../common/viewEventHandler.js' ;
1212import { ViewEvent } from '../../../common/viewEvents.js' ;
1313import { testViewModel } from './testViewModel.js' ;
@@ -149,6 +149,38 @@ suite('ViewModel', () => {
149149 } ) ;
150150 } ) ;
151151
152+ test ( 'rtlAutoDetect renders Arabic text as RTL when enabled' , ( ) => {
153+ testViewModel ( [ 'مرحبا، Hello world!' ] , { rtlAutoDetect : true } , ( viewModel ) => {
154+ assert . strictEqual ( viewModel . getTextDirection ( 1 ) , TextDirection . RTL ) ;
155+ } ) ;
156+ } ) ;
157+
158+ test ( 'rtlAutoDetect keeps Arabic text as LTR when disabled' , ( ) => {
159+ testViewModel ( [ 'مرحبا، Hello world!' ] , { rtlAutoDetect : false } , ( viewModel ) => {
160+ assert . strictEqual ( viewModel . getTextDirection ( 1 ) , TextDirection . LTR ) ;
161+ } ) ;
162+ } ) ;
163+
164+ test ( 'rtlAutoDetect still allows forcing LTR direction via decorations' , ( ) => {
165+ testViewModel ( [ 'مرحبا، Hello world!' ] , { rtlAutoDetect : true } , ( viewModel , model ) => {
166+ model . deltaDecorations ( [ ] , [ {
167+ range : new Range ( 1 , 1 , 1 , 1 ) ,
168+ options : {
169+ description : 'text-direction-ltr' ,
170+ textDirection : TextDirection . LTR ,
171+ }
172+ } ] ) ;
173+
174+ assert . strictEqual ( viewModel . getTextDirection ( 1 ) , TextDirection . LTR ) ;
175+ } ) ;
176+ } ) ;
177+
178+ test ( 'rtlAutoDetect renders ASCII-only lines as LTR' , ( ) => {
179+ testViewModel ( [ 'Hello world!' ] , { rtlAutoDetect : true } , ( viewModel ) => {
180+ assert . strictEqual ( viewModel . getTextDirection ( 1 ) , TextDirection . LTR ) ;
181+ } ) ;
182+ } ) ;
183+
152184 function assertGetPlainTextToCopy ( text : string [ ] , ranges : Range [ ] , emptySelectionClipboard : boolean , expected : string | string [ ] ) : void {
153185 testViewModel ( text , { } , ( viewModel , model ) => {
154186 const actual = viewModel . getPlainTextToCopy ( ranges , emptySelectionClipboard , false ) ;
0 commit comments