Matthias Mullie has uploaded a new change for review. https://gerrit.wikimedia.org/r/98497
Change subject: Alternative method to focus textarea ...................................................................... Alternative method to focus textarea Textarea focus should not be handled by the editor object itself. Reason: clicking the "add new topic" title input field will add a textarea which loads an editor, which will steal focus from the title input field. Instead, focus should be applied earlier in the code. Meanwhile also changed how initial height is set; better to re-use same code. And I've removed setSelectionRange( 0, 0 ). Not really sure it that's ok, but I couldn't really figure out why that was needed (I wouldn't expect the cursor to be in front of all text, but that may just be me) Bug: 57275 Change-Id: I62b767c922441a70e5bafe557d498f74c306a4ee --- M modules/base/ui-functions.js M modules/editor/editors/ext.flow.editors.none.js 2 files changed, 12 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/97/98497/1 diff --git a/modules/base/ui-functions.js b/modules/base/ui-functions.js index cf3daa7..b2dc77d 100644 --- a/modules/base/ui-functions.js +++ b/modules/base/ui-functions.js @@ -148,7 +148,15 @@ }; } - mw.flow.editor.load( $postForm.find( 'textarea' ), initialContent.content, initialContent.format ); + /* + * Setting focus inside an event that grants focus (like + * clicking the edit icon), is tricky. This is a workaround. + */ + setTimeout( function( $postForm, initialContent ) { + var $textarea = $postForm.find( 'textarea' ); + $textarea.focus(); + mw.flow.editor.load( $textarea, initialContent.content, initialContent.format ); + }.bind( this, $postForm, initialContent ), 0 ); $contentContainer.hide(); diff --git a/modules/editor/editors/ext.flow.editors.none.js b/modules/editor/editors/ext.flow.editors.none.js index f1b02aa..a611f94 100644 --- a/modules/editor/editors/ext.flow.editors.none.js +++ b/modules/editor/editors/ext.flow.editors.none.js @@ -12,12 +12,12 @@ this.$node.css( 'overflow', 'hidden' ); this.$node.css( 'resize', 'none' ); - this.$node.height( this.$node.prop( 'scrollHeight' ) ); // auto-expansion shouldn't shrink too much; set default height as min this.$node.css( 'min-height', this.$node.outerHeight() ); + + // initialize at height of existing content & update on every keyup this.$node.keyup( this.autoExpand ); - this.$node.focus(); - this.$node[0].setSelectionRange( 0, 0 ); + this.autoExpand.call( this.$node.get( 0 ) ); }; /** -- To view, visit https://gerrit.wikimedia.org/r/98497 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I62b767c922441a70e5bafe557d498f74c306a4ee Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits