From ec6f14eef47cb7246367ebeef32f9868fb9168c8 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 22 Apr 2014 17:01:22 -0700 Subject: [PATCH] Make double-click in the edit box smarter Use the syntax highlighting's word splitting to decide what to select so that double-clicking on \Nword only selects 'word'. --- src/subs_edit_ctrl.cpp | 9 +++++++++ src/subs_edit_ctrl.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index ac5ffead7..e7c17db24 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -122,6 +122,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a Bind(wxEVT_CONTEXT_MENU, &SubsTextEditCtrl::OnContextMenu, this); Bind(wxEVT_IDLE, std::bind(&SubsTextEditCtrl::UpdateCallTip, this)); + Bind(wxEVT_STC_DOUBLECLICK, &SubsTextEditCtrl::OnDoubleClick, this); Bind(wxEVT_STC_STYLENEEDED, [=](wxStyledTextEvent&) { { std::string text = GetTextRaw().data(); @@ -349,6 +350,14 @@ void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) { PopupMenu(&menu); } +void SubsTextEditCtrl::OnDoubleClick(wxStyledTextEvent &evt) { + auto bounds = GetBoundsOfWordAtPosition(evt.GetPosition()); + if (bounds.second != 0) + SetSelection(bounds.first, bounds.first + bounds.second); + else + evt.Skip(); +} + void SubsTextEditCtrl::AddSpellCheckerEntries(wxMenu &menu) { if (currentWord.empty()) return; diff --git a/src/subs_edit_ctrl.h b/src/subs_edit_ctrl.h index 24f7ceac0..d708f8bb9 100644 --- a/src/subs_edit_ctrl.h +++ b/src/subs_edit_ctrl.h @@ -91,6 +91,7 @@ class SubsTextEditCtrl final : public ScintillaTextCtrl { std::vector tokenized_line; void OnContextMenu(wxContextMenuEvent &); + void OnDoubleClick(wxStyledTextEvent&); void OnUseSuggestion(wxCommandEvent &event); void OnSetDicLanguage(wxCommandEvent &event); void OnSetThesLanguage(wxCommandEvent &event);