Author: ekohl
Date: Sun Dec 21 12:36:24 2014
New Revision: 65782

URL: http://svn.reactos.org/svn/reactos?rev=65782&view=rev
Log:
[CMD]
Implement CTRL+Left (jump to previous word) and CRTL+Right (jump to next word) 
edit keys.

CORE-5626 #resolve

Modified:
    trunk/reactos/base/shell/cmd/cmdinput.c

Modified: trunk/reactos/base/shell/cmd/cmdinput.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmdinput.c?rev=65782&r1=65781&r2=65782&view=diff
==============================================================================
--- trunk/reactos/base/shell/cmd/cmdinput.c     [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmdinput.c     [iso-8859-1] Sun Dec 21 
12:36:24 2014
@@ -137,6 +137,7 @@
     INT   current = 0;  /*the position of the cursor in the string (str)*/
     INT   charcount = 0;/*chars in the string (str)*/
     INPUT_RECORD ir;
+    DWORD dwControlKeyState;
 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
     WORD   wLastKey = 0;
 #endif
@@ -185,7 +186,9 @@
         bReturn = FALSE;
         ConInKey (&ir);
 
-        if (ir.Event.KeyEvent.dwControlKeyState &
+        dwControlKeyState = ir.Event.KeyEvent.dwControlKeyState;
+
+        if (dwControlKeyState &
             (RIGHT_ALT_PRESSED |LEFT_ALT_PRESSED|
              RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED) )
         {
@@ -194,7 +197,7 @@
 #ifdef FEATURE_HISTORY
                 case 'K':
                     /*add the current command line to the history*/
-                    if (ir.Event.KeyEvent.dwControlKeyState &
+                    if (dwControlKeyState &
                         (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
                     {
                         if (str[0])
@@ -210,7 +213,7 @@
 
                 case 'D':
                     /*delete current history entry*/
-                    if (ir.Event.KeyEvent.dwControlKeyState &
+                    if (dwControlKeyState &
                         (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
                     {
                         ClearCommandLine (str, maxlen, orgx, orgy);
@@ -481,59 +484,137 @@
                 break;
 
             case VK_LEFT:
-                /* move cursor left */
-                if (current > 0)
-                {
-                    current--;
-                    if (GetCursorX () == 0)
-                    {
-                        SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () 
- 1));
-                        curx = maxx - 1;
-                        cury--;
+                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 */
+                    if (current > 0)
+                    {
+                        current--;
+                        if (GetCursorX () == 0)
+                        {
+                            SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY 
() - 1));
+                            curx = maxx - 1;
+                            cury--;
+                        }
+                        else
+                        {
+                            SetCursorXY ((SHORT)(GetCursorX () - 1), 
GetCursorY ());
+                            curx--;
+                        }
                     }
                     else
                     {
-                        SetCursorXY ((SHORT)(GetCursorX () - 1), GetCursorY 
());
-                        curx--;
+                        MessageBeep (-1);
+                    }
+                }
+                break;
+
+            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
                 {
-                    MessageBeep (-1);
-                }
-                break;
-
-            case VK_RIGHT:
-                /* move cursor right */
-                if (current != charcount)
-                {
-                    current++;
-                    if (GetCursorX () == maxx - 1)
-                    {
-                        SetCursorXY (0, (SHORT)(GetCursorY () + 1));
-                        curx = 0;
-                        cury++;
-                    }
+                    /* move cursor right */
+                    if (current != charcount)
+                    {
+                        current++;
+                        if (GetCursorX () == maxx - 1)
+                        {
+                            SetCursorXY (0, (SHORT)(GetCursorY () + 1));
+                            curx = 0;
+                            cury++;
+                        }
+                        else
+                        {
+                            SetCursorXY ((SHORT)(GetCursorX () + 1), 
GetCursorY ());
+                            curx++;
+                        }
+                    }
+#ifdef FEATURE_HISTORY
                     else
                     {
-                        SetCursorXY ((SHORT)(GetCursorX () + 1), GetCursorY 
());
-                        curx++;
-                    }
-                }
-#ifdef FEATURE_HISTORY
-                else
-                {
-                    LPCTSTR last = PeekHistory(-1);
-                    if (last && charcount < (INT)_tcslen (last))
-                    {
-                        PreviousChar = last[current];
-                        ConOutChar(PreviousChar);
-                        GetCursorXY(&curx, &cury);
-                        str[current++] = PreviousChar;
-                        charcount++;
-                    }
-                }
-#endif
+                        LPCTSTR last = PeekHistory(-1);
+                        if (last && charcount < (INT)_tcslen (last))
+                        {
+                            PreviousChar = last[current];
+                            ConOutChar(PreviousChar);
+                            GetCursorXY(&curx, &cury);
+                            str[current++] = PreviousChar;
+                            charcount++;
+                        }
+                    }
+#endif
+                }
                 break;
 
             default:


Reply via email to