Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

T/ckeditor5/1151: Brought support for RTL content in the bindTwoStepCaretToAttribute() helper #1769

Merged
merged 12 commits into from
Aug 12, 2019
Merged
Prev Previous commit
Next Next commit
Passed a Locale instance to the bindTwoStepCaretToAttribute() helper …
…instead of a static content direction info.
oleq committed Aug 9, 2019
commit 99b24585bd6ae9a970eb4b6ddd5f50506567015a
6 changes: 3 additions & 3 deletions src/utils/bindtwostepcarettoattribute.js
Original file line number Diff line number Diff line change
@@ -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 ) ) {
2 changes: 1 addition & 1 deletion tests/manual/tickets/1301/1.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ ClassicEditor
model: editor.model,
emitter: bold,
attribute: 'bold',
contentDirection: 'ltr'
locale: editor.locale
} );
} )
.catch( err => {
8 changes: 4 additions & 4 deletions tests/manual/two-step-caret.js
Original file line number Diff line number Diff line change
@@ -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 => {
16 changes: 11 additions & 5 deletions tests/utils/bindtwostepcarettoattribute.js
Original file line number Diff line number Diff line change
@@ -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;