File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
packages/ckeditor5-source-editing Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,9 @@ export default class SourceEditing extends Plugin {
227
227
228
228
domSourceEditingElementTextarea . value = data ;
229
229
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
+
230
233
// Bind the textarea's value to the wrapper's `data-value` property. Each change of the textarea's value updates the
231
234
// wrapper's `data-value` property.
232
235
domSourceEditingElementTextarea . addEventListener ( 'input' , ( ) => {
Original file line number Diff line number Diff line change @@ -390,6 +390,16 @@ describe( 'SourceEditing', () => {
390
390
expect ( document . activeElement ) . to . equal ( textarea ) ;
391
391
} ) ;
392
392
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
+
393
403
it ( 'should focus the editing view after switching back from the source editing mode' , ( ) => {
394
404
const spy = sinon . spy ( editor . editing . view , 'focus' ) ;
395
405
You can’t perform that action at this time.
0 commit comments