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

Commit c387059

Browse files
authored
Merge pull request #61 from ckeditor/t/ckeditor5/1151
Feature: The `InlineEditorUIView` should display on different sides of editable depending on the direction of the UI language. See ckeditor/ckeditor5#1151.
2 parents 5e42fcf + ae27966 commit c387059

File tree

5 files changed

+81
-5
lines changed

5 files changed

+81
-5
lines changed

src/inlineeditoruiview.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default class InlineEditorUIView extends EditorUIView {
172172
* @returns {module:utils/dom/position~Options#positions}
173173
*/
174174
_getPanelPositions() {
175-
return [
175+
const positions = [
176176
( editableRect, panelRect ) => {
177177
return {
178178
top: this._getPanelPositionTop( editableRect, panelRect ),
@@ -188,5 +188,11 @@ export default class InlineEditorUIView extends EditorUIView {
188188
};
189189
}
190190
];
191+
192+
if ( this.locale.uiLanguageDirection === 'ltr' ) {
193+
return positions;
194+
} else {
195+
return positions.reverse();
196+
}
191197
}
192198
}

tests/inlineeditoruiview.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe( 'InlineEditorUIView', () => {
1919
testUtils.createSinonSandbox();
2020

2121
beforeEach( () => {
22-
locale = new Locale( 'en' );
22+
locale = new Locale();
2323
editingView = new EditingView();
2424
editingViewRoot = createRoot( editingView.document );
2525
view = new InlineEditorUIView( locale, editingView );
@@ -115,7 +115,7 @@ describe( 'InlineEditorUIView', () => {
115115

116116
describe( 'init()', () => {
117117
it( 'appends #toolbar to panel#content', () => {
118-
locale = new Locale( 'en' );
118+
locale = new Locale();
119119
const view = new InlineEditorUIView( locale, editingView );
120120

121121
view.editable.name = editingViewRoot.rootName;
@@ -130,8 +130,11 @@ describe( 'InlineEditorUIView', () => {
130130
} );
131131

132132
describe( 'panelPositions', () => {
133-
it( 'returns the positions in the right order', () => {
134-
const positions = view.panelPositions;
133+
it( 'returns the positions in the right order (uiLanguageDirection="ltr")', () => {
134+
locale.uiLanguageDirection = 'ltr';
135+
136+
const uiView = new InlineEditorUIView( locale, editingView );
137+
const positions = uiView.panelPositions;
135138
const editableRect = {
136139
top: 100,
137140
bottom: 200,
@@ -150,6 +153,29 @@ describe( 'InlineEditorUIView', () => {
150153
expect( positions[ 1 ]( editableRect, panelRect ).name ).to.equal( 'toolbar_east' );
151154
} );
152155

156+
it( 'returns the positions in the right order (uiLanguageDirection="rtl")', () => {
157+
locale.uiLanguageDirection = 'rtl';
158+
159+
const uiView = new InlineEditorUIView( locale, editingView );
160+
const positions = uiView.panelPositions;
161+
const editableRect = {
162+
top: 100,
163+
bottom: 200,
164+
left: 100,
165+
right: 100,
166+
width: 100,
167+
height: 100
168+
};
169+
const panelRect = {
170+
width: 50,
171+
height: 50
172+
};
173+
174+
expect( positions ).to.have.length( 2 );
175+
expect( positions[ 0 ]( editableRect, panelRect ).name ).to.equal( 'toolbar_east' );
176+
expect( positions[ 1 ]( editableRect, panelRect ).name ).to.equal( 'toolbar_west' );
177+
} );
178+
153179
describe( 'west', () => {
154180
testTopPositions( 0, 100 );
155181
} );

tests/manual/rtl.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div id="editor" contenteditable="true">
2+
<h2>Editor 1</h2>
3+
<p>This is an editor instance.</p>
4+
</div>
5+
6+
<style>
7+
body {
8+
height: 10000px;
9+
}
10+
</style>

tests/manual/rtl.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4+
*/
5+
6+
/* globals console:false, document, window */
7+
8+
import InlineEditor from '../../src/inlineeditor';
9+
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
10+
11+
InlineEditor
12+
.create( document.querySelector( '#editor' ), {
13+
plugins: [ ArticlePluginSet ],
14+
toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
15+
language: 'ar'
16+
} )
17+
.then( editor => {
18+
console.log( 'Editor has been initialized', editor );
19+
20+
window.editor = editor;
21+
} )
22+
.catch( err => {
23+
console.error( err.stack );
24+
} );

tests/manual/rtl.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Inline editor with right–to–left UI
2+
3+
**Note**: For the best testing, run manual tests adding Arabic to [additional languages configuration](https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/testing-environment.html#running-manual-tests).
4+
5+
---
6+
7+
### Expected
8+
9+
1. The main editor toolbar should be displayed on the **right** side of editable.
10+
1. Same as above but also when the viewport is scrolled and the toolbar is attached to the bottom of editable.

0 commit comments

Comments
 (0)