From a376ed90b921da982018a6d524b7457db3b169cb Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 18 May 2014 07:50:23 -0700 Subject: [PATCH] Insert \\N on shift-enter in the edit box --- src/subs_edit_ctrl.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index b98a38047..1d1944fd8 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -188,11 +188,22 @@ void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) { } void SubsTextEditCtrl::OnKeyDown(wxKeyEvent &event) { - // Workaround for wxSTC eating tabs. - if (event.GetKeyCode() == WXK_TAB) { - Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward); - } event.Skip(); + + // Workaround for wxSTC eating tabs. + if (event.GetKeyCode() == WXK_TAB) + Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward); + else if (event.GetKeyCode() == WXK_RETURN && event.GetModifiers() == wxMOD_SHIFT) { + auto sel_start = GetSelectionStart(), sel_end = GetSelectionEnd(); + wxCharBuffer old = GetTextRaw(); + std::string data(old.data(), sel_start); + data.append("\\N"); + data.append(old.data() + sel_end, old.length() - sel_end); + SetTextRaw(data.c_str()); + + SetSelection(sel_start + 2, sel_start + 2); + event.Skip(false); + } } void SubsTextEditCtrl::SetSyntaxStyle(int id, wxFont &font, std::string const& name) {