-
Notifications
You must be signed in to change notification settings - Fork 4
Note-entry preview cell + Logic-style ruler snap #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a7fc3ed
feat(editor): note-entry preview cell + Logic-style ruler snap
f034fb5
fix(editor): declare caretFret in state, drop a dead width clamp, rea…
byrongamatos e29aac3
fix(editor): CodeRabbit round — snapped-time advance, live Alt scrub,…
byrongamatos 91b6fa2
fix(editor): the entry-preview cell must sit where the note will land
byrongamatos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ __pycache__/ | |
| *.pyc | ||
| .pytest_cache/ | ||
| .tmp/ | ||
| node_modules/ | ||
| node_modules | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Note-entry preview tests (gap-audit follow-up): the dashed caret cell now | ||
| * previews a typed note's LENGTH (sized to the snap step) and is a persisted, | ||
| * toggleable view pref. Covers the pure width helper (src/draw.js) and the | ||
| * localStorage-backed toggle (src/input.js). | ||
| * | ||
| * Run: node --test tests/entry_preview.test.mjs | ||
| */ | ||
| import assert from 'node:assert'; | ||
|
|
||
| // Minimal browser surface the modules touch at import / call time. | ||
| let _store = {}; | ||
| globalThis.localStorage = { | ||
| getItem: (k) => (k in _store ? _store[k] : null), | ||
| setItem: (k, v) => { _store[k] = String(v); }, | ||
| removeItem: (k) => { delete _store[k]; }, | ||
| }; | ||
| globalThis.document = globalThis.document || { | ||
| getElementById: () => null, querySelector: () => null, | ||
| addEventListener: () => {}, createElement: () => ({ style: {}, classList: { add() {}, remove() {} } }), | ||
| }; | ||
| globalThis.window = globalThis.window || globalThis; | ||
|
|
||
| const { _caretCellWidthPure } = await import('../src/draw.js'); | ||
| const { _editorEntryPreviewEnabled, editorToggleEntryPreview } = await import('../src/input.js'); | ||
|
|
||
| let pass = 0, fail = 0; | ||
| function t(name, fn) { | ||
| try { fn(); pass++; console.log(' ok ' + name); } | ||
| catch (e) { fail++; console.error(' FAIL ' + name + ': ' + e.message); } | ||
| } | ||
| async function ta(name, fn) { | ||
| try { await fn(); pass++; console.log(' ok ' + name); } | ||
| catch (e) { fail++; console.error(' FAIL ' + name + ': ' + e.message); } | ||
| } | ||
|
|
||
| // ── _caretCellWidthPure: the cell earns its note SHAPE ──────────────────────── | ||
| t('cell width is the note value (step × zoom) when that beats the minimum', () => { | ||
| // 0.5 s step at 200 px/s = 100 px, well over the 8 px minimum. | ||
| assert.strictEqual(_caretCellWidthPure(0.5, 200, 8), 100); | ||
| }); | ||
|
|
||
| t('floors to the minimum so the cell always shows at tiny steps / low zoom', () => { | ||
| // 1/64-note-ish step at low zoom → sub-pixel; must not vanish. | ||
| assert.strictEqual(_caretCellWidthPure(0.01, 100, 8), 8); // 1px < 8 | ||
| assert.strictEqual(_caretCellWidthPure(0, 200, 8), 8); // no grid → minimum | ||
| }); | ||
|
|
||
| t('a zero/negative zoom or garbage input degrades to the minimum, never NaN', () => { | ||
| assert.strictEqual(_caretCellWidthPure(0.5, 0, 8), 8); | ||
| assert.strictEqual(_caretCellWidthPure(0.5, -200, 8), 8); | ||
| assert.strictEqual(_caretCellWidthPure(NaN, 200, 8), 8); | ||
| assert.strictEqual(_caretCellWidthPure(0.5, 200, undefined), 100); // minW absent → 0 floor | ||
| }); | ||
|
|
||
| t('grows and shrinks monotonically with the snap step (longer note → wider cell)', () => { | ||
| const eighth = _caretCellWidthPure(0.25, 200, 8); | ||
| const quarter = _caretCellWidthPure(0.5, 200, 8); | ||
| const half = _caretCellWidthPure(1.0, 200, 8); | ||
| assert.ok(eighth < quarter && quarter < half, `${eighth} < ${quarter} < ${half}`); | ||
| }); | ||
|
|
||
| // ── toggle: persisted view pref, default ON ─────────────────────────────────── | ||
| // The getter caches on first read, so the localStorage-backed DEFAULT can only be | ||
| // exercised on a module instance that has not read it yet. A distinct import | ||
| // specifier gives us a fresh one (input.js has no import-time side effects). | ||
| async function freshEnabled(store) { | ||
| _store = store; | ||
| const m = await import(`../src/input.js?probe=${Math.random()}`); | ||
| return m._editorEntryPreviewEnabled(); | ||
| } | ||
|
|
||
| await ta('defaults ON when nothing is stored', async () => { | ||
| assert.strictEqual(await freshEnabled({}), true); | ||
| }); | ||
|
|
||
| await ta('reads a stored OFF back as off', async () => { | ||
| assert.strictEqual(await freshEnabled({ editorEntryPreview: '0' }), false); | ||
| }); | ||
|
|
||
| t('toggling flips the flag and persists it to localStorage', () => { | ||
| editorToggleEntryPreview(true); | ||
| assert.strictEqual(_editorEntryPreviewEnabled(), true); | ||
| const off = editorToggleEntryPreview(); | ||
| assert.strictEqual(off, false); | ||
| assert.strictEqual(_editorEntryPreviewEnabled(), false); | ||
| assert.strictEqual(_store.editorEntryPreview, '0'); | ||
| const on = editorToggleEntryPreview(); | ||
| assert.strictEqual(on, true); | ||
| assert.strictEqual(_store.editorEntryPreview, '1'); | ||
| }); | ||
|
|
||
| t('an explicit force sets the state directly (idempotent)', () => { | ||
| assert.strictEqual(editorToggleEntryPreview(false), false); | ||
| assert.strictEqual(editorToggleEntryPreview(false), false); | ||
| assert.strictEqual(_editorEntryPreviewEnabled(), false); | ||
| assert.strictEqual(editorToggleEntryPreview(true), true); | ||
| }); | ||
|
|
||
| console.log(`\n${pass} passed, ${fail} failed`); | ||
| process.exit(fail ? 1 : 0); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.