-
-
Notifications
You must be signed in to change notification settings - Fork 66
fix: sync first line when windows get focus #447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @HardyNLee, 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 focuses on improving the user experience within the text editor, particularly when the application window regains focus. The changes address two key issues: ensuring that the live preview accurately reflects the current cursor position rather than resetting to the first line, and preserving the editor's undo history during content refreshes.
Highlights
- Live Preview Synchronization Fix: I've updated the
handleChange
function inTextEditor.tsx
to use a stored cursor position (editorLineHolder.getSceneLine
) for live preview synchronization. This change addresses an issue where the live preview would incorrectly jump to the first line when the editor content was updated, especially after the application window regained focus. Previously, it relied onev.changes[0].range.startLineNumber
, which could be 1 if the entire document was replaced, leading to the incorrect synchronization. - Undo History Preservation: To prevent the loss of undo history when the editor content is refreshed (e.g., after the window regains focus), I've modified the content update mechanism in
TextEditor.tsx
. Instead of usingeditorRef.current?.getModel()?.setValue()
, which clears the undo stack, I've switched tomodel?.applyEdits()
. This treats the content update as a single edit operation, thereby preserving the user's undo history.
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 is currently in preview and 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 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.
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 addresses issues related to the editor's behavior when the window regains focus: preventing the view from jumping to the first line and preserving the undo history. The approach to use a stored line number for syncing is a good solution for the first issue. The switch from setValue
to applyEdits
correctly addresses the undo history problem.
I've found one critical issue that could lead to a runtime crash. Please see my detailed comments below.
const model = editorRef.current?.getModel(); | ||
model?.applyEdits([ | ||
{ | ||
range: model.getFullModelRange(), | ||
text: currentText.value, | ||
forceMoveMarkers: true | ||
} | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a potential TypeError
here that could crash the application. The range
property of the object inside the applyEdits
array is evaluated before applyEdits
is called. If model
is null
or undefined
(which can happen if editorRef.current
is not yet available), the expression model.getFullModelRange()
will throw an error. The optional chaining on model?.applyEdits
does not prevent this.
To fix this, you should wrap the applyEdits
call in a conditional block that checks if model
exists.
const model = editorRef.current?.getModel();
if (model) {
model.applyEdits([
{
range: model.getFullModelRange(),
text: currentText.value,
forceMoveMarkers: true
}
]);
}
介绍
fix #437
主要更改
修复窗口重新获得焦点时总是预览第一行
TextEditor
的handleChange
不再使用改变的行数作为同步行数, 而是使用储存的行数进行同步;此举是由于,
updateEditData
会完全赋予新文字, 这使得其触发的handleChange => ev.changes[0].range.startLineNumber
永远是1, 即从头到尾;通常来说,
onDidChangeCursorPosition
会及时记录光标位置, 而光标位置目前绝大多数清空都是与ev.changes[0].range.startLineNumber
一致, 故此更改应该是可以接受的窗口重新获得焦点时保留撤销历史
model.setValue
会完全清空撤销历史, 如果用户出于某些原因使浏览器失焦后, 重新获得焦点, 会失去所有撤销历史, 因此改成ApplyEdit
, 使更新的文本作为一步操作;ApplyEdit
会刷新语法高亮, 因而短时间内会没有高亮, 应该不影响使用