Skip to content

Fix macOS file open association and scroll sync#3

Merged
Amoner merged 2 commits intomainfrom
fix/macos-file-open-and-scroll-sync
Mar 16, 2026
Merged

Fix macOS file open association and scroll sync#3
Amoner merged 2 commits intomainfrom
fix/macos-file-open-and-scroll-sync

Conversation

@Amoner
Copy link
Copy Markdown
Owner

@Amoner Amoner commented Mar 16, 2026

Summary

  • Issue OSX: double clicking on a file opens Inkwell but not the file #1: Fix double-click / "Open With" not opening files on macOS. The app only checked argv for file paths, but macOS uses Apple Events (kAEOpenDocuments) for file associations. Switched from builder.run() to builder.build().run() with a RunEvent::Opened handler that emits open-file-requested to the frontend. The existing get_open_file_arg remains as a fallback for Linux/Windows.
  • Issue OSX: Weird scrolling behavior #2: Fix scroll feedback loop causing editor to drift back up when scrolling with mouse wheel. Replaced single-frame requestAnimationFrame sync guard with a 200ms debounced setTimeout, preventing the bounce-back caused by macOS's asynchronous scroll event delivery.

Closes #1, Closes #2

Test plan

  • On macOS, double-click a .md file in Finder — Inkwell should open and display the file
  • On macOS, right-click a .md file → "Open With" → Inkwell — file should open
  • Drag-and-drop still works as before
  • In split view with a long document, scroll down with mouse wheel — editor should not drift back up
  • Switching between editor/split/preview modes preserves scroll position
  • On Linux/Windows, opening via CLI argument still works (argv fallback)

🤖 Generated with Claude Code

Handle macOS Apple Events for file associations (#1) by switching from
argv-based detection to Tauri's RunEvent::Opened handler, emitting an
event to the frontend. Fix scroll sync drift (#2) by replacing the
single-frame requestAnimationFrame guard with a 200ms debounced timeout
to prevent feedback loops on macOS.

Closes #1, Closes #2

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 16, 2026 02:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses two macOS-specific UX issues in the Tauri-based Inkwell app: handling file-association opens on macOS, and preventing scroll-sync feedback loops between editor and preview.

Changes:

  • Add a Tauri RunEvent::Opened handler to forward macOS “open document” events to the frontend.
  • Register a frontend event listener to load files requested by the backend.
  • Replace requestAnimationFrame-based scroll-sync reset with a debounced timeout to prevent scroll bounce/drift.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/preview/scroll-sync.js Debounces scroll-sync reset to avoid feedback loops with async scroll events.
src/main.js Listens for a new backend-emitted event and loads the requested file path.
src-tauri/src/lib.rs Switches to build().run() and emits an event on RunEvent::Opened for macOS file associations.
src-tauri/Cargo.lock Reflects version bump to 0.2.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +52 to +54
if let Some(path_str) = path.to_str() {
let _ = app_handle.emit("open-file-requested", path_str.to_string());
}
Comment on lines +7 to +9
function deferSyncReset() {
clearTimeout(syncResetTimer);
syncResetTimer = setTimeout(() => { syncSource = null; }, 200);
src/main.js Outdated
Comment on lines +67 to +71

// Handle macOS file-open events (double-click / "Open With" file associations)
await listen("open-file-requested", async (event) => {
await loadFile(event.payload);
});
Issue #1: RunEvent::Opened fires before the webview is ready on macOS,
so app_handle.emit() silently drops events on cold launch. Fix by
buffering opened paths in managed AppState (PendingOpenFiles) and
exposing get_pending_open_file command for the frontend to poll at
startup. The event listener is kept for runtime opens when the app is
already running.

Issue #2: The 200ms deferSyncReset was applied to applyScrollRatio,
blocking user scroll for 200ms after every view-mode switch. Restore
requestAnimationFrame for applyScrollRatio (one-shot restore only needs
one-frame suppression) while keeping the 200ms debounce for the
bidirectional sync handlers where macOS async scroll delivery requires
a longer guard window.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Amoner Amoner merged commit 2c42d33 into main Mar 16, 2026
2 of 4 checks passed
@Amoner Amoner deleted the fix/macos-file-open-and-scroll-sync branch March 16, 2026 03:11
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.

OSX: Weird scrolling behavior OSX: double clicking on a file opens Inkwell but not the file

2 participants