Add Ctrl+Backspace and Ctrl+Del to ui::Entry field (fix #769)

This commit is contained in:
David Capello 2015-08-20 23:31:46 -03:00
parent dc33cf754b
commit 9662c0cb90
2 changed files with 21 additions and 3 deletions

View File

@ -254,6 +254,8 @@ bool Entry::onProcessMessage(Message* msg)
case kKeyDel:
if (msg->shiftPressed())
cmd = EntryCmd::Cut;
else if (msg->ctrlPressed())
cmd = EntryCmd::DeleteForwardToEndOfLine;
else
cmd = EntryCmd::DeleteForward;
break;
@ -266,7 +268,10 @@ bool Entry::onProcessMessage(Message* msg)
break;
case kKeyBackspace:
cmd = EntryCmd::DeleteBackward;
if (msg->ctrlPressed())
cmd = EntryCmd::DeleteBackwardWord;
else
cmd = EntryCmd::DeleteBackward;
break;
default:
@ -657,6 +662,18 @@ void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed)
m_select = -1;
break;
case EntryCmd::DeleteBackwardWord:
m_select = m_caret;
backwardWord();
if (m_caret < m_select)
text.erase(m_caret, m_select-m_caret);
m_select = -1;
break;
case EntryCmd::DeleteForwardToEndOfLine:
text.erase(m_caret);
break;
case EntryCmd::SelectAll:
selectAllText();
break;

View File

@ -16,8 +16,7 @@ namespace ui {
class MouseMessage;
class Entry : public Widget
{
class Entry : public Widget {
public:
Entry(std::size_t maxsize, const char *format, ...);
~Entry();
@ -67,6 +66,8 @@ namespace ui {
EndOfLine,
DeleteForward,
DeleteBackward,
DeleteBackwardWord,
DeleteForwardToEndOfLine,
Cut,
Copy,
Paste,