Skip to content

Commit 4883ed0

Browse files
authored
fix: Incorrect horizontal scrollbar displayed. (#2209)
The horizontal scroll bar length is set using the maximum line length across the input file. The original setup had the lengths of imported and included files added so changes are made to insure that only changes from the input file are taken. This required changes to the Pattern Language library so the library is updated to the latest version as well.
1 parent 78ad0d2 commit 4883ed0

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

lib/third_party/imgui/ColorTextEditor/include/TextEditor.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ class TextEditor
295295
void SetText(const std::string& aText);
296296
void JumpToLine(int line=-1);
297297
void JumpToCoords(const Coordinates &coords);
298+
void SetLongestLineLength(size_t line) {
299+
mLongestLineLength = line;
300+
}
298301
std::string GetText() const;
299302
bool isEmpty() const {
300303
auto text = GetText();
@@ -555,7 +558,6 @@ class TextEditor
555558
int GetCharacterColumn(int aLine, int aIndex) const;
556559
int GetLineCharacterCount(int aLine) const;
557560
int Utf8CharsToBytes(const Coordinates &aCoordinates) const;
558-
int GetLongestLineLength() const;
559561
unsigned long long GetLineByteCount(int aLine) const;
560562
int GetStringCharacterCount(std::string str) const;
561563
int GetLineMaxColumn(int aLine) const;
@@ -594,7 +596,7 @@ class TextEditor
594596
bool mTextChanged = false;
595597
bool mColorizerEnabled = true;
596598
float mLineNumberFieldWidth = 0.0F;
597-
float mLongest = 0.0F;
599+
size_t mLongestLineLength = 0;
598600
float mTextStart = 20.0F; // position (in pixels) where a code line starts relative to the left of the TextEditor.
599601
float mLeftMargin = 10.0;
600602
float mTopLine = 0.0F;

lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,6 @@ void TextEditor::HandleMouseInputs() {
847847
}
848848
}
849849

850-
int TextEditor::GetLongestLineLength() const {
851-
int result = 0;
852-
for (int i = 0; i < (int)mLines.size(); i++)
853-
result = std::max(result, GetLineCharacterCount(i));
854-
return result;
855-
}
856-
857850
inline void TextUnformattedColoredAt(const ImVec2 &pos, const ImU32 &color, const char *text) {
858851
ImGui::SetCursorScreenPos(pos);
859852
ImGui::PushStyleColor(ImGuiCol_Text,color);
@@ -913,7 +906,6 @@ void TextEditor::RenderText(const char *aTitle, const ImVec2 &lineNumbersStartPo
913906
float globalLineMax = mLines.size();
914907
auto lineMax = std::clamp(lineNo + mNumberOfLinesDisplayed, 0.0F, globalLineMax-1.0F);
915908
int totalDigitCount = std::floor(std::log10(globalLineMax)) + 1;
916-
mLongest = GetLongestLineLength() * mCharAdvance.x;
917909

918910
// Deduce mTextStart by evaluating mLines size (global lineMax) plus two spaces as text width
919911
char buf[16];
@@ -1184,9 +1176,9 @@ void TextEditor::RenderText(const char *aTitle, const ImVec2 &lineNumbersStartPo
11841176
ImGui::BeginChild(aTitle);
11851177

11861178
if (mShowLineNumbers)
1187-
ImGui::Dummy(ImVec2(mLongest, (globalLineMax - lineMax - 2.0F) * mCharAdvance.y + ImGui::GetCurrentWindow()->InnerClipRect.GetHeight()));
1179+
ImGui::Dummy(ImVec2(mLongestLineLength * mCharAdvance.x, (globalLineMax - lineMax - 2.0F) * mCharAdvance.y + ImGui::GetCurrentWindow()->InnerClipRect.GetHeight()));
11881180
else
1189-
ImGui::Dummy(ImVec2(mLongest, (globalLineMax - 1.0f - lineMax + GetPageSize() - 1.0f ) * mCharAdvance.y - 2 * ImGuiStyle().WindowPadding.y));
1181+
ImGui::Dummy(ImVec2(mLongestLineLength * mCharAdvance.x, (globalLineMax - 1.0f - lineMax + GetPageSize() - 1.0f ) * mCharAdvance.y - 2 * ImGuiStyle().WindowPadding.y));
11901182

11911183
if (mScrollToCursor)
11921184
EnsureCursorVisible();
@@ -1247,8 +1239,7 @@ void TextEditor::Render(const char *aTitle, const ImVec2 &aSize, bool aBorder) {
12471239

12481240
ImVec2 textEditorSize = aSize;
12491241
textEditorSize.x -= mLineNumberFieldWidth;
1250-
mLongest = GetLongestLineLength() * mCharAdvance.x;
1251-
bool scroll_x = mLongest > textEditorSize.x;
1242+
bool scroll_x = mLongestLineLength * mCharAdvance.x > textEditorSize.x;
12521243
bool scroll_y = mLines.size() > 1;
12531244
if (!aBorder && scroll_y)
12541245
textEditorSize.x -= scrollBarSize;

plugins/builtin/source/content/views/view_pattern_editor.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ namespace hex::plugin::builtin {
18461846

18471847
ContentRegistry::PatternLanguage::configureRuntime(*m_editorRuntime, nullptr);
18481848
const auto &ast = m_editorRuntime->parseString(code, pl::api::Source::DefaultSource);
1849+
m_textEditor.SetLongestLineLength(m_editorRuntime->getInternals().preprocessor.get()->getLongestLineLength());
18491850

18501851
auto &patternVariables = m_patternVariables.get(provider);
18511852
auto oldPatternVariables = std::move(patternVariables);

0 commit comments

Comments
 (0)