mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(whiteboard): keep editing state when crossing editor
This commit is contained in:
@@ -64,18 +64,7 @@ export class EditorUtil extends TDShapeUtil<T, E> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Component = TDShapeUtil.Component<T, E, TDMeta>(
|
Component = TDShapeUtil.Component<T, E, TDMeta>(
|
||||||
(
|
({ shape, meta: { app }, events, isEditing, onShapeChange }, ref) => {
|
||||||
{
|
|
||||||
shape,
|
|
||||||
meta: {
|
|
||||||
app: { useStore },
|
|
||||||
},
|
|
||||||
events,
|
|
||||||
isEditing,
|
|
||||||
onShapeChange,
|
|
||||||
},
|
|
||||||
ref
|
|
||||||
) => {
|
|
||||||
const containerRef = useRef<HTMLDivElement>();
|
const containerRef = useRef<HTMLDivElement>();
|
||||||
const {
|
const {
|
||||||
workspace,
|
workspace,
|
||||||
@@ -83,7 +72,7 @@ export class EditorUtil extends TDShapeUtil<T, E> {
|
|||||||
size: [width, height],
|
size: [width, height],
|
||||||
} = shape;
|
} = shape;
|
||||||
|
|
||||||
const state = useStore();
|
const state = app.useStore();
|
||||||
const { currentPageId } = state.appState;
|
const { currentPageId } = state.appState;
|
||||||
const { editingId } = state.document.pageStates[currentPageId];
|
const { editingId } = state.document.pageStates[currentPageId];
|
||||||
const { shapes } = state.document.pages[currentPageId];
|
const { shapes } = state.document.pages[currentPageId];
|
||||||
@@ -134,11 +123,19 @@ export class EditorUtil extends TDShapeUtil<T, E> {
|
|||||||
[isEditing]
|
[isEditing]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const activateIfEditing = useCallback(() => {
|
||||||
|
if (editingText && editingId !== shape.id) {
|
||||||
|
app.setEditingText(shape.id);
|
||||||
|
}
|
||||||
|
}, [app, shape.id, editingText, editingId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HTMLContainer ref={ref} {...events}>
|
<HTMLContainer ref={ref} {...events}>
|
||||||
<Container
|
<Container
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
onPointerDown={stopPropagation}
|
onPointerDown={stopPropagation}
|
||||||
|
onMouseEnter={activateIfEditing}
|
||||||
|
onDragEnter={activateIfEditing}
|
||||||
>
|
>
|
||||||
<MemoAffineEditor
|
<MemoAffineEditor
|
||||||
workspace={workspace}
|
workspace={workspace}
|
||||||
|
|||||||
@@ -967,6 +967,29 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used for EditorUtil only
|
||||||
|
* @param id
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setEditingText = (id: string) => {
|
||||||
|
if (this.readOnly) return;
|
||||||
|
|
||||||
|
this.patchState(
|
||||||
|
{
|
||||||
|
document: {
|
||||||
|
pageStates: {
|
||||||
|
[this.currentPageId]: {
|
||||||
|
selectedIds: [id],
|
||||||
|
editingId: id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`set_editing_id`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set or clear the hovered id
|
* Set or clear the hovered id
|
||||||
* @param id [string]
|
* @param id [string]
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ export interface TDMeta {
|
|||||||
isDarkMode: boolean;
|
isDarkMode: boolean;
|
||||||
app: {
|
app: {
|
||||||
useStore: () => TDSnapshot;
|
useStore: () => TDSnapshot;
|
||||||
|
setEditingText: (id: string) => void;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user