From a46da4ee164ea5fbbee812a7cde548c00161e5f2 Mon Sep 17 00:00:00 2001 From: Sen66 Date: Thu, 5 Mar 2026 12:46:55 +0100 Subject: [PATCH] fix: horizontal scrollbar calculations for C/C++ view - added msvc define NOMINMAX so we can use std::max --- msvc/Reclass.vcxproj | 2 ++ src/main.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/msvc/Reclass.vcxproj b/msvc/Reclass.vcxproj index 9edf950..3c78416 100644 --- a/msvc/Reclass.vcxproj +++ b/msvc/Reclass.vcxproj @@ -66,6 +66,7 @@ ..\third_party\fadec\;..\third_party\raw_pdb\src\;..\third_party\qscintilla\src\;..\src\ + NOMINMAX;%(PreprocessorDefinitions) dwmapi.lib;dbghelp.lib;%(AdditionalDependencies) @@ -80,6 +81,7 @@ ..\third_party\fadec\;..\third_party\raw_pdb\src\;..\third_party\qscintilla\src\;..\src\ + NOMINMAX;%(PreprocessorDefinitions) $(QtToolsPath)/windeployqt $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName).exe diff --git a/src/main.cpp b/src/main.cpp index 3260885..14092e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2263,6 +2263,21 @@ void MainWindow::updateRenderedView(TabState& tab, SplitPane& pane) { // Set text pane.rendered->setText(text); + // Set horizontal scroll width to match the longest line (ignoring trailing spaces) + { + int maxLen = 0; + const QStringList lines = text.split(QChar('\n')); + for (const auto& line : lines) { + int len = (int)line.size(); + while (len > 0 && line[len - 1] == QChar(' ')) --len; + maxLen = std::max(maxLen, len); + } + QFontMetrics fm(pane.rendered->font()); + int pixelWidth = fm.horizontalAdvance(QString(maxLen, QChar('0'))); + pane.rendered->SendScintilla(QsciScintillaBase::SCI_SETSCROLLWIDTH, + (unsigned long)qMax(1, pixelWidth)); + } + // Update margin width for line count int lineCount = pane.rendered->lines(); QString marginStr = QString(QString::number(lineCount).size() + 2, '0');