ADFA-3154 Ctrl-mouseWheel for zoom in/out in Sora editor#1036
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
WalkthroughAdds 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
coerceInis 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 (onFontSizePrefChangedand 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, theelse if (vScroll < 0f)on line 215 can be simplified to justelse.♻️ 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.
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.