Skip to content

Commit 1e5b03d

Browse files
authored
Merge pull request #10288 from ckeditor/ck/10180
Fix (source-editing): Selection is now set at the beginning of the source editing view. Closes #10180.
2 parents 4b0fe23 + 23aac89 commit 1e5b03d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/ckeditor5-source-editing/src/sourceediting.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ export default class SourceEditing extends Plugin {
227227

228228
domSourceEditingElementTextarea.value = data;
229229

230+
// Setting a value to textarea moves the input cursor to the end. We want the selection at the beginning.
231+
domSourceEditingElementTextarea.setSelectionRange( 0, 0 );
232+
230233
// Bind the textarea's value to the wrapper's `data-value` property. Each change of the textarea's value updates the
231234
// wrapper's `data-value` property.
232235
domSourceEditingElementTextarea.addEventListener( 'input', () => {

packages/ckeditor5-source-editing/tests/sourceediting.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,16 @@ describe( 'SourceEditing', () => {
390390
expect( document.activeElement ).to.equal( textarea );
391391
} );
392392

393+
it( 'should move the input cursor to the beginning of textarea', () => {
394+
button.fire( 'execute' );
395+
396+
const domRoot = editor.editing.view.getDomRoot();
397+
const textarea = domRoot.nextSibling.children[ 0 ];
398+
399+
expect( textarea.selectionStart ).to.equal( 0 );
400+
expect( textarea.selectionEnd ).to.equal( 0 );
401+
} );
402+
393403
it( 'should focus the editing view after switching back from the source editing mode', () => {
394404
const spy = sinon.spy( editor.editing.view, 'focus' );
395405

0 commit comments

Comments
 (0)