From 2bb30f1e763d813b40c7f0aa3a6f2b9880d1ce1c Mon Sep 17 00:00:00 2001 From: zhixzhan Date: Fri, 13 Mar 2020 10:43:33 +0800 Subject: [PATCH 1/2] auto focus to editor --- .../client/src/pages/language-generation/code-editor.tsx | 4 ++-- .../client/src/pages/language-understanding/code-editor.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Composer/packages/client/src/pages/language-generation/code-editor.tsx b/Composer/packages/client/src/pages/language-generation/code-editor.tsx index fabd5b42f1..4c535e8a3b 100644 --- a/Composer/packages/client/src/pages/language-generation/code-editor.tsx +++ b/Composer/packages/client/src/pages/language-generation/code-editor.tsx @@ -44,7 +44,7 @@ const CodeEditor: React.FC = props => { const hash = props.location?.hash ?? ''; const hashLine = querystring.parse(hash).L; - const line = Array.isArray(hashLine) ? +hashLine[0] : typeof hashLine === 'string' ? +hashLine : undefined; + const line = Array.isArray(hashLine) ? +hashLine[0] : typeof hashLine === 'string' ? +hashLine : 0; const inlineMode = !!template; const [content, setContent] = useState(template?.body || file?.content); @@ -69,7 +69,7 @@ const CodeEditor: React.FC = props => { }; useEffect(() => { - if (lgEditor && line !== undefined) { + if (lgEditor) { window.requestAnimationFrame(() => { lgEditor.revealLine(line); lgEditor.focus(); diff --git a/Composer/packages/client/src/pages/language-understanding/code-editor.tsx b/Composer/packages/client/src/pages/language-understanding/code-editor.tsx index 577b47acdc..20724c5a66 100644 --- a/Composer/packages/client/src/pages/language-understanding/code-editor.tsx +++ b/Composer/packages/client/src/pages/language-understanding/code-editor.tsx @@ -43,7 +43,7 @@ const CodeEditor: React.FC = props => { const hash = props.location?.hash ?? ''; const hashLine = querystring.parse(hash).L; - const line = Array.isArray(hashLine) ? +hashLine[0] : typeof hashLine === 'string' ? +hashLine : undefined; + const line = Array.isArray(hashLine) ? +hashLine[0] : typeof hashLine === 'string' ? +hashLine : 0; const inlineMode = !!intent; const [content, setContent] = useState(intent?.Body || file?.content); @@ -66,7 +66,7 @@ const CodeEditor: React.FC = props => { }; useEffect(() => { - if (luEditor && line !== undefined) { + if (luEditor) { window.requestAnimationFrame(() => { luEditor.revealLine(line); luEditor.focus(); From 8b3b5af5805d10ba62ed3c2fbdd0deb11eeff3ff Mon Sep 17 00:00:00 2001 From: zhixzhan Date: Fri, 13 Mar 2020 11:14:49 +0800 Subject: [PATCH 2/2] auto focus to new one --- .../client/src/pages/language-generation/table-view.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Composer/packages/client/src/pages/language-generation/table-view.tsx b/Composer/packages/client/src/pages/language-generation/table-view.tsx index 3765e83f7a..f9c049e468 100644 --- a/Composer/packages/client/src/pages/language-generation/table-view.tsx +++ b/Composer/packages/client/src/pages/language-generation/table-view.tsx @@ -39,6 +39,8 @@ const TableView: React.FC = props => { const activeDialog = dialogs.find(({ id }) => id === fileId); + const [focusedIndex, setFocusedIndex] = useState(0); + useEffect(() => { if (!file || isEmpty(file)) return; @@ -87,6 +89,7 @@ const TableView: React.FC = props => { toTemplateName: resolvedName, }; copyLgTemplate(payload); + setFocusedIndex(templates.length); }, [templates, file] ); @@ -229,6 +232,7 @@ const TableView: React.FC = props => {