8
0
Quellcode durchsuchen

Passed a Locale instance to the bindTwoStepCaretToAttribute() helper instead of a static content direction info.

Aleksander Nowodzinski vor 6 Jahren
Ursprung
Commit
07f6ab7da9

+ 3 - 3
packages/ckeditor5-engine/src/utils/bindtwostepcarettoattribute.js

@@ -87,10 +87,9 @@ import priorities from '@ckeditor/ckeditor5-utils/src/priorities';
  * @param {module:utils/dom/emittermixin~Emitter} options.emitter The emitter to which this behavior should be added
  * (e.g. a plugin instance).
  * @param {String} options.attribute Attribute for which this behavior will be added.
- * @param {String} options.contentDirection Either "ltr" or "rtl" depending on the editor content direction.
- * Please refer to the {@link module:utils/locale~Locale editor locale} class to learn more.
+ * @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
  */
-export default function bindTwoStepCaretToAttribute( { view, model, emitter, attribute, contentDirection } ) {
+export default function bindTwoStepCaretToAttribute( { view, model, emitter, attribute, locale } ) {
 	const twoStepCaretHandler = new TwoStepCaretHandler( model, emitter, attribute );
 	const modelSelection = model.document.selection;
 
@@ -126,6 +125,7 @@ export default function bindTwoStepCaretToAttribute( { view, model, emitter, att
 		}
 
 		const position = modelSelection.getFirstPosition();
+		const contentDirection = locale.contentLanguageDirection;
 		let isMovementHandled;
 
 		if ( ( contentDirection === 'ltr' && arrowRightPressed ) || ( contentDirection === 'rtl' && arrowLeftPressed ) ) {

+ 1 - 1
packages/ckeditor5-engine/tests/manual/tickets/1301/1.js

@@ -26,7 +26,7 @@ ClassicEditor
 			model: editor.model,
 			emitter: bold,
 			attribute: 'bold',
-			contentDirection: 'ltr'
+			locale: editor.locale
 		} );
 	} )
 	.catch( err => {

+ 4 - 4
packages/ckeditor5-engine/tests/manual/two-step-caret.js

@@ -28,14 +28,14 @@ ClassicEditor
 			model: editor.model,
 			emitter: bold,
 			attribute: 'italic',
-			contentDirection: 'ltr'
+			locale: editor.locale
 		} );
 		bindTwoStepCaretToAttribute( {
 			view: editor.editing.view,
 			model: editor.model,
 			emitter: underline,
 			attribute: 'underline',
-			contentDirection: 'ltr'
+			locale: editor.locale
 		} );
 	} )
 	.catch( err => {
@@ -59,14 +59,14 @@ ClassicEditor
 			model: editor.model,
 			emitter: bold,
 			attribute: 'italic',
-			contentDirection: 'rtl'
+			locale: editor.locale
 		} );
 		bindTwoStepCaretToAttribute( {
 			view: editor.editing.view,
 			model: editor.model,
 			emitter: underline,
 			attribute: 'underline',
-			contentDirection: 'rtl'
+			locale: editor.locale
 		} );
 	} )
 	.catch( err => {

+ 11 - 5
packages/ckeditor5-engine/tests/utils/bindtwostepcarettoattribute.js

@@ -16,7 +16,7 @@ import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import { setData } from '../../src/dev-utils/model';
 
 describe( 'bindTwoStepCaretToAttribute()', () => {
-	let editor, model, emitter, selection, view;
+	let editor, model, emitter, selection, view, locale;
 	let preventDefaultSpy, evtStopSpy;
 
 	testUtils.createSinonSandbox();
@@ -29,6 +29,7 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
 			model = editor.model;
 			selection = model.document.selection;
 			view = editor.editing.view;
+			locale = editor.locale;
 
 			preventDefaultSpy = sinon.spy();
 			evtStopSpy = sinon.spy();
@@ -49,7 +50,7 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
 				model: editor.model,
 				emitter,
 				attribute: 'a',
-				contentDirection: 'ltr'
+				locale
 			} );
 		} );
 	} );
@@ -564,7 +565,7 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
 				model: editor.model,
 				emitter,
 				attribute: 'c',
-				contentDirection: 'ltr'
+				locale
 			} );
 		} );
 
@@ -789,7 +790,12 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
 
 			let model;
 
-			return VirtualTestEditor.create()
+			return VirtualTestEditor
+				.create( {
+					language: {
+						content: 'ar'
+					}
+				} )
 				.then( newEditor => {
 					model = newEditor.model;
 					selection = model.document.selection;
@@ -811,7 +817,7 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
 						model: newEditor.model,
 						emitter,
 						attribute: 'a',
-						contentDirection: 'rtl'
+						locale: newEditor.locale
 					} );
 
 					return newEditor;