fix: autofocus editor when creating notes
This commit is contained in:
1 parent
3c2cfb895e
commit
db465bb1ef
3 files changed
+18
-9
No files matched your search
@@ -1102,7 +1102,10 @@ export const EditorPane = (props: EditorPaneProps) => {
|
||||
return (
|
||||
<RichEditorPane
|
||||
{...props}
|
||||
mobileDefaultEditMemoId={null}
|
||||
// On desktop this is also the create-note autofocus request. On mobile
|
||||
// the native editor branch above consumes it before RichEditorPane is
|
||||
// rendered.
|
||||
mobileDefaultEditMemoId={props.mobileDefaultEditMemoId}
|
||||
onRequestMobileNativeEdit={() => {
|
||||
if (props.memo?.id && !readOnly) {
|
||||
setMobileNativeEditMemoId(props.memo.id);
|
||||
@@ -1263,12 +1266,18 @@ const RichEditorPane = ({
|
||||
}
|
||||
|
||||
const currentEditor = editorRef.current;
|
||||
if (!isMobileViewport && isEditorReady(currentEditor)) {
|
||||
currentEditor.commands.focus("end");
|
||||
return;
|
||||
if (!isMobileViewport) {
|
||||
if (isEditorReady(currentEditor) && hydratedMemoIdRef.current === memo.id) {
|
||||
currentEditor.commands.focus("end");
|
||||
onMobileDefaultEditConsumed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (attempt < 10) {
|
||||
// The editor is mounted before its memo hydration/edit session
|
||||
// finishes. Keep retrying across that async boundary so a newly
|
||||
// created note reliably receives the caret on desktop as well.
|
||||
if (attempt < 120) {
|
||||
focusWhenReady(attempt + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1301,9 +1301,9 @@ export const WorkspaceApp = ({
|
||||
const selectedMemoInList = selectedMemoId ? memos.some((memo) => memo.id === selectedMemoId) : false;
|
||||
|
||||
if (createdMemoEditId && selectedMemoId === createdMemoEditId) {
|
||||
if (selectedMemoInList) {
|
||||
setCreatedMemoEditId(null);
|
||||
}
|
||||
// Keep the create request alive until the editor consumes it. The new
|
||||
// memo can appear in the list before its detail query has mounted the
|
||||
// editor, and clearing it here would lose the autofocus request.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "edgeever",
|
||||
"version": "1.6.16",
|
||||
"version": "1.6.17",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"workspaces": [
|
||||
|
||||
Reference in new issue
Block a user