ui: adapt scroll target value in code single file mode as workaround when view scrolls below last line
This commit is contained in:
@@ -274,8 +274,7 @@ void QtCodeArea::lineNumberAreaPaintEvent(QPaintEvent *event)
|
||||
|
||||
int QtCodeArea::lineNumberDigits() const
|
||||
{
|
||||
int max = qMax(1, int(getStartLineNumber()) + blockCount());
|
||||
return utility::digits(max);
|
||||
return utility::digits(getEndLineNumber());
|
||||
}
|
||||
|
||||
int QtCodeArea::lineNumberAreaWidth() const
|
||||
|
||||
@@ -130,6 +130,11 @@ uint QtCodeField::getEndLineNumber() const
|
||||
return m_startLineNumber + blockCount() - 1;
|
||||
}
|
||||
|
||||
int QtCodeField::totalLineHeight() const
|
||||
{
|
||||
return blockBoundingRect(firstVisibleBlock()).height() * blockCount();
|
||||
}
|
||||
|
||||
std::string QtCodeField::getCode() const
|
||||
{
|
||||
return m_code;
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
uint getStartLineNumber() const;
|
||||
uint getEndLineNumber() const;
|
||||
|
||||
int totalLineHeight() const;
|
||||
|
||||
std::string getCode() const;
|
||||
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationFile() const;
|
||||
|
||||
@@ -195,6 +195,19 @@ bool QtCodeFileSingle::requestScroll(
|
||||
double percentA = double(lineNumber - 1) / m_area->getEndLineNumber();
|
||||
double percentB = endLineNumber ? double(endLineNumber - 1) / m_area->getEndLineNumber() : 0.0f;
|
||||
|
||||
// fix percentages wrong when code area is scrollable beyond last line due to some unknown bug
|
||||
{
|
||||
int totalHeight = m_area->sizeHint().height();
|
||||
int totalLineHeight = m_area->totalLineHeight();
|
||||
|
||||
if (std::abs(totalHeight - totalLineHeight) > 100)
|
||||
{
|
||||
double factor = totalLineHeight / double(totalHeight);
|
||||
percentA *= factor;
|
||||
percentB *= factor;
|
||||
}
|
||||
}
|
||||
|
||||
ensurePercentVisibleAnimated(percentA, percentB, animated, target);
|
||||
|
||||
m_scrollRequested = true;
|
||||
|
||||
Reference in New Issue
Block a user