Fix bottom-line scrolling and add regression test#107
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @hgwr, 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 bug where the editor's view did not scroll correctly when the cursor moved past the last visible line. I've implemented a fix to ensure that the editor scrolls as expected, making the next line visible, and I've also added a new end-to-end test to prevent this regression in the future.
Highlights
- Improved Cursor Scrolling Logic: I've adjusted the internal logic that determines when the editor should scroll its view. Previously, the editor would only scroll when the cursor was beyond the last visible row, leading to the last line being obscured. The change ensures that scrolling is triggered when the cursor reaches the second-to-last visible row, allowing the final row to become visible as intended. This affects character insertion, line appending, and cursor movement commands.
- New Regression Test for j Motion: I've added a new end-to-end test, test_motion_j_scrolls_at_bottom, to specifically verify that the j (move down) command correctly triggers screen scrolling when the cursor is at the bottom of the visible window. This test simulates a small terminal window and asserts that the content scrolls up as expected.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 or fill out our survey to provide feedback.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request fixes an issue with scrolling when the cursor moves to the bottom line of the screen and adds a regression test for it. The logical changes in the Rust code correctly address an off-by-one error in boundary checks. The new e2e test effectively validates the fix. My review includes suggestions to refactor duplicated code in both the new test and the Rust command implementations to improve maintainability.
| def test_motion_j_scrolls_at_bottom(): | ||
| file_content = "line1\nline2\nline3\nline4\nline5\nline6\n" | ||
| fd, path = tempfile.mkstemp() | ||
| try: | ||
| with os.fdopen(fd, "w") as f: | ||
| f.write(file_content) | ||
|
|
||
| env = os.environ.copy() | ||
| env.setdefault("TERM", "xterm") | ||
|
|
||
| child = pexpect.spawn(EVI_BIN, [path], env=env, encoding="utf-8") | ||
| child.delaybeforesend = float(os.getenv("EVI_DELAY_BEFORE_SEND", "0.1")) | ||
| child.setwinsize(6, 80) | ||
|
|
||
| # Ensure the editor has finished drawing | ||
| get_screen_and_cursor(child) | ||
|
|
||
| # Move cursor to the bottom line and attempt to move down once more | ||
| child.send("jjjj") | ||
| get_screen_and_cursor(child) | ||
| child.send("j") | ||
| screen, _ = get_screen_and_cursor(child) | ||
| clean_screen = screen.split("\x1b[2J")[-1] | ||
|
|
||
| assert "line6" in clean_screen | ||
| assert "line1" not in clean_screen | ||
|
|
||
| child.send(":q!\r") | ||
| child.expect(pexpect.EOF) | ||
| finally: | ||
| os.unlink(path) |
There was a problem hiding this comment.
This test is a great addition for catching regressions in scrolling behavior. However, there's a lot of boilerplate code for setting up the test environment that is duplicated from the run_motion_test helper function. To improve maintainability and reduce code duplication, consider refactoring the setup and teardown logic into a pytest fixture or a context manager. This would make both this test and run_motion_test cleaner and easier to read.
Summary
jscrolling at the bottom of the screenTesting
cargo build --verbosecargo test --verbosepytest -n auto e2e --verbosehttps://chatgpt.com/codex/tasks/task_e_6896daee4ecc832f981199889b2c0258