fix: move Ctrl+A useEffect after notes declaration to avoid TDZ error

This commit is contained in:
2026-07-25 20:38:53 +07:00
parent f4ec769650
commit 29b682e3ba
2 changed files with 14 additions and 14 deletions
+12 -12
View File
@@ -4563,18 +4563,6 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
window.addEventListener('mouseup', up);
return () => window.removeEventListener('mouseup', up);
}, []);
React.useEffect(() => {
const handler = (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
const target = e.target;
if (target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable)) return;
e.preventDefault();
setSelectedNoteIds(notes.map(n => n.id));
}
};
window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, [notes, setSelectedNoteIds]);
const NoteHeight = 18;
const PITCH_START = 0; // C0 (render all 128 keys)
@@ -4598,6 +4586,18 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
const notesRef = React.useRef(notes);
notesRef.current = notes;
React.useEffect(() => { setNotes(st.notes || []); }, [st.notes]);
React.useEffect(() => {
const handler = (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
const target = e.target;
if (target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable)) return;
e.preventDefault();
setSelectedNoteIds(notes.map(n => n.id));
}
};
window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, [notes, setSelectedNoteIds]);
const brushVelocityRef = React.useRef(0.8);
const [selectedNoteIds, setSelectedNoteIds] = React.useState([]);