Code-Schnipsel History: Diff vs. aktuellem Code, Wiederherstellen nur bei Unterschied
This commit is contained in:
@@ -148,7 +148,10 @@ function HistoryModal({ snippet, onClose, onRestore, toast }) {
|
|||||||
const isMob = window.innerWidth < 768;
|
const isMob = window.innerWidth < 768;
|
||||||
const getOlderCode = (h) => {
|
const getOlderCode = (h) => {
|
||||||
const idx = history.indexOf(h);
|
const idx = history.indexOf(h);
|
||||||
return idx < history.length-1 ? history[idx+1].code : null;
|
// Newest history entry (idx=0) compares against CURRENT snippet code
|
||||||
|
if (idx === 0) return snippet.code;
|
||||||
|
// Older entries compare against the next newer history entry
|
||||||
|
return history[idx - 1].code;
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div style={{position:'fixed',inset:0,background:'rgba(0,0,0,0.85)',zIndex:7000,
|
<div style={{position:'fixed',inset:0,background:'rgba(0,0,0,0.85)',zIndex:7000,
|
||||||
@@ -194,9 +197,9 @@ function HistoryModal({ snippet, onClose, onRestore, toast }) {
|
|||||||
<div style={{display:'flex',alignItems:'center',justifyContent:'space-between',flexWrap:'wrap',gap:6}}>
|
<div style={{display:'flex',alignItems:'center',justifyContent:'space-between',flexWrap:'wrap',gap:6}}>
|
||||||
<span style={{color:'rgba(255,255,255,0.35)',fontFamily:'monospace',fontSize:10}}>
|
<span style={{color:'rgba(255,255,255,0.35)',fontFamily:'monospace',fontSize:10}}>
|
||||||
{getLangLabel(selected.language)} · {fmtDt(selected.saved_at)}
|
{getLangLabel(selected.language)} · {fmtDt(selected.saved_at)}
|
||||||
{showDiff && getOlderCode(selected)===null && <span style={{color:'rgba(255,255,255,0.2)',marginLeft:6}}>(älteste Version)</span>}
|
{history.indexOf(selected) === history.length-1 && <span style={{color:'rgba(255,255,255,0.2)',marginLeft:6}}>(älteste Version)</span>}
|
||||||
</span>
|
</span>
|
||||||
{!snippet.is_shared && (
|
{!snippet.is_shared && selected.code !== snippet.code && (
|
||||||
<button onClick={()=>onRestore(selected)} style={{
|
<button onClick={()=>onRestore(selected)} style={{
|
||||||
background:'rgba(255,230,109,0.1)',border:'1px solid rgba(255,230,109,0.25)',
|
background:'rgba(255,230,109,0.1)',border:'1px solid rgba(255,230,109,0.25)',
|
||||||
borderRadius:6,color:'#ffe66d',cursor:'pointer',fontSize:10,padding:'4px 10px'}}>
|
borderRadius:6,color:'#ffe66d',cursor:'pointer',fontSize:10,padding:'4px 10px'}}>
|
||||||
|
|||||||
Reference in New Issue
Block a user