From 285a744cba3986551a4efc764d6714bfcbb742b5 Mon Sep 17 00:00:00 2001 From: Siklos Date: Mon, 15 Aug 2022 17:49:51 +0200 Subject: [PATCH] Implement max history --- src/Components/Editor/Editor.tsx | 9 ++++++++- src/Components/History/History.tsx | 4 +--- src/utils/default.ts | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Components/Editor/Editor.tsx b/src/Components/Editor/Editor.tsx index 4337365..784cca4 100644 --- a/src/Components/Editor/Editor.tsx +++ b/src/Components/Editor/Editor.tsx @@ -10,6 +10,7 @@ import { onKeyDown } from './Shortcuts'; import { OnPropertyChange, OnPropertiesSubmit } from './PropertiesOperations'; import EditorEvents from '../../Events/EditorEvents'; import { IEditorState } from '../../Interfaces/IEditorState'; +import { MAX_HISTORY } from '../../utils/default'; interface IEditorProps { configuration: IConfiguration @@ -17,7 +18,13 @@ interface IEditorProps { historyCurrentStep: number } -export const getCurrentHistory = (history: IHistoryState[], historyCurrentStep: number): IHistoryState[] => history.slice(0, historyCurrentStep + 1); +export const getCurrentHistory = (history: IHistoryState[], historyCurrentStep: number): IHistoryState[] => { + return history.slice( + Math.max(0, history.length - MAX_HISTORY), + historyCurrentStep + 1 + ); +}; + export const getCurrentHistoryState = (history: IHistoryState[], historyCurrentStep: number): IHistoryState => history[historyCurrentStep]; const Editor: React.FunctionComponent = (props) => { diff --git a/src/Components/History/History.tsx b/src/Components/History/History.tsx index 30778bd..36e8e80 100644 --- a/src/Components/History/History.tsx +++ b/src/Components/History/History.tsx @@ -14,9 +14,7 @@ export const History: React.FC = (props: IHistoryProps) => { const Row = ({ index, style }: {index: number, style: React.CSSProperties}): JSX.Element => { const reversedIndex = (props.history.length - 1) - index; const step = props.history[reversedIndex]; - const desc = reversedIndex > 0 - ? `${reversedIndex}: ${step.LastAction}` - : 'Go to the beginning'; + const desc = step.LastAction; const selectedClass = reversedIndex === props.historyCurrentStep ? 'bg-blue-500 hover:bg-blue-600' diff --git a/src/utils/default.ts b/src/utils/default.ts index 2bd22dc..027c540 100644 --- a/src/utils/default.ts +++ b/src/utils/default.ts @@ -39,3 +39,5 @@ export const DEFAULT_MAINCONTAINER_PROPS: IProperties = { }; export const NOTCHES_LENGTH = 4; + +export const MAX_HISTORY = 200;