diff --git a/final/widget/flistview.cpp b/final/widget/flistview.cpp index 7db156c3..c0934f56 100644 --- a/final/widget/flistview.cpp +++ b/final/widget/flistview.cpp @@ -2179,7 +2179,7 @@ inline void FListView::afterInsertion() } //---------------------------------------------------------------------- -void FListView::adjustListBeforeRemoval (FListViewItem* item) +void FListView::adjustListBeforeRemoval (const FListViewItem* item) { const auto* current_item = static_cast(*selection.current_iter); const auto* first_item = data.itemlist.front(); diff --git a/final/widget/flistview.h b/final/widget/flistview.h index 7e05acd2..e6502dee 100644 --- a/final/widget/flistview.h +++ b/final/widget/flistview.h @@ -520,7 +520,7 @@ class FListView : public FWidget auto determineLineWidth (FListViewItem*) -> std::size_t; void beforeInsertion (FListViewItem*); void afterInsertion(); - void adjustListBeforeRemoval (FListViewItem*); + void adjustListBeforeRemoval (const FListViewItem*); void removeItemFromParent (FListViewItem*); void updateListAfterRemoval(); void recalculateHorizontalBar (std::size_t); diff --git a/final/widget/ftextview.cpp b/final/widget/ftextview.cpp index 70f184d6..e75cba3e 100644 --- a/final/widget/ftextview.cpp +++ b/final/widget/ftextview.cpp @@ -279,67 +279,13 @@ void FTextView::insert (const FString& str, int pos) if ( pos < 0 || pos >= int(getRows()) ) pos = int(getRows()); - auto showHorizontallyScrollable = [this] () + for (auto&& line : splitTextLines(str)) // Line loop { - if ( isShown() && isHorizontallyScrollable() ) - hbar->show(); - }; - - auto&& text_split = \ - [&str] () - { - if ( str.isEmpty() ) - { - FStringList list{}; - list.emplace_back(""); - return list; - } - - const auto& string = str.rtrim().expandTabs(getFOutput()->getTabstop()); - return string.split("\n"); - }(); - - for (auto&& line : text_split) // Line loop - { - line = line.removeBackspaces() - .removeDel() - .replaceControlCodes() - .rtrim(); - const auto column_width = getColumnWidth(line); - - if ( column_width > max_line_width ) - { - max_line_width = column_width; - - if ( column_width > getTextWidth() ) - { - const int hmax = ( max_line_width > getTextWidth() ) - ? int(max_line_width) - int(getTextWidth()) - : 0; - hbar->setMaximum (hmax); - hbar->setPageSize (int(max_line_width), int(getTextWidth())); - hbar->calculateSliderValues(); - showHorizontallyScrollable(); - } - } - - data.emplace (data.cbegin() + pos, std::move(line)); + processLine(std::move(line), pos); pos++; } - const int vmax = ( getRows() > getTextHeight() ) - ? int(getRows()) - int(getTextHeight()) - : 0; - vbar->setMaximum (vmax); - vbar->setPageSize (int(getRows()), int(getTextHeight())); - vbar->calculateSliderValues(); - - if ( isShown() && ! vbar->isShown() && isVerticallyScrollable() ) - vbar->show(); - - if ( isShown() && vbar->isShown() && ! isVerticallyScrollable() ) - vbar->hide(); - + updateVerticalScrollBar(); processChanged(); } @@ -689,6 +635,71 @@ inline auto FTextView::isPrintable (wchar_t ch) const -> bool || (! utf8 && std::isprint(char(ch))) ); } +//---------------------------------------------------------------------- +inline auto FTextView::splitTextLines (const FString& str) const -> FStringList +{ + if ( str.isEmpty() ) + { + FStringList list{}; + list.emplace_back(""); + return list; + } + + const auto& string = str.rtrim().expandTabs(getFOutput()->getTabstop()); + return string.split("\n"); +} + +//---------------------------------------------------------------------- +inline void FTextView::processLine (FString&& line, int pos) +{ + line = line.removeBackspaces() + .removeDel() + .replaceControlCodes() + .rtrim(); + + data.emplace (data.cbegin() + pos, std::move(line)); + updateHorizontalScrollBar (getColumnWidth(line)); +} + +//---------------------------------------------------------------------- +inline void FTextView::updateVerticalScrollBar() +{ + const int vmax = ( getRows() > getTextHeight() ) + ? int(getRows()) - int(getTextHeight()) + : 0; + vbar->setMaximum (vmax); + vbar->setPageSize (int(getRows()), int(getTextHeight())); + vbar->calculateSliderValues(); + + if ( isShown() && ! vbar->isShown() && isVerticallyScrollable() ) + vbar->show(); + + if ( isShown() && vbar->isShown() && ! isVerticallyScrollable() ) + vbar->hide(); +} + +//---------------------------------------------------------------------- +inline void FTextView::updateHorizontalScrollBar (std::size_t column_width) +{ + if ( column_width <= max_line_width ) + return; + + max_line_width = column_width; + + if ( column_width <= getTextWidth() ) + return; + + const int hmax = ( max_line_width > getTextWidth() ) + ? int(max_line_width) - int(getTextWidth()) + : 0; + hbar->setMaximum (hmax); + hbar->setPageSize (int(max_line_width), int(getTextWidth())); + hbar->calculateSliderValues(); + + if ( isShown() && isHorizontallyScrollable() ) + hbar->show(); +} + //---------------------------------------------------------------------- void FTextView::processChanged() const { diff --git a/final/widget/ftextview.h b/final/widget/ftextview.h index 9067af92..70bfe6fa 100644 --- a/final/widget/ftextview.h +++ b/final/widget/ftextview.h @@ -242,6 +242,10 @@ class FTextView : public FWidget , const std::vector& ); auto useFDialogBorder() const -> bool; auto isPrintable (wchar_t) const -> bool; + auto splitTextLines (const FString&) const -> FStringList; + void processLine (FString&&, int); + void updateVerticalScrollBar(); + void updateHorizontalScrollBar (std::size_t); void processChanged() const; void changeOnResize() const; diff --git a/test/fkeyboard-test.cpp b/test/fkeyboard-test.cpp index e322f194..39628e8c 100644 --- a/test/fkeyboard-test.cpp +++ b/test/fkeyboard-test.cpp @@ -3171,7 +3171,7 @@ void FKeyboardTest::init() // Copy the section with the fixed escape sequences auto& fkey_cap_table = finalcut::FKeyMap::getInstance().getKeyCapMap(); std::size_t first = 150; - std::size_t last = fkey_cap_table.size(); + std::size_t last = fkey_cap_table.size() - 1; assert ( last > first ); std::copy ( &fkey_cap_table[first].num, &fkey_cap_table[last].num, &test::fkey[first].num);