1
0
mirror of synced 2025-01-10 21:41:53 +01:00

fix: Text Editor find option jumping to the wrong location (#2060)

After successfully finding matches and setting the cursor to them, the
screen would jump to the original window location upon closing the
window.

The error was caused by the wrong assumption that the scroll location
should be restored when window is closed. Instead, the right amount of
scrolling needs to be calculated to account for the window no longer
covering part of the text editor. Unused variable was discarded.

Another unrelated error is that the history of search names cannot be
accessed which will be addressed at a later PR.
This commit is contained in:
paxcut 2025-01-09 10:39:00 -07:00 committed by GitHub
parent 98f32ebcad
commit f10af882a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 6 deletions

View File

@ -629,7 +629,6 @@ private:
uint64_t mStartTime = 0;
std::vector<std::string> mDefines;
TextEditor *mSourceCodeEditor = nullptr;
float mSavedScrollY = 0;
float mShiftedScrollY = 0;
float mScrollY = 0;
float mScrollYIncrement = 0.0F;

View File

@ -1179,8 +1179,6 @@ void TextEditor::RenderText(const char *aTitle, const ImVec2 &lineNumbersStartPo
if (mTopMarginChanged) {
mTopMarginChanged = false;
if (mTopMargin == 0)
mSavedScrollY = ImGui::GetScrollY();
auto window = ImGui::GetCurrentWindow();
auto maxScroll = window->ScrollMax.y;
if (maxScroll > 0) {
@ -1196,10 +1194,8 @@ void TextEditor::RenderText(const char *aTitle, const ImVec2 &lineNumbersStartPo
if (mNewTopMargin > mTopMargin)
mShiftedScrollY = oldScrollY + pixelCount;
else if (mNewTopMargin > 0)
mShiftedScrollY = oldScrollY - pixelCount;
else
mShiftedScrollY = mSavedScrollY;
mShiftedScrollY = oldScrollY - pixelCount;
ImGui::SetScrollY(mShiftedScrollY);
mTopMargin = mNewTopMargin;
}