Skip to content

Commit

Permalink
Merge pull request #10288 from ckeditor/ck/10180
Browse files Browse the repository at this point in the history
Fix (source-editing): Selection is now set at the beginning of the source editing view. Closes #10180.
  • Loading branch information
psmyrek authored Aug 3, 2021
2 parents 4b0fe23 + 23aac89 commit 1e5b03d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/ckeditor5-source-editing/src/sourceediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ export default class SourceEditing extends Plugin {

domSourceEditingElementTextarea.value = data;

// Setting a value to textarea moves the input cursor to the end. We want the selection at the beginning.
domSourceEditingElementTextarea.setSelectionRange( 0, 0 );

// Bind the textarea's value to the wrapper's `data-value` property. Each change of the textarea's value updates the
// wrapper's `data-value` property.
domSourceEditingElementTextarea.addEventListener( 'input', () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/ckeditor5-source-editing/tests/sourceediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ describe( 'SourceEditing', () => {
expect( document.activeElement ).to.equal( textarea );
} );

it( 'should move the input cursor to the beginning of textarea', () => {
button.fire( 'execute' );

const domRoot = editor.editing.view.getDomRoot();
const textarea = domRoot.nextSibling.children[ 0 ];

expect( textarea.selectionStart ).to.equal( 0 );
expect( textarea.selectionEnd ).to.equal( 0 );
} );

it( 'should focus the editing view after switching back from the source editing mode', () => {
const spy = sinon.spy( editor.editing.view, 'focus' );

Expand Down

0 comments on commit 1e5b03d

Please sign in to comment.