Skip to content

Commit

Permalink
Add a setLines() method to FTextVie
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Apr 2, 2024
1 parent 580c499 commit 0078fd6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2023-04-02 Markus Gans <guru.mail@muenster.de>
* Implementation of the mouse selection in the FTextView. Can be
activated by setSelectable()
* Add a setLines() method to FTextView

2023-03-26 Markus Gans <guru.mail@muenster.de>
* Visual highlighting of the selected text in FTextView
Expand Down
10 changes: 5 additions & 5 deletions final/widget/ftextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 12 additions & 0 deletions final/widget/ftextview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
void setLines (T&&);
void setSelectable (bool = true);
void unsetSelectable();
void scrollToX (int);
Expand Down Expand Up @@ -416,6 +418,16 @@ inline void FTextView::resetSelection()
selection_end = {UNINITIALIZED_ROW, UNINITIALIZED_COLUMN};
}

//----------------------------------------------------------------------
template <typename T>
inline void FTextView::setLines (T&& list)
{
clear();
data = std::forward<T>(list);
updateVerticalScrollBar();
processChanged();
}

//----------------------------------------------------------------------
inline void FTextView::setSelectable (bool enable)
{ selectable = enable; }
Expand Down

0 comments on commit 0078fd6

Please sign in to comment.