Skip to content

Commit

Permalink
Add Clear Button on Tune Editor (hackclub#1488)
Browse files Browse the repository at this point in the history
* Add Clear Button on Tune Editor

as mentioned on hackclub#905 , i have added clear button which clear the sequence rather than right click each line

* Added Comment For Friendly Codebase

as @JosiasAurel requested , i have added the function description + comment.

* add a chicky missing } to the code
  • Loading branch information
DevIos01 committed Mar 7, 2024
1 parent 5409dc8 commit 8c84fbd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/subeditors/sequencer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ export default function SequencerEditor(props: EditorProps) {
const preventContextMenu = (event: MouseEvent) => { event.preventDefault(); }
window.addEventListener('contextmenu', preventContextMenu)

/**
* Clear the sequencer editor.
* This function:
* - Clears the cells from the sequencer
* - Sets the lastDraw (used for drawing lines) to null
* - Clears the text in the editor
*/
const clearSequencer = () => {
cells.value = {}; // Remove all cells from the sequencer
lastDraw.value = null; // Reset the draw cursor
props.text.value = ""; // Clear the text in the editor
}

// Sync text changes with cells
useSignalEffect(() => {
const newCells = tuneToCells(textToTune(props.text.value))
Expand Down Expand Up @@ -196,6 +209,15 @@ export default function SequencerEditor(props: EditorProps) {
beat.value = 0
}}
/>
<Button
onClick={() => {
const isConfirmed = confirm('Are you sure you want to clear the sequencer?');
if (isConfirmed) {
clearSequencer();
}
}}
> {'Clear'}
</Button>
</div>

<div class={styles.bpm}>
Expand Down

0 comments on commit 8c84fbd

Please sign in to comment.