From 3e827194b88f4a78b9a6b3b3b4454bcddf9ee1dc Mon Sep 17 00:00:00 2001 From: Sen66 Date: Fri, 13 Feb 2026 01:55:52 +0100 Subject: [PATCH] Adjustments to scrollbars --- src/editor.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/editor.cpp b/src/editor.cpp index 0d4bdf6..df8b787 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -128,10 +128,13 @@ void RcxEditor::setupScintilla() { m_sci->SendScintilla(QsciScintillaBase::SCI_SETSELFORE, (long)0, (long)0); m_sci->SendScintilla(QsciScintillaBase::SCI_SETSELBACK, (long)0, (long)0); - // Auto-size horizontal scrollbar to actual content width (default is fixed 2000px) - m_sci->SendScintilla(QsciScintillaBase::SCI_SETSCROLLWIDTHTRACKING, 1); + // Horizontal scrollbar: sized explicitly in applyDocument() to match content + m_sci->SendScintilla(QsciScintillaBase::SCI_SETSCROLLWIDTHTRACKING, 0); m_sci->SendScintilla(QsciScintillaBase::SCI_SETSCROLLWIDTH, 1); + // Vertical scrollbar: don't allow scrolling past the last line + m_sci->SendScintilla(QsciScintillaBase::SCI_SETENDATLASTLINE, 1); + // Editable-field indicator - HIDDEN (no visual) m_sci->SendScintilla(QsciScintillaBase::SCI_INDICSETSTYLE, IND_EDITABLE, 5 /*INDIC_HIDDEN*/); @@ -371,9 +374,20 @@ void RcxEditor::applyDocument(const ComposeResult& result) { m_sci->setText(result.text); m_sci->setReadOnly(true); - // Reset scroll width so tracking re-measures from current content - // (tracking never shrinks automatically — only grows) - m_sci->SendScintilla(QsciScintillaBase::SCI_SETSCROLLWIDTH, 1); + // Set horizontal scroll width to match the longest line (ignoring trailing spaces) + { + int maxLen = 0; + const QStringList lines = result.text.split(QChar('\n')); + for (const auto& line : lines) { + int len = line.size(); + while (len > 0 && line[len - 1] == QChar(' ')) --len; + if (len > maxLen) maxLen = len; + } + QFontMetrics fm(editorFont()); + int pixelWidth = fm.horizontalAdvance(QString(maxLen, QChar('0'))); + m_sci->SendScintilla(QsciScintillaBase::SCI_SETSCROLLWIDTH, + (unsigned long)qMax(1, pixelWidth)); + } // Force full re-lex to fix stale syntax coloring after edits m_sci->SendScintilla(QsciScintillaBase::SCI_COLOURISE, (uintptr_t)0, (long)-1);