Implement CTRL+Left (jump to previous word) and CRTL+Right (jump to next word) edit keys.

CORE-5626 #resolve

svn path=/trunk/; revision=65782
This commit is contained in:
Eric Kohl 2014-12-21 12:36:24 +00:00
parent 7528b04c30
commit baf567d896

View file

@ -137,6 +137,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
INT current = 0; /*the position of the cursor in the string (str)*/ INT current = 0; /*the position of the cursor in the string (str)*/
INT charcount = 0;/*chars in the string (str)*/ INT charcount = 0;/*chars in the string (str)*/
INPUT_RECORD ir; INPUT_RECORD ir;
DWORD dwControlKeyState;
#ifdef FEATURE_UNIX_FILENAME_COMPLETION #ifdef FEATURE_UNIX_FILENAME_COMPLETION
WORD wLastKey = 0; WORD wLastKey = 0;
#endif #endif
@ -185,7 +186,9 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
bReturn = FALSE; bReturn = FALSE;
ConInKey (&ir); ConInKey (&ir);
if (ir.Event.KeyEvent.dwControlKeyState & dwControlKeyState = ir.Event.KeyEvent.dwControlKeyState;
if (dwControlKeyState &
(RIGHT_ALT_PRESSED |LEFT_ALT_PRESSED| (RIGHT_ALT_PRESSED |LEFT_ALT_PRESSED|
RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED) ) RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED) )
{ {
@ -194,7 +197,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
#ifdef FEATURE_HISTORY #ifdef FEATURE_HISTORY
case 'K': case 'K':
/*add the current command line to the history*/ /*add the current command line to the history*/
if (ir.Event.KeyEvent.dwControlKeyState & if (dwControlKeyState &
(LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
{ {
if (str[0]) if (str[0])
@ -210,7 +213,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
case 'D': case 'D':
/*delete current history entry*/ /*delete current history entry*/
if (ir.Event.KeyEvent.dwControlKeyState & if (dwControlKeyState &
(LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
{ {
ClearCommandLine (str, maxlen, orgx, orgy); ClearCommandLine (str, maxlen, orgx, orgy);
@ -481,6 +484,44 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
break; break;
case VK_LEFT: case VK_LEFT:
if (dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
{
/* move cursor to the previous word */
if (current > 0)
{
while (current > 0 && str[current - 1] == _T(' '))
{
current--;
if (curx == 0)
{
cury--;
curx = maxx -1;
}
else
{
curx--;
}
}
while (current > 0 && str[current -1] != _T(' '))
{
current--;
if (curx == 0)
{
cury--;
curx = maxx -1;
}
else
{
curx--;
}
}
SetCursorXY(curx, cury);
}
}
else
{
/* move cursor left */ /* move cursor left */
if (current > 0) if (current > 0)
{ {
@ -501,9 +542,48 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
{ {
MessageBeep (-1); MessageBeep (-1);
} }
}
break; break;
case VK_RIGHT: case VK_RIGHT:
if (dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
{
/* move cursor to the next word */
if (current != charcount)
{
while (current != charcount && str[current] != _T(' '))
{
current++;
if (curx == maxx - 1)
{
cury++;
curx = 0;
}
else
{
curx++;
}
}
while (current != charcount && str[current] == _T(' '))
{
current++;
if (curx == maxx - 1)
{
cury++;
curx = 0;
}
else
{
curx++;
}
}
SetCursorXY(curx, cury);
}
}
else
{
/* move cursor right */ /* move cursor right */
if (current != charcount) if (current != charcount)
{ {
@ -534,6 +614,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
} }
} }
#endif #endif
}
break; break;
default: default: