Render text actions panel on double click (#450)
* Render text actions panel on double click * cleanup wysiwyg on click * use `state.editingElement` instead of global to determine whether t ext panel is shown * clarify comment Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
parent
3715da9966
commit
61be0f7b61
@ -7,6 +7,7 @@ export function getDefaultAppState(): AppState {
|
|||||||
return {
|
return {
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
resizingElement: null,
|
resizingElement: null,
|
||||||
|
editingElement: null,
|
||||||
elementType: "selection",
|
elementType: "selection",
|
||||||
exportBackground: true,
|
exportBackground: true,
|
||||||
currentItemStrokeColor: "#000000",
|
currentItemStrokeColor: "#000000",
|
||||||
|
@ -344,12 +344,18 @@ export class App extends React.Component<{}, AppState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private renderSelectedShapeActions(elements: readonly ExcalidrawElement[]) {
|
private renderSelectedShapeActions(elements: readonly ExcalidrawElement[]) {
|
||||||
const { elementType } = this.state;
|
const { elementType, editingElement } = this.state;
|
||||||
const selectedElements = elements.filter(el => el.isSelected);
|
const selectedElements = elements.filter(el => el.isSelected);
|
||||||
const hasSelectedElements = selectedElements.length > 0;
|
const hasSelectedElements = selectedElements.length > 0;
|
||||||
const isTextToolSelected = elementType === "text";
|
const isTextToolSelected = elementType === "text";
|
||||||
const isShapeToolSelected = elementType !== "selection";
|
const isShapeToolSelected = elementType !== "selection";
|
||||||
if (!(hasSelectedElements || isShapeToolSelected || isTextToolSelected)) {
|
const isEditingText = editingElement && editingElement.type === "text";
|
||||||
|
if (
|
||||||
|
!hasSelectedElements &&
|
||||||
|
!isShapeToolSelected &&
|
||||||
|
!isTextToolSelected &&
|
||||||
|
!isEditingText
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,7 +409,7 @@ export class App extends React.Component<{}, AppState> {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(hasText(elements) || isTextToolSelected) && (
|
{(hasText(elements) || isTextToolSelected || isEditingText) && (
|
||||||
<>
|
<>
|
||||||
{this.actionManager.renderAction(
|
{this.actionManager.renderAction(
|
||||||
"changeFontSize",
|
"changeFontSize",
|
||||||
@ -800,11 +806,15 @@ export class App extends React.Component<{}, AppState> {
|
|||||||
elements = [...elements, { ...element, isSelected: true }];
|
elements = [...elements, { ...element, isSelected: true }];
|
||||||
this.setState({
|
this.setState({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
|
editingElement: null,
|
||||||
elementType: "selection"
|
elementType: "selection"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.setState({ elementType: "selection" });
|
this.setState({
|
||||||
|
elementType: "selection",
|
||||||
|
editingElement: element
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1095,6 +1105,8 @@ export class App extends React.Component<{}, AppState> {
|
|||||||
100
|
100
|
||||||
) as ExcalidrawTextElement;
|
) as ExcalidrawTextElement;
|
||||||
|
|
||||||
|
this.setState({ editingElement: element });
|
||||||
|
|
||||||
let initText = "";
|
let initText = "";
|
||||||
let textX = e.clientX;
|
let textX = e.clientX;
|
||||||
let textY = e.clientY;
|
let textY = e.clientY;
|
||||||
@ -1149,6 +1161,7 @@ export class App extends React.Component<{}, AppState> {
|
|||||||
elements = [...elements, { ...element, isSelected: true }];
|
elements = [...elements, { ...element, isSelected: true }];
|
||||||
this.setState({
|
this.setState({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
|
editingElement: null,
|
||||||
elementType: "selection"
|
elementType: "selection"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ import { ExcalidrawElement } from "./element/types";
|
|||||||
export type AppState = {
|
export type AppState = {
|
||||||
draggingElement: ExcalidrawElement | null;
|
draggingElement: ExcalidrawElement | null;
|
||||||
resizingElement: ExcalidrawElement | null;
|
resizingElement: ExcalidrawElement | null;
|
||||||
|
// element being edited, but not necessarily added to elements array yet
|
||||||
|
// (e.g. text element when typing into the input)
|
||||||
|
editingElement: ExcalidrawElement | null;
|
||||||
elementType: string;
|
elementType: string;
|
||||||
exportBackground: boolean;
|
exportBackground: boolean;
|
||||||
currentItemStrokeColor: string;
|
currentItemStrokeColor: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user