Skip to content

Generalize the math in vertical panel scrolling - #755

Merged
zonble merged 1 commit into
openvanilla:masterfrom
lukhnos:candidate-ui-fix
Dec 5, 2025
Merged

Generalize the math in vertical panel scrolling#755
zonble merged 1 commit into
openvanilla:masterfrom
lukhnos:candidate-ui-fix

Conversation

@lukhnos

@lukhnos lukhnos commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

The changes introduced in #453 were designed for McBopomofo's use case where the candidate index is only moved by one or by a page. The issue found at openvanilla/openvanilla#119 showed that the math needed to be generalized.

How tested: manually running through the scenarios mentioned in #453 to make sure that the UI invariants are not changed.

Copilot AI review requested due to automatic review settings December 4, 2025 18:43
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @lukhnos, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a limitation in the vertical scrolling mechanism of the candidate UI, as identified in issue #119. The changes generalize the underlying mathematical logic for scrolling, ensuring that the UI behaves correctly and consistently across various types of candidate index movements, not just single-step or single-page navigations. This enhancement improves the robustness and user experience of candidate selection.

Highlights

  • Scrolling Logic Generalization: The vertical panel scrolling logic has been refactored to generalize the mathematical calculations, moving beyond the previous implementation's specific handling of single-row or single-page movements.
  • Improved Page Navigation: The updated code now explicitly differentiates between single-row movements and larger page-based movements, ensuring more accurate and predictable scrolling behavior when navigating through candidate lists.
  • Simplified Scroll Target Calculation: The calculation for the scroll target has been simplified, now relying on the pageIndex and labelCount to determine where to scroll for page-based navigation, rather than dynamically calculating visible rows.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

lukhnos added a commit to lukhnos/openvanilla that referenced this pull request Dec 4, 2025
This fixes openvanilla#119

This is synced from openvanilla/McBopomofo#755
and a detailed analysis of the changes can be found there.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the vertical panel scrolling logic to be more generalized. The new implementation is clearer and appears to correctly handle different scrolling scenarios, such as single-line moves and page jumps. However, I've found a critical issue where a division by zero can occur if keyLabels is empty, leading to a crash. I've provided a code suggestion to fix this.

Comment thread Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the vertical candidate panel scrolling logic to generalize the math beyond the original single-step and page-at-a-time movements. The change addresses an issue found in OpenVanilla where candidate index jumps by arbitrary amounts need to be handled correctly.

Key changes:

  • Replaced conditional logic based on movement distance with page-index-based calculations
  • Simplified scrolling by determining which page contains the target index and scrolling to show that page appropriately

Comment thread Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift Outdated
Comment thread Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift Outdated
The changes introduced in openvanilla#453
were designed for McBopomofo's use case where the candidate index is
only moved by one or by a page. The issue found at
openvanilla/openvanilla#119 showed that the
math needed to be generalized.

How tested: manually running through the scenarios mentioned in
openvanilla#453 to make sure that the
UI invariants are not changed.
lukhnos added a commit to lukhnos/openvanilla that referenced this pull request Dec 4, 2025
This fixes openvanilla#119

This is synced from openvanilla/McBopomofo#755
and a detailed analysis of the changes can be found there.
@lukhnos
lukhnos requested a review from zonble December 4, 2025 19:14
@zonble
zonble merged commit 60e367d into openvanilla:master Dec 5, 2025
10 checks passed
lukhnos added a commit to lukhnos/McBopomofo that referenced this pull request Jan 5, 2026
In openvanilla#755 we generalized the
math in vertical panel scrolling and synced the code with OpenVanilla,
but due to how McBopomofo sets the panel candidate differently, the PR
caused a regression in that the vertical panel failed to scroll back to
page 0 if a previous candidate selection session moved to a non-zero
page.

Postmortem. The generalized math has a code path that does nothing.
However, we didn't account for the fact that McBopomofo repeatedly
resets the candidate panel's delegate. Resetting delegate reloads the
data, but when the delegate is set to nil, there are no actual rows, and
the table view's selected row is reset to 0 while the scroll view is
still set to where the non-zero page started (this is consistent with
Cocoa's behavior). But because the selected row is now reset, when the
new candidate data is loaded, the candidate panel thinks that no further
action is needed (because it's already set to 0), and so no scrolling is
needed. In the previous code, -scrollRowToVisible was always called in
this case. We therefore need to make sure that -scrollRowToVisible is
always called when the selected candidate index is set to 0.

OpenVanilla is not affected due to how it interacts with the panel's
delegate logic, but syncing this change is still desirable.
@lukhnos
lukhnos deleted the candidate-ui-fix branch January 11, 2026 00:52
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.

3 participants