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'.
This commit is contained in:
Thomas Goyne 2014-04-22 17:01:22 -07:00
parent b4284efb38
commit ec6f14eef4
2 changed files with 10 additions and 0 deletions

View File

@ -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;

View File

@ -91,6 +91,7 @@ class SubsTextEditCtrl final : public ScintillaTextCtrl {
std::vector<agi::ass::DialogueToken> tokenized_line;
void OnContextMenu(wxContextMenuEvent &);
void OnDoubleClick(wxStyledTextEvent&);
void OnUseSuggestion(wxCommandEvent &event);
void OnSetDicLanguage(wxCommandEvent &event);
void OnSetThesLanguage(wxCommandEvent &event);