Skip to content

fix(mobile): lock canvas#40

Open
fufesou wants to merge 1 commit into
masterfrom
fix/mobile-lock-canvas
Open

fix(mobile): lock canvas#40
fufesou wants to merge 1 commit into
masterfrom
fix/mobile-lock-canvas

Conversation

@fufesou

@fufesou fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added a mobile "Lock canvas" toggle in the toolbar to prevent pan/zoom during two-finger scaling; state is cached per session for fast restore. Camera view disables this option.
  • Bug Fixes

    • Two-finger gesture handling now consults the cached lock state and safely handles async load/save failures to avoid unintended view changes.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c784c730-5091-4059-9e71-eef8814ad192

📥 Commits

Reviewing files that changed from the base of the PR and between da37057 and e9d2ad4.

📒 Files selected for processing (4)
  • flutter/lib/common/widgets/remote_input.dart
  • flutter/lib/common/widgets/toolbar.dart
  • flutter/lib/mobile/pages/view_camera_page.dart
  • flutter/lib/utils/canvas_lock.dart

Walkthrough

Adds a per-session in-memory canvas-lock cache, a mobile "Lock canvas" toolbar toggle (persisted to session options), and mobile two-finger gesture changes that consult the cache to skip scale/pan when canvas-lock is active.

Changes

Cohort / File(s) Summary
Canvas Lock Utilities
flutter/lib/utils/canvas_lock.dart
New module with kLockCanvasOptionKey, 'Y'/'N' sentinels, conversion helpers, per-session in-memory cache + revision API: read, set (with revision increment), sync, conditional init, and clear.
Gesture Detection Enhancement
flutter/lib/common/widgets/remote_input.dart
Mobile _RawTouchGestureDetectorRegionState now derives a sessionKey, loads cached canvas-lock in initState (with mounted checks/errors), uses cached lock state during onTwoFingerScaleUpdate to early-return and only set _scale when locked/unresolved, and clears cached entry on dispose.
Toolbar UI Control
flutter/lib/common/widgets/toolbar.dart
Adds mobile "Lock canvas" toggle (gated by supportsCanvasLock) whose initial state uses cache then session option; updates cache immediately on toggle, persists to session option with epoch guard, and reverts cache on persistence failure. Function signature updated: toolbarDisplayToggle(BuildContext context, String id, FFI ffi)toolbarDisplayToggle(BuildContext context, String id, FFI ffi, {bool supportsCanvasLock = true}).
Options Dialog Restriction
flutter/lib/mobile/pages/view_camera_page.dart
showOptions now calls toolbarDisplayToggle with supportsCanvasLock: false to disable the canvas-lock toggle on the camera page.

Sequence Diagram(s)

sequenceDiagram
    participant Toolbar as Toolbar (UI)
    participant Session as Flutter Session / Options
    participant Cache as CanvasLock Cache (utils)
    participant Gesture as Touch Gesture Detector
    participant Canvas as Remote Canvas

    Toolbar->>Session: read kLockCanvasOptionKey
    Session-->>Toolbar: option value ("Y"/"N"/null)
    Toolbar->>Cache: setCachedCanvasLockValue(sessionKey, enabled)
    Note right of Cache: store bool + increment revision

    Gesture->>Cache: setInitialCachedCanvasLockValue(sessionKey, enabled, expectedRev)
    Cache-->>Gesture: ok / no-op

    Gesture->>Gesture: two-finger scale update (mobile)
    Gesture->>Cache: cachedCanvasLockValue(sessionKey) / hasCachedCanvasLockValue
    alt locked == true or (loading && !hasCachedCanvasLockValue)
      Gesture->>Canvas: update internal _scale and return (skip scale/pan)
    else locked == false
      Gesture->>Canvas: perform scale/pan updates (ffi.canvasModel.updateScale, pan)
    end

    Gesture->>Cache: clearCachedCanvasLockValue(sessionKey) on dispose
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I stash a Y or N in hand,
Two-finger tides obey my command,
A toggle hums, the strokes hold fast,
I guard the page till spells are past,
Hop, lock, and sketch — a quiet land.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(mobile): lock canvas' clearly and concisely describes the main feature: implementing a canvas lock mechanism for mobile. It directly relates to all three modified files which collectively add canvas-lock caching, UI toggle, and gesture handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mobile-lock-canvas

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flutter/lib/common/widgets/remote_input.dart`:
- Around line 459-464: The current code fetches the canvas lock on every scale
gesture start (using _canvasLockScaleGestureToken, _canvasLockedForScaleGesture,
_canvasLockLoadingForScaleGesture and _loadCanvasLockForScaleGesture), causing
UI stalls; instead cache the lock state by reading sessionGetFlutterOption once
(e.g., in initState) into _canvasLockedForScaleGesture and set
_canvasLockLoadingForScaleGesture=false, and update that cached value when the
toolbar toggle changes or by subscribing to an option change stream/callback so
_loadCanvasLockForScaleGesture is only used for initial load or explicit
refresh; keep the token/race logic only if you still perform async refreshes
during gestures and ensure widget.isCamera checks remain unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ebc34e71-e39a-4eb1-8ecb-a02460139602

📥 Commits

Reviewing files that changed from the base of the PR and between ee8cc0c and 4fee209.

📒 Files selected for processing (3)
  • flutter/lib/common/widgets/remote_input.dart
  • flutter/lib/common/widgets/toolbar.dart
  • flutter/lib/utils/canvas_lock.dart

Comment thread flutter/lib/common/widgets/remote_input.dart Outdated
@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from 4fee209 to c277ba8 Compare April 28, 2026 05:57
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a mobile-only “Lock canvas” option to prevent two-finger scale gestures from panning/zooming the remote canvas, improving UI interaction on touch devices.

Changes:

  • Introduces a small utility for persisting/parsing the lock-canvas option and caching its value per session.
  • Adds a “Lock canvas” toggle to the mobile display toggles menu (default connections).
  • Updates mobile two-finger scale handling to no-op (for pan/zoom) when the lock is enabled.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
flutter/lib/utils/canvas_lock.dart Adds option key/constants and an in-memory per-session cache for the canvas-lock setting.
flutter/lib/common/widgets/toolbar.dart Adds a mobile “Lock canvas” toggle wired to session flutter options and the local cache.
flutter/lib/common/widgets/remote_input.dart Loads the option on init and blocks mobile two-finger pan/zoom when the cached lock is enabled.

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

Comment thread flutter/lib/common/widgets/remote_input.dart
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from c277ba8 to b9eb128 Compare April 28, 2026 06:37
@fufesou fufesou requested a review from Copilot April 28, 2026 06:37
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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


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

@fufesou fufesou requested a review from Copilot April 28, 2026 07:01
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flutter/lib/common/widgets/remote_input.dart`:
- Around line 121-149: Add a one-time init guard so gestures cannot act until
the persisted canvas-lock state is loaded: introduce a private bool (e.g.
_canvasLockLoaded = false) on the widget, set it to true at the end of
_loadCachedCanvasLock() after calling setInitialCachedCanvasLockValue(sessionId,
...), and trigger setState if necessary; then update any gesture checks that
currently call cachedCanvasLockValue(sessionId) (the pinch/pan/zoom handlers
that use that value) to also require _canvasLockLoaded before allowing gestures
(or treat gestures as locked until _canvasLockLoaded is true). Ensure the flag
lifecycle is handled consistently (initState starts load, dispose cleanup
unchanged).

In `@flutter/lib/common/widgets/toolbar.dart`:
- Around line 609-616: The handler currently writes the new lock state to the
local cache via setCachedCanvasLockValue(sessionId, value) before persisting
with bind.sessionSetFlutterOption(sessionId: sessionId, k: kLockCanvasOptionKey,
v: canvasLockValue(value)), which can cause cache/backend divergence on failure;
change the logic to record the previous cached value, then attempt the async
persist first (or if keeping current order, catch errors from
bind.sessionSetFlutterOption) and on any failure restore the previous value by
calling setCachedCanvasLockValue(sessionId, previousValue) and log or surface
the error; reference the onChanged closure, setCachedCanvasLockValue,
bind.sessionSetFlutterOption, canvasLockValue and sessionId to locate and update
the code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bce4afaa-8b02-40d9-a547-912ccb5eabdd

📥 Commits

Reviewing files that changed from the base of the PR and between 4fee209 and b9eb128.

📒 Files selected for processing (3)
  • flutter/lib/common/widgets/remote_input.dart
  • flutter/lib/common/widgets/toolbar.dart
  • flutter/lib/utils/canvas_lock.dart

Comment thread flutter/lib/common/widgets/remote_input.dart
Comment thread flutter/lib/common/widgets/toolbar.dart

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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


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

Comment thread flutter/lib/utils/canvas_lock.dart Outdated
Comment thread flutter/lib/utils/canvas_lock.dart Outdated
Comment thread flutter/lib/common/widgets/toolbar.dart Outdated
@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from b9eb128 to 4def7cf Compare April 28, 2026 07:15
@fufesou fufesou requested a review from Copilot April 28, 2026 07:15
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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


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

Comment thread flutter/lib/common/widgets/toolbar.dart
Comment thread flutter/lib/utils/canvas_lock.dart Outdated
Comment thread flutter/lib/common/widgets/remote_input.dart Outdated
@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


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

Comment thread flutter/lib/common/widgets/remote_input.dart
@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from e389dd7 to e728976 Compare April 28, 2026 09:36
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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


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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


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

Comment thread flutter/lib/common/widgets/toolbar.dart Outdated
@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from e728976 to 5f5ba35 Compare April 28, 2026 11:37
@fufesou fufesou requested a review from Copilot April 28, 2026 11:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flutter/lib/common/widgets/toolbar.dart`:
- Around line 615-632: The current onChanged handler can race: add a
monotonically incrementing operation id (e.g., int lockWriteOp = 0) in the same
scope as committedLockValue and increment it at the start of each onChanged
call, capture the id in the async closure, then when the async
bind.sessionSetFlutterOption completes (either success or catch) only update
committedLockValue or revert the cached value if the captured id equals the
latest seen id; for failures ignore stale completions whose captured id is less
than the latest id. Reference symbols: TToggleMenu's onChanged closure,
committedLockValue, setCachedCanvasLockValue(sessionKey, ...),
bind.sessionSetFlutterOption(sessionId, kLockCanvasOptionKey,
canvasLockValue(value)), sessionKey and sessionId.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f8ec6fba-8beb-4a94-b472-4db3e05a1367

📥 Commits

Reviewing files that changed from the base of the PR and between b9eb128 and 5f5ba35.

📒 Files selected for processing (3)
  • flutter/lib/common/widgets/remote_input.dart
  • flutter/lib/common/widgets/toolbar.dart
  • flutter/lib/utils/canvas_lock.dart

Comment thread flutter/lib/common/widgets/toolbar.dart

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


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

Comment thread flutter/lib/common/widgets/remote_input.dart Outdated
@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from 5f5ba35 to 36d2b94 Compare April 28, 2026 11:54
@fufesou

fufesou commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


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

Comment thread flutter/lib/common/widgets/toolbar.dart Outdated
@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from d5a93cc to da37057 Compare April 28, 2026 12:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flutter/lib/common/widgets/toolbar.dart`:
- Around line 609-612: You read the persisted lock value into initialLockValue
(via bind.sessionGetFlutterOption + isCanvasLockEnabled) but never update the
in-memory/cache copy remote_input.dart relies on, so the gesture enforcement can
stay stale; after successfully resolving lockValue into initialLockValue, write
the same persisted value back into the session option cache (the same cache API
remote_input.dart uses) using the sessionId and kLockCanvasOptionKey so the
cached state and persisted state are in sync (e.g., call the session cache
setter used elsewhere with sessionId, kLockCanvasOptionKey and lockValue
immediately before leaving the try block).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d76c7f4b-87c6-41db-8acb-42fe17c3d6e6

📥 Commits

Reviewing files that changed from the base of the PR and between 5f5ba35 and da37057.

📒 Files selected for processing (4)
  • flutter/lib/common/widgets/remote_input.dart
  • flutter/lib/common/widgets/toolbar.dart
  • flutter/lib/mobile/pages/view_camera_page.dart
  • flutter/lib/utils/canvas_lock.dart

Comment thread flutter/lib/common/widgets/toolbar.dart
Signed-off-by: fufesou <linlong1266@gmail.com>
@fufesou fufesou force-pushed the fix/mobile-lock-canvas branch from da37057 to e9d2ad4 Compare April 29, 2026 01:59
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.

2 participants