Skip to content

Conversation

@tomusdrw
Copy link
Member

@tomusdrw tomusdrw commented Dec 2, 2025

better memory input for default host call dialog

@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for pvm-debugger ready!

Name Link
🔨 Latest commit ca9e684
🔍 Latest deploy log https://app.netlify.com/projects/pvm-debugger/deploys/692f55b50008710008737a0e
😎 Deploy Preview https://deploy-preview-459--pvm-debugger.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

📝 Walkthrough

Walkthrough

The MemoryEditor component undergoes a comprehensive refactor replacing simple editing state with a focus-driven, multi-ref system. The change introduces nibble-based hex editing, per-byte hex and ASCII inputs, keyboard navigation, paste handling, and input validation for precise byte-level editing workflows.

Changes

Cohort / File(s) Change Summary
Hex/ASCII Memory Editor Refactor
src/components/HostCallDialog/MemoryEditor.tsx
Replaces single-byte editing state with focused multi-ref system; adds nibble-based hex editor with digit parsing, keyboard handling (Backspace, Delete, Arrow keys), and navigation. Introduces per-byte hex and ASCII inputs with separate ref management. Implements paste handling for hex strings and ASCII characters with validation. Refactors rendering to use input-based cells with dynamic styling for disabled/focused states. Adjusts effect dependencies for memory loading.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Hex nibble parsing and boundary validation: Verify correct handling of odd-length hex input, proper caret placement, and nibble-level navigation logic
  • Ref management and focus flow: Ensure focus transitions between hex and ASCII inputs work correctly; confirm refs are properly cleaned up and targeted
  • Paste handling logic: Review hex string parsing, ASCII character validation, and data integrity when pasting into hex versus ASCII cells
  • State update timing: Verify onMemoryChange is called only on meaningful edits; confirm dependency array changes don't cause unexpected re-renders or missed updates
  • Keyboard event handling: Check completeness of keyboard shortcuts (Backspace, Delete, Arrow keys) and ensure they don't conflict with browser defaults

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Better memory input' directly reflects the main change: refactoring memory editing in MemoryEditor component with improved input handling, validation, and user experience.
Description check ✅ Passed The description 'better memory input for default host call dialog' is related to the changeset, describing the improved memory input functionality for the host call dialog component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch td-better-mem

Comment @coderabbitai help to get the list of available commands and usage tips.

@tomusdrw tomusdrw marked this pull request as ready for review December 2, 2025 21:28
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/components/HostCallDialog/MemoryEditor.tsx (3)

49-76: Consider adding an abort mechanism for rapid address/length changes.

If the user rapidly changes address or length, multiple async readMemory calls can race. The last to complete (not necessarily the last triggered) will set the data, potentially showing stale results.

This is likely acceptable for a debugger UI, but adding an abort controller or a request ID check would make it more robust.

  useEffect(() => {
+   let cancelled = false;
    const loadMemory = async () => {
      if (address === null || length === null || length <= 0) {
        setData(null);
        return;
      }

      if (length > MAX_LENGTH) {
        setError(`Length cannot exceed ${MAX_LENGTH} bytes`);
        return;
      }

      setIsLoading(true);
      setError(null);
      try {
        const memoryData = await readMemory(address, length);
+       if (cancelled) return;
        setData(memoryData);
      } catch (e) {
+       if (cancelled) return;
        setError(e instanceof Error ? e.message : "Failed to read memory");
        setData(null);
      } finally {
+       if (!cancelled) setIsLoading(false);
-       setIsLoading(false);
      }
    };

    loadMemory();
+   return () => { cancelled = true; };
  }, [address, length, readMemory]);

416-439: Add aria-label for accessibility.

The hex and ASCII inputs lack accessible labels. Screen reader users won't know which byte address they're editing.

                            <input
                              key={i}
                              ref={(el) => {
                                inputRefs.current[byteIndex] = el;
                              }}
+                             aria-label={`Hex byte at offset ${(address! + byteIndex).toString(16).toUpperCase()}`}
                              className={`w-4 h-4 text-center font-mono text-xs uppercase rounded border ${

460-481: Add aria-label for ASCII inputs as well.

Same accessibility concern applies to the ASCII input cells.

                            <input
                              key={i}
                              ref={(el) => {
                                asciiRefs.current[byteIndex] = el;
                              }}
+                             aria-label={`ASCII byte at offset ${(address! + byteIndex).toString(16).toUpperCase()}`}
                              className={`w-4 h-4 text-center font-mono text-xs rounded border p-0 ${
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 192b87e and ca9e684.

📒 Files selected for processing (1)
  • src/components/HostCallDialog/MemoryEditor.tsx (6 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/components/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

src/components/**/*.{ts,tsx}: Keep reusable UI components in src/components/
Write TypeScript-first functional components

Files:

  • src/components/HostCallDialog/MemoryEditor.tsx
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.{ts,tsx}: Use two-space indentation in TypeScript files
Use descriptive filenames in kebab-case (e.g., memory-range-panel.tsx)
Validate external inputs with Zod when parsing user data

Files:

  • src/components/HostCallDialog/MemoryEditor.tsx
src/**/*.{css,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Favor Tailwind utilities from globals.css before adding new CSS files

Files:

  • src/components/HostCallDialog/MemoryEditor.tsx
🔇 Additional comments (14)
src/components/HostCallDialog/MemoryEditor.tsx (14)

1-11: LGTM!

Imports, constants, and interface definition are clean and appropriate for the component's functionality.


13-35: LGTM!

Helper functions for parsing and formatting are correctly implemented.


45-47: LGTM!

State and refs are appropriately initialized for the focus-driven editing workflow.


78-95: LGTM!

Address and length update callbacks handle parsing and clamping correctly.


97-128: LGTM!

Focus management callbacks properly clamp indices and use requestAnimationFrame for reliable DOM manipulation.


130-139: LGTM!

Immutable update pattern with proper byte masking.


141-156: LGTM!

Nibble-level hex editing logic is correctly implemented with proper bit masking.


158-182: LGTM!

Nibble navigation helpers correctly handle boundary conditions.


184-229: LGTM!

Comprehensive keyboard handling for hex editing with proper nibble-level navigation.


231-260: LGTM!

Input validation and hex character filtering work correctly with proper nibble advancement.


262-287: LGTM!

Paste handling correctly processes hex strings with proper prefix stripping and odd-length padding.


289-323: LGTM!

ASCII input and paste handlers correctly process character data with byte masking.


325-350: LGTM!

ASCII keyboard navigation is consistent with hex editing behavior.


443-451: LGTM!

Padding for incomplete rows maintains visual alignment.

@tomusdrw tomusdrw merged commit 139f6d4 into main Dec 2, 2025
7 checks passed
@tomusdrw tomusdrw deleted the td-better-mem branch December 2, 2025 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant