Add shortcut description to right click + add Suppr shortcut + Fix next selection after deletion
This commit is contained in:
parent
4e3c5d71fd
commit
d580890b9d
6 changed files with 87 additions and 9 deletions
|
@ -105,7 +105,7 @@ export function DeleteContainer(
|
||||||
/**
|
/**
|
||||||
* Returns the next container that will be selected
|
* Returns the next container that will be selected
|
||||||
* after the selectedContainer is removed.
|
* after the selectedContainer is removed.
|
||||||
* If the selected container is removed, select the sibling before,
|
* If the selected container is removed, select the sibling after,
|
||||||
* If there is no sibling, select the parent,
|
* If there is no sibling, select the parent,
|
||||||
*
|
*
|
||||||
* @param mainContainerClone Main container
|
* @param mainContainerClone Main container
|
||||||
|
@ -121,7 +121,7 @@ function GetSelectedContainerOnDelete(
|
||||||
index: number
|
index: number
|
||||||
): string {
|
): string {
|
||||||
const newSelectedContainer = FindContainerById(mainContainerClone, selectedContainerId) ??
|
const newSelectedContainer = FindContainerById(mainContainerClone, selectedContainerId) ??
|
||||||
parent.children.at(index - 1) ??
|
parent.children.at(index) ??
|
||||||
parent;
|
parent;
|
||||||
const newSelectedContainerId = newSelectedContainer.properties.id;
|
const newSelectedContainerId = newSelectedContainer.properties.id;
|
||||||
return newSelectedContainerId;
|
return newSelectedContainerId;
|
||||||
|
|
|
@ -6,7 +6,8 @@ export function OnKey(
|
||||||
event: KeyboardEvent,
|
event: KeyboardEvent,
|
||||||
history: IHistoryState[],
|
history: IHistoryState[],
|
||||||
historyCurrentStep: number,
|
historyCurrentStep: number,
|
||||||
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
|
setHistoryCurrentStep: Dispatch<SetStateAction<number>>,
|
||||||
|
deleteAction: () => void
|
||||||
): void {
|
): void {
|
||||||
if (!ENABLE_SHORTCUTS) {
|
if (!ENABLE_SHORTCUTS) {
|
||||||
return;
|
return;
|
||||||
|
@ -24,5 +25,7 @@ export function OnKey(
|
||||||
event.ctrlKey &&
|
event.ctrlKey &&
|
||||||
historyCurrentStep < history.length - 1) {
|
historyCurrentStep < history.length - 1) {
|
||||||
setHistoryCurrentStep(historyCurrentStep + 1);
|
setHistoryCurrentStep(historyCurrentStep + 1);
|
||||||
|
} else if (event.key === 'Delete') {
|
||||||
|
deleteAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ function InitActions(
|
||||||
[{
|
[{
|
||||||
text: 'Delete',
|
text: 'Delete',
|
||||||
title: 'Delete the container',
|
title: 'Delete the container',
|
||||||
|
shortcut: '<kbd>Suppr</kbd>',
|
||||||
action: (target: HTMLElement) => {
|
action: (target: HTMLElement) => {
|
||||||
const id = target.id;
|
const id = target.id;
|
||||||
const newHistory = DeleteContainer(
|
const newHistory = DeleteContainer(
|
||||||
|
@ -50,6 +51,7 @@ function InitActions(
|
||||||
[{
|
[{
|
||||||
text: 'Delete',
|
text: 'Delete',
|
||||||
title: 'Delete the container',
|
title: 'Delete the container',
|
||||||
|
shortcut: '<kbd>Suppr</kbd>',
|
||||||
action: (target: HTMLElement) => {
|
action: (target: HTMLElement) => {
|
||||||
const id = target.id;
|
const id = target.id;
|
||||||
const newHistory = DeleteSymbol(
|
const newHistory = DeleteSymbol(
|
||||||
|
@ -99,7 +101,8 @@ function InitActions(
|
||||||
function UseShortcuts(
|
function UseShortcuts(
|
||||||
history: IHistoryState[],
|
history: IHistoryState[],
|
||||||
historyCurrentStep: number,
|
historyCurrentStep: number,
|
||||||
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
|
setHistoryCurrentStep: Dispatch<SetStateAction<number>>,
|
||||||
|
deleteAction: () => void
|
||||||
): void {
|
): void {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function OnKeyUp(event: KeyboardEvent): void {
|
function OnKeyUp(event: KeyboardEvent): void {
|
||||||
|
@ -107,7 +110,8 @@ function UseShortcuts(
|
||||||
event,
|
event,
|
||||||
history,
|
history,
|
||||||
historyCurrentStep,
|
historyCurrentStep,
|
||||||
setHistoryCurrentStep
|
setHistoryCurrentStep,
|
||||||
|
deleteAction
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +204,17 @@ export function Editor(props: IEditorProps): JSX.Element {
|
||||||
const setNewHistory = UseNewHistoryState(setHistory, setHistoryCurrentStep);
|
const setNewHistory = UseNewHistoryState(setHistory, setHistoryCurrentStep);
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
UseShortcuts(history, historyCurrentStep, setHistoryCurrentStep);
|
UseShortcuts(
|
||||||
|
history,
|
||||||
|
historyCurrentStep,
|
||||||
|
setHistoryCurrentStep,
|
||||||
|
() => {
|
||||||
|
const current = GetCurrentHistoryState(history, historyCurrentStep);
|
||||||
|
setNewHistory(
|
||||||
|
DeleteContainer(current.selectedContainerId, history, historyCurrentStep)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
UseCustomEvents(
|
UseCustomEvents(
|
||||||
props.root,
|
props.root,
|
||||||
history,
|
history,
|
||||||
|
|
|
@ -16,6 +16,9 @@ export interface IMenuAction {
|
||||||
/** title to show on hover */
|
/** title to show on hover */
|
||||||
title?: string
|
title?: string
|
||||||
|
|
||||||
|
/** description of the shortcut */
|
||||||
|
shortcut?: string
|
||||||
|
|
||||||
/** function to be called on button click */
|
/** function to be called on button click */
|
||||||
action: (target: HTMLElement) => void
|
action: (target: HTMLElement) => void
|
||||||
}
|
}
|
||||||
|
@ -101,6 +104,7 @@ export function Menu(props: IMenuProps): JSX.Element {
|
||||||
className={'contextmenu-item'}
|
className={'contextmenu-item'}
|
||||||
text={action.text}
|
text={action.text}
|
||||||
title={action.title}
|
title={action.title}
|
||||||
|
shortcut={action.shortcut}
|
||||||
onClick={() => action.action(target)} />);
|
onClick={() => action.action(target)} />);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,15 +4,18 @@ interface IMenuItemProps {
|
||||||
className?: string
|
className?: string
|
||||||
text: string
|
text: string
|
||||||
title?: string
|
title?: string
|
||||||
|
shortcut?: string
|
||||||
onClick: () => void
|
onClick: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MenuItem(props: IMenuItemProps): JSX.Element {
|
export function MenuItem(props: IMenuItemProps): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<button type="button"
|
<button type="button"
|
||||||
className={props.className}
|
className={`flex place-content-between ${props.className ?? ''}`}
|
||||||
title={props.title}
|
title={props.title}
|
||||||
onClick={() => props.onClick()}>{props.text}
|
onClick={() => props.onClick()}>
|
||||||
|
{props.text}
|
||||||
|
<span dangerouslySetInnerHTML={{ __html: props.shortcut ?? '' }} />
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,61 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
stroke: 'green',
|
stroke: 'green',
|
||||||
fill: 'white'
|
fill: 'white'
|
||||||
},
|
},
|
||||||
Category: "Stuff"
|
Category: "Stuff",
|
||||||
|
Actions: [
|
||||||
|
{
|
||||||
|
Id: "SplitRemplissage",
|
||||||
|
Action: "SplitRemplissage",
|
||||||
|
Label: "Diviser le remplissage en insérant un montant",
|
||||||
|
Description: "Diviser le remplissage en insérant un montant",
|
||||||
|
CustomLogo: {
|
||||||
|
Base64Image: null,
|
||||||
|
Name: 'Image1',
|
||||||
|
Svg: null,
|
||||||
|
Url: ""
|
||||||
|
},
|
||||||
|
AddingBehavior: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "SplitRemplissageParent",
|
||||||
|
Action: "SplitRemplissageParent",
|
||||||
|
Label: "Diviser le remplissage en insérant un montant",
|
||||||
|
Description: "Diviser le remplissage en insérant un montant",
|
||||||
|
CustomLogo: {
|
||||||
|
Base64Image: null,
|
||||||
|
Name: 'Image1',
|
||||||
|
Svg: null,
|
||||||
|
Url: ""
|
||||||
|
},
|
||||||
|
AddingBehavior: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "SplitRemplissageParent",
|
||||||
|
Action: "SplitRemplissageParent",
|
||||||
|
Label: "Diviser le remplissage en insérant un montant",
|
||||||
|
Description: "Diviser le remplissage en insérant un montant",
|
||||||
|
CustomLogo: {
|
||||||
|
Base64Image: null,
|
||||||
|
Name: 'Image1',
|
||||||
|
Svg: null,
|
||||||
|
Url: ""
|
||||||
|
},
|
||||||
|
AddingBehavior: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "SplitRemplissageParent",
|
||||||
|
Action: "SplitRemplissageParent",
|
||||||
|
Label: "Diviser le remplissage en insérant un montant",
|
||||||
|
Description: "Diviser le remplissage en insérant un montant",
|
||||||
|
CustomLogo: {
|
||||||
|
Base64Image: null,
|
||||||
|
Name: 'Image1',
|
||||||
|
Svg: null,
|
||||||
|
Url: ""
|
||||||
|
},
|
||||||
|
AddingBehavior: 3
|
||||||
|
}
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: 'Remplissage',
|
Type: 'Remplissage',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue