Skip to content

ADFA-3154 Ctrl-mouseWheel for zoom in/out in Sora editor#1036

Merged
hal-eisen-adfa merged 5 commits into
stagefrom
ADFA-3154-Support-control-mouse-wheel-scroll-to-zoom-in-and-out
Mar 3, 2026
Merged

ADFA-3154 Ctrl-mouseWheel for zoom in/out in Sora editor#1036
hal-eisen-adfa merged 5 commits into
stagefrom
ADFA-3154-Support-control-mouse-wheel-scroll-to-zoom-in-and-out

Conversation

@hal-eisen-adfa
Copy link
Copy Markdown
Collaborator

Zoom helper and font-size logic
changeFontSizeBy(delta: Float) (private): Reads EditorPreferences.fontSize, computes a new size with computeNewEditorFontSize(current, delta) (same 6–32sp bounds as the existing slider), updates the preference when the value changes, and calls binding.editor.setTextSize(newSize).
computeNewEditorFontSize(current, delta) (internal, for tests): If current is outside 6–32, it’s treated as 14; then current + delta is clamped to 6–32 and returned.
onFontSizePrefChanged(): Unchanged behavior; when the pref is out of range it now also sets EditorPreferences.fontSize = 14f before applying, so the stored value stays in range.

Ctrl + mouse-wheel handling
In init, binding.editor.setOnGenericMotionListener was added. It:
Handles only MotionEvent.ACTION_SCROLL from a pointer-class device (SOURCE_CLASS_POINTER).
Requires Ctrl (event.isCtrlPressed()); otherwise returns false so the editor still scrolls.
Uses event.getAxisValue(MotionEvent.AXIS_VSCROLL): vScroll > 0 → zoom in (changeFontSizeBy(1f)), vScroll < 0 → zoom out (changeFontSizeBy(-1f)).
Returns true only when it handles Ctrl+scroll, so normal wheel scrolling is unchanged.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5c18a3 and d5f8960.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt

📝 Walkthrough
  • Feature: Add Ctrl+mouse-wheel zoom to the Sora code editor — hold Ctrl and scroll vertical wheel to increase/decrease editor font size (±1 sp per scroll step).

  • Implementation:

    • Introduced font-size constants: MIN_FONT_SIZE = 6f, DEFAULT_FONT_SIZE = 14f, MAX_FONT_SIZE = 32f.
    • Added private changeFontSizeBy(delta: Float) in CodeEditorView: reads EditorPreferences.fontSize, computes new size via computeNewEditorFontSize(current, delta), persists when changed, and applies with binding.editor.setTextSize(newSize).
    • Added top-level internal function computeNewEditorFontSize(current: Float, delta: Float): Float: treats out-of-range current as DEFAULT_FONT_SIZE, applies delta, clamps result to MIN–MAX and returns (intended for unit testing).
    • Updated onFontSizePrefChanged behavior to enforce stored preference stays in-range by resetting EditorPreferences.fontSize to DEFAULT_FONT_SIZE when out-of-range before applying.
    • Registered an OnGenericMotionListener on the editor that:
      • only handles MotionEvent.ACTION_SCROLL from pointer-class devices,
      • requires Ctrl to be pressed (checks metaState),
      • reads MotionEvent.AXIS_VSCROLL (vScroll > 0 → +1 sp; vScroll < 0 → -1 sp),
      • returns true only when it handles a Ctrl+scroll event; otherwise lets the editor handle scrolling.
  • API/visibility changes:

    • Added private method changeFontSizeBy(delta: Float) in CodeEditorView.
    • Added internal top-level function computeNewEditorFontSize(current: Float, delta: Float): Float for testing.
  • Risks & best-practice concerns:

    • No throttling/debouncing: rapid Ctrl+wheel events update preferences and UI immediately — may cause excessive preference writes or UI churn on fast/many events.
    • No user feedback or undo: font-size changes are applied silently with no confirmation, toast, or easy revert, which can confuse users.
    • Preference concurrency: read-modify-write updates preferences without synchronization — potential race if preferences are modified concurrently elsewhere.
    • Meta-state check style: listener checks metaState bit (KeyEvent.META_CTRL_ON) rather than using event.isCtrlPressed(); inconsistent API usage may reduce readability/consistency.
    • Granularity: font-size changes are fixed to 1 sp per wheel step; no configuration or acceleration for larger deltas.

Walkthrough

Adds Ctrl+mouse-wheel zoom to the code editor: handles generic motion events, computes a clamped new font size, applies it to the editor, and persists the updated preference with MIN/DEFAULT/MAX bounds.

Changes

Cohort / File(s) Summary
Ctrl+Scroll Zoom Feature
app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt
Adds MIN/DEFAULT/MAX font size constants, an OnGenericMotionListener for Ctrl + vertical wheel events, private fun changeFontSizeBy(delta: Float), internal fun computeNewEditorFontSize(current: Float, delta: Float): Float, and stronger clamping + preference persistence logic.
sequenceDiagram
    participant User
    participant CodeEditorView
    participant Editor
    participant Prefs

    User->>CodeEditorView: Ctrl + mouse wheel
    CodeEditorView->>CodeEditorView: OnGenericMotionListener detects scroll + Ctrl
    CodeEditorView->>CodeEditorView: computeNewEditorFontSize(current, delta)
    CodeEditorView->>Editor: apply new font size
    CodeEditorView->>Prefs: persist updated font size
    Editor-->>User: display updated text size
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I twitch my whiskers, scroll a beat,
Ctrl and wheel make font hops sweet,
Bigger, smaller, snug and bright,
Code in rhythm, left-to-right —
A rabbit cheers for zoom tonight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding Ctrl+mouse wheel zoom functionality to the Sora editor, which matches the primary feature implemented in the changeset.
Description check ✅ Passed The description is directly related to the changeset, detailing the font-size management logic and Ctrl+mouse-wheel handling that were implemented in CodeEditorView.kt.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ADFA-3154-Support-control-mouse-wheel-scroll-to-zoom-in-and-out

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

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

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (2)
app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt (2)

645-655: LGTM!

The function correctly normalizes out-of-range values to the default (14), applies the delta, and clamps to the valid range. Using coerceIn is idiomatic Kotlin.

Optional: Consider extracting the magic numbers (6, 14, 32) into named constants (e.g., MIN_FONT_SIZE, DEFAULT_FONT_SIZE, MAX_FONT_SIZE) since they're used in multiple places (onFontSizePrefChanged and here).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt` around lines
645 - 655, Extract the hard-coded font-size magic numbers into named constants
and use them in computeNewEditorFontSize and onFontSizePrefChanged: define
constants like MIN_FONT_SIZE, DEFAULT_FONT_SIZE, MAX_FONT_SIZE (Float) and
replace 6f, 14f, 32f in computeNewEditorFontSize as well as any occurrences in
onFontSizePrefChanged so all logic (normalization, delta application, and
coerceIn) uses the centralized constants.

208-217: Consider simplifying the vScroll handling.

Since line 209 already returns early when vScroll == 0f, the else if (vScroll < 0f) on line 215 can be simplified to just else.

♻️ Suggested simplification
 			val vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
 			if (vScroll == 0f) {
 				return@setOnGenericMotionListener false
 			}

 			if (vScroll > 0f) {
 				changeFontSizeBy(1f)
-			} else if (vScroll < 0f) {
+			} else {
 				changeFontSizeBy(-1f)
 			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt` around lines
208 - 217, The vScroll handling in the setOnGenericMotionListener block is
verbose: after returning early when vScroll == 0f, the final branch uses "else
if (vScroll < 0f)"; change that to a plain "else" to simplify logic. Locate the
event handler where vScroll is read and where changeFontSizeBy(1f) and
changeFontSizeBy(-1f) are called and replace the "else if (vScroll < 0f)" branch
with "else" so negative scrolls still call changeFontSizeBy(-1f) while keeping
the early return for zero.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt`:
- Around line 204-206: Replace the invalid use of event.isCtrlPressed inside the
setOnGenericMotionListener callback by checking the motion event's meta state:
import android.view.KeyEvent and change the condition to test (event.metaState
and KeyEvent.META_CTRL_ON) != 0 (or use KeyEvent.hasModifiers) so the Ctrl key
is detected correctly; update the file to add the KeyEvent import and adjust the
condition in the setOnGenericMotionListener block where event is a MotionEvent.

---

Nitpick comments:
In `@app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt`:
- Around line 645-655: Extract the hard-coded font-size magic numbers into named
constants and use them in computeNewEditorFontSize and onFontSizePrefChanged:
define constants like MIN_FONT_SIZE, DEFAULT_FONT_SIZE, MAX_FONT_SIZE (Float)
and replace 6f, 14f, 32f in computeNewEditorFontSize as well as any occurrences
in onFontSizePrefChanged so all logic (normalization, delta application, and
coerceIn) uses the centralized constants.
- Around line 208-217: The vScroll handling in the setOnGenericMotionListener
block is verbose: after returning early when vScroll == 0f, the final branch
uses "else if (vScroll < 0f)"; change that to a plain "else" to simplify logic.
Locate the event handler where vScroll is read and where changeFontSizeBy(1f)
and changeFontSizeBy(-1f) are called and replace the "else if (vScroll < 0f)"
branch with "else" so negative scrolls still call changeFontSizeBy(-1f) while
keeping the early return for zero.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34f24db and 182b97d.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt

Comment thread app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt Outdated
@hal-eisen-adfa hal-eisen-adfa requested a review from a team March 3, 2026 23:00
Comment thread app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt
@hal-eisen-adfa hal-eisen-adfa merged commit 43c968d into stage Mar 3, 2026
2 checks passed
@hal-eisen-adfa hal-eisen-adfa deleted the ADFA-3154-Support-control-mouse-wheel-scroll-to-zoom-in-and-out branch March 3, 2026 23:37
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