diff --git a/uppsrc/CtrlLib/RichText.h b/uppsrc/CtrlLib/RichText.h index 3b5051f58..434876c1b 100644 --- a/uppsrc/CtrlLib/RichText.h +++ b/uppsrc/CtrlLib/RichText.h @@ -14,7 +14,6 @@ public: virtual void LeftTriple(Point p, dword keyflags); virtual void RightDown(Point p, dword keyflags); virtual String GetSelectionData(const String& fmt) const; - virtual void LostFocus(); private: Rect margin; @@ -55,6 +54,7 @@ protected: public: Event WhenLink; Event WhenMouseMove; + Event<> WhenLeftClick; void Clear(); void Pick(RichText&& t); @@ -81,6 +81,7 @@ public: int GetLength() const { return text.GetLength(); } bool IsSelection() const { return anchor != cursor; } + void ClearSelection(); void Copy(); void ScrollUp() { sb.PrevLine(); } diff --git a/uppsrc/CtrlLib/RichTextView.cpp b/uppsrc/CtrlLib/RichTextView.cpp index 5dcab3820..355869e0f 100644 --- a/uppsrc/CtrlLib/RichTextView.cpp +++ b/uppsrc/CtrlLib/RichTextView.cpp @@ -208,10 +208,12 @@ void RichTextView::RefreshSel() SetSelectionSource(ClipFmtsText()); } -void RichTextView::LostFocus() +void RichTextView::ClearSelection() { - anchor = cursor; - RefreshSel(); + if(IsSelection()) { + anchor = cursor; + RefreshSel(); + } } void RichTextView::LeftDown(Point p, dword keyflags) @@ -232,6 +234,7 @@ void RichTextView::LeftDown(Point p, dword keyflags) SetFocus(); SetCapture(); } + WhenLeftClick(); } void RichTextView::LeftDouble(Point p, dword keyflags) diff --git a/upptst/RichTextCtrlSelection/main.cpp b/upptst/RichTextCtrlSelection/main.cpp index 9179e363f..9d96c43d1 100644 --- a/upptst/RichTextCtrlSelection/main.cpp +++ b/upptst/RichTextCtrlSelection/main.cpp @@ -5,6 +5,9 @@ RichTextCtrlSelection::RichTextCtrlSelection() CtrlLayout(*this, "Window title"); a <<= "This is some text"; b <<= "This is another text"; + + a.WhenLeftClick = [=] { b.ClearSelection(); }; + b.WhenLeftClick = [=] { a.ClearSelection(); }; } GUI_APP_MAIN