Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code mirror autofocus issue #20270

Merged
merged 4 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
20 changes: 16 additions & 4 deletions libraries/src/Form/Field/EditorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
9 changes: 8 additions & 1 deletion plugins/editors/codemirror/codemirror.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
13 changes: 0 additions & 13 deletions plugins/editors/codemirror/codemirror.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,6 @@
<option value="0">JOFF</option>
</field>

<field
name="autoFocus"
type="radio"
label="PLG_CODEMIRROR_FIELD_AUTOFOCUS_LABEL"
description="PLG_CODEMIRROR_FIELD_AUTOFOCUS_DESC"
class="btn-group btn-group-yesno"
default="1"
filter="options"
>
<option value="1">JON</option>
<option value="0">JOFF</option>
</field>

<field
name="keyMap"
type="list"
Expand Down