diff --git a/ChangeLog b/ChangeLog index 8e1e44fc..3524eb49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2023-04-02 Markus Gans * Implementation of the mouse selection in the FTextView. Can be activated by setSelectable() + * Add a setLines() method to FTextView 2023-03-26 Markus Gans * Visual highlighting of the selected text in FTextView diff --git a/final/widget/ftextview.cpp b/final/widget/ftextview.cpp index c6d37677..0ac6e55b 100644 --- a/final/widget/ftextview.cpp +++ b/final/widget/ftextview.cpp @@ -442,7 +442,7 @@ void FTextView::onMouseDoubleClick (FMouseEvent* ev) using size_type = std::wstring::size_type; // Word selection exclusion characters - const std::wstring select_exclusion_chars = L" !\"#$%&'()*+,@~:;=^<>`|[]{}\\"; + const std::wstring select_exclusion_chars = LR"( !"#$%&'()*+,@~:;=^<>`|[]{}\)"; if ( ! isSelectable() || ! isWithinTextBounds(ev->getPos()) @@ -464,14 +464,14 @@ void FTextView::onMouseDoubleClick (FMouseEvent* ev) auto start_pos = string.find_last_of( select_exclusion_chars , selection_start.column ); - if ( start_pos == string.npos ) + if ( start_pos == std::wstring::npos ) start_pos = 0; else if ( start_pos != selection_start.column ) start_pos++; auto end_pos = string.find_first_of(select_exclusion_chars, start_pos); - if ( end_pos == string.npos ) + if ( end_pos == std::wstring::npos ) end_pos = string.length(); selection_start.column = start_pos; @@ -978,7 +978,7 @@ void FTextView::handleMouseDragging (const FMouseEvent* ev) || select_click_pos == FPoint(-1, -1) || isWithinTextBounds(ev->getPos()) || ev->getButton() != MouseButton::Left ) - return; + return; const int mouse_x = ev->getX(); const int mouse_y = ev->getY(); @@ -1109,7 +1109,7 @@ void FTextView::dragUp() if ( yoffset > 0 ) { yoffset--; - const std::size_t start_row = std::size_t(yoffset); + const auto start_row = std::size_t(yoffset); setSelectionEnd (start_row, 0); } diff --git a/final/widget/ftextview.h b/final/widget/ftextview.h index b6a4bdd2..33d3b9b5 100644 --- a/final/widget/ftextview.h +++ b/final/widget/ftextview.h @@ -199,6 +199,8 @@ class FTextView : public FWidget void setSelectionStart (const FTextViewList::size_type, const FString::size_type); void setSelectionEnd (const FTextViewList::size_type, const FString::size_type); void resetSelection(); + template + void setLines (T&&); void setSelectable (bool = true); void unsetSelectable(); void scrollToX (int); @@ -416,6 +418,16 @@ inline void FTextView::resetSelection() selection_end = {UNINITIALIZED_ROW, UNINITIALIZED_COLUMN}; } +//---------------------------------------------------------------------- +template +inline void FTextView::setLines (T&& list) +{ + clear(); + data = std::forward(list); + updateVerticalScrollBar(); + processChanged(); +} + //---------------------------------------------------------------------- inline void FTextView::setSelectable (bool enable) { selectable = enable; }