diff --git a/administrator/language/en-GB/en-GB.plg_editors_codemirror.ini b/administrator/language/en-GB/en-GB.plg_editors_codemirror.ini index 37b69e57b2071..fa71ce7874b0c 100644 --- a/administrator/language/en-GB/en-GB.plg_editors_codemirror.ini +++ b/administrator/language/en-GB/en-GB.plg_editors_codemirror.ini @@ -11,6 +11,7 @@ PLG_CODEMIRROR_FIELD_AUTOCLOSEBRACKET_DESC="Automatic bracket completion." PLG_CODEMIRROR_FIELD_AUTOCLOSEBRACKET_LABEL="Bracket Completion" PLG_CODEMIRROR_FIELD_AUTOCLOSETAGS_DESC="Automatic tag completion." PLG_CODEMIRROR_FIELD_AUTOCLOSETAGS_LABEL="Tag Completion" +; The following two strings are deprecated and will be removed in J4 PLG_CODEMIRROR_FIELD_AUTOFOCUS_DESC="Auto focus." PLG_CODEMIRROR_FIELD_AUTOFOCUS_LABEL="Auto Focus" PLG_CODEMIRROR_FIELD_CODEFOLDING_DESC="Allow blocks of code to be folded." diff --git a/libraries/src/Form/Field/EditorField.php b/libraries/src/Form/Field/EditorField.php index 2def265d7493b..762e77a82be74 100644 --- a/libraries/src/Form/Field/EditorField.php +++ b/libraries/src/Form/Field/EditorField.php @@ -246,12 +246,24 @@ protected function getInput() { // Get an editor object. $editor = $this->getEditor(); - $readonly = $this->readonly || $this->disabled; + $params = array( + 'autofocus' => $this->autofocus, + 'readonly' => $this->readonly || $this->disabled, + 'syntax' => (string) $this->element['syntax'], + ); return $editor->display( - $this->name, htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'), $this->width, $this->height, $this->columns, $this->rows, - $this->buttons ? (is_array($this->buttons) ? array_merge($this->buttons, $this->hide) : $this->hide) : false, $this->id, $this->asset, - $this->form->getValue($this->authorField), array('syntax' => (string) $this->element['syntax'], 'readonly' => $readonly) + $this->name, + htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'), + $this->width, + $this->height, + $this->columns, + $this->rows, + $this->buttons ? (is_array($this->buttons) ? array_merge($this->buttons, $this->hide) : $this->hide) : false, + $this->id, + $this->asset, + $this->form->getValue($this->authorField), + $params ); } diff --git a/plugins/editors/codemirror/codemirror.php b/plugins/editors/codemirror/codemirror.php index 3f71e6b25b0a3..2cb2226b50590 100644 --- a/plugins/editors/codemirror/codemirror.php +++ b/plugins/editors/codemirror/codemirror.php @@ -179,6 +179,9 @@ public function onGetInsertMethod() public function onDisplay( $name, $content, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null, $params = array()) { + // True if a CodeMirror already has autofocus. Prevent multiple autofocuses. + static $autofocused; + $id = empty($id) ? $name : $id; // Must pass the field id to the buttons in this editor. @@ -198,7 +201,11 @@ public function onDisplay( } // Should we focus on the editor on load? - $options->autofocus = (boolean) $this->params->get('autoFocus', true); + if (!$autofocused) + { + $options->autofocus = isset($params['autofocus']) ? (bool) $params['autofocus'] : false; + $autofocused = $options->autofocus; + } // Until there's a fix for the overflow problem, always wrap lines. $options->lineWrapping = true; diff --git a/plugins/editors/codemirror/codemirror.xml b/plugins/editors/codemirror/codemirror.xml index 5c48b8168bedb..dcdb7c538075d 100644 --- a/plugins/editors/codemirror/codemirror.xml +++ b/plugins/editors/codemirror/codemirror.xml @@ -155,19 +155,6 @@ - - - - -