From 47cfa0cf45f6c26b7ea432ae012d19ec1e0992de Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 13 Sep 2017 18:09:55 +0200 Subject: [PATCH] Focus the editable content when opening a codemirror pad --- www/code/inner.js | 11 ----------- www/common/sframe-common-codemirror.js | 1 + www/common/sframe-common-interface.js | 8 +++++++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/www/code/inner.js b/www/code/inner.js index 306b57ff5..382b90fe4 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -163,14 +163,6 @@ define([ content: textValue, metadata: metadataMgr.getMetadataLazy() }; - /* metadata: { - users: UserList.userData, - defaultTitle: Title.defaultTitle - } - }; - if (!initializing) { - obj.metadata.title = Title.title; - }*/ // set mode too... obj.highlightMode = CodeMirror.highlightMode; @@ -428,9 +420,6 @@ define([ //console.log("%s => %s", CodeMirror.highlightMode, CodeMirror.$language.val()); } - // Update the user list (metadata) from the hyperjson - //Metadata.update(userDoc); - if (newDoc) { editor.setValue(newDoc); } diff --git a/www/common/sframe-common-codemirror.js b/www/common/sframe-common-codemirror.js index 4c0fe5cfc..6686a9a55 100644 --- a/www/common/sframe-common-codemirror.js +++ b/www/common/sframe-common-codemirror.js @@ -49,6 +49,7 @@ define([ readOnly: true }); editor.setValue(Messages.codeInitialState); + editor.focus(); var setMode = exp.setMode = function (mode, cb) { exp.highlightMode = mode; diff --git a/www/common/sframe-common-interface.js b/www/common/sframe-common-interface.js index 6c228e3cb..0a7306cdf 100644 --- a/www/common/sframe-common-interface.js +++ b/www/common/sframe-common-interface.js @@ -454,9 +454,13 @@ define([ var metadataMgr = common.getMetadataMgr(); var type = metadataMgr.getMetadataLazy().type; var sframeChan = common.getSframeChannel(); + var focus; var onConfirm = function (yes) { - if (!yes) { return; } + if (!yes) { + if (focus) { focus.focus(); } + return; + } var first = true; // We can only pick a template once (for a new document) var fileDialogCfg = { onSelect: function (data) { @@ -467,6 +471,7 @@ define([ Cryptpad.removeLoadingScreen(); common.feedback('TEMPLATE_USED'); }); + if (focus) { focus.focus(); } return; } } @@ -481,6 +486,7 @@ define([ sframeChan.query("Q_TEMPLATE_EXIST", type, function (err, data) { if (data) { + focus = document.activeElement; Cryptpad.confirm(Messages.useTemplate, onConfirm, { ok: Messages.useTemplateOK, cancel: Messages.useTemplateCancel,