Skip to content
Snippets Groups Projects
Commit e4ee3276 authored by Loïc Correnson's avatar Loïc Correnson Committed by Michele Alberti
Browse files

[ivette] fix delete last history item

parent 785e2f14
No related branches found
No related tags found
No related merge requests found
...@@ -155,9 +155,7 @@ const RenderConsole = () => { ...@@ -155,9 +155,7 @@ const RenderConsole = () => {
const [cursor, setCursor] = React.useState(-1); const [cursor, setCursor] = React.useState(-1);
const [H0, setH0] = Dome.useState('Controller.history', []); const [H0, setH0] = Dome.useState('Controller.history', []);
const [isEmpty, setEmpty] = React.useState(true); const [isEmpty, setEmpty] = React.useState(true);
Dome.useEmitter(editor, 'change', () => { const [noTrash, setNoTrash] = React.useState(true);
setEmpty(editor.getValue().trim() === '');
});
// Cope with merge settings that keeps previous array entries (BUG in DOME) // Cope with merge settings that keeps previous array entries (BUG in DOME)
const history = Array.isArray(H0) ? H0.filter((h) => h !== '') : []; const history = Array.isArray(H0) ? H0.filter((h) => h !== '') : [];
...@@ -166,6 +164,12 @@ const RenderConsole = () => { ...@@ -166,6 +164,12 @@ const RenderConsole = () => {
setH0(n < 50 ? hs.concat(Array(50 - n).fill('')) : hs); setH0(n < 50 ? hs.concat(Array(50 - n).fill('')) : hs);
}; };
Dome.useEmitter(editor, 'change', () => {
const cmd = editor.getValue().trim();
setEmpty(cmd === '');
setNoTrash(cursor === 0 && history.length === 1 && cmd === history[0]);
});
const doReload = () => { const doReload = () => {
const cfg = Server.getConfig(); const cfg = Server.getConfig();
const hst = insertConfig(history, cfg); const hst = insertConfig(history, cfg);
...@@ -210,7 +214,8 @@ const RenderConsole = () => { ...@@ -210,7 +214,8 @@ const RenderConsole = () => {
const doRemove = () => { const doRemove = () => {
const n = history.length; const n = history.length;
if (n > 1) { if (n <= 1) doReload();
else {
const hst = history.slice(); const hst = history.slice();
const pad = scratch.current; const pad = scratch.current;
hst.splice(cursor, 1); hst.splice(cursor, 1);
...@@ -219,11 +224,6 @@ const RenderConsole = () => { ...@@ -219,11 +224,6 @@ const RenderConsole = () => {
const next = cursor > 0 ? cursor - 1 : 0; const next = cursor > 0 ? cursor - 1 : 0;
editor.setValue(pad[next]); editor.setValue(pad[next]);
setCursor(next); setCursor(next);
} else {
// Do not share the two arrays!
setHistory(['']);
scratch.current = [''];
editor.clear();
} }
}; };
...@@ -235,7 +235,7 @@ const RenderConsole = () => { ...@@ -235,7 +235,7 @@ const RenderConsole = () => {
let LABEL: string | JSX.Element = 'Console'; let LABEL: string | JSX.Element = 'Console';
if (edited) { if (edited) {
LABEL = ( LABEL = (
<Label title="Rank in history"> <Label title="History (last command comes first)">
Command Command
<span className="controller-rank"> <span className="controller-rank">
{1 + cursor} / {n} {1 + cursor} / {n}
...@@ -249,15 +249,16 @@ const RenderConsole = () => { ...@@ -249,15 +249,16 @@ const RenderConsole = () => {
<IconButton <IconButton
icon="TRASH" icon="TRASH"
display={edited} display={edited}
disabled={noTrash}
onClick={doRemove} onClick={doRemove}
title="Discard command from History" title="Discard command from history (irreversible)"
/> />
<Space /> <Space />
<IconButton <IconButton
icon="RELOAD" icon="RELOAD"
display={edited} display={edited}
onClick={doReload} onClick={doReload}
title="Discard edited commands" title="Discard changes"
/> />
<IconButton <IconButton
icon="MEDIA.PREV" icon="MEDIA.PREV"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment