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!
I've addressed an issue where moving the cursor down (j command) in the editor would cause unexpected screen scrolling when navigating through lines that wrap. My changes refine the NextLine command's behavior to accurately account for wrapped lines, ensuring that the cursor moves smoothly to the next logical line without causing the display to jump. This significantly improves the user experience when editing text with word wrapping enabled.
Highlights
- Improved Cursor Movement for Wrapped Lines: The core change is within the
NextLinecommand, which is typically bound to thejkey for moving the cursor down. The previous implementation could cause the screen to jump unexpectedly when moving from a wrapped line to the next logical line. - Precise Calculation of Remaining Wrapped Lines: The updated logic now calculates how many display lines remain on the current logical line from the cursor's current position. This calculation considers the terminal's width and the width of individual characters.
- Smarter Screen and Window Scrolling: Based on the calculated remaining lines, the code intelligently adjusts both the cursor's screen position and the editor's window position in the buffer. This ensures that the screen scrolls only when necessary and by the correct amount, preventing jarring visual jumps.
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
The pull request adjusts the 'j' key movement to correctly handle scrolling with wrapped lines. The logic for calculating line wrapping information is duplicated, which can be refactored for better maintainability and slight performance improvement. Otherwise, the change correctly addresses the issue of unexpected scrolling.
| // 現在のカーソル位置が行の何行目に相当するかを計算 | ||
| let mut width = 0usize; | ||
| let mut cursor_row_in_line = 0usize; | ||
| for (i, c) in current_line.chars().enumerate() { | ||
| if i >= editor.cursor_position_in_buffer.col { | ||
| break; | ||
| } | ||
| width += get_char_width(c) as usize; | ||
| if width >= editor.terminal_size.width as usize { | ||
| width = 0; | ||
| cursor_row_in_line += 1; | ||
| } | ||
| } | ||
|
|
||
| // 行全体が何行に折り返されるかを計算 | ||
| width = 0; | ||
| let mut line_height = 1usize; | ||
| for c in current_line.chars() { | ||
| width += get_char_width(c) as usize; | ||
| if width >= editor.terminal_size.width as usize { | ||
| width = 0; | ||
| line_height += 1; | ||
| } | ||
| } |
There was a problem hiding this comment.
The logic to calculate cursor_row_in_line and line_height involves iterating over the characters of current_line twice. This can be optimized by combining these two loops into a single pass over the line's characters. This refactoring will improve code readability and reduce redundancy.
// Calculate both cursor_row_in_line and total line_height in one pass
let mut width = 0usize;
let mut cursor_row_in_line = 0usize;
let mut line_height = 1usize;
let cursor_col = editor.cursor_position_in_buffer.col;
for (i, c) in current_line.chars().enumerate() {
if i == cursor_col {
cursor_row_in_line = line_height - 1;
}
width += get_char_width(c) as usize;
if width >= editor.terminal_size.width as usize {
width = 0;
line_height += 1;
}
}
if cursor_col >= current_line.chars().count() {
cursor_row_in_line = line_height - 1;
}
Summary
jmovement so leaving a wrapped line doesn't scroll the window unexpectedlyTesting
cargo build --verbosecargo test --verbosepytest -n auto e2e --verbosehttps://chatgpt.com/codex/tasks/task_e_6896df2888f8832fa1d7cc80714f82e5