[colobot] 72/100: Allow ctrl + backspace in the editor. (#839)

Didier Raboud odyx at moszumanska.debian.org
Thu Jun 1 18:10:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit a0e5cc25e136a57cda05fb58610a7fb6957b6659
Author: MatiRg <MatiRg at users.noreply.github.com>
Date:   Mon May 22 10:57:30 2017 +0200

    Allow ctrl + backspace in the editor. (#839)
---
 src/ui/controls/edit.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/ui/controls/edit.h   |  1 +
 2 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp
index f453c8f..af04d93 100644
--- a/src/ui/controls/edit.cpp
+++ b/src/ui/controls/edit.cpp
@@ -84,7 +84,17 @@ bool IsSep(int character)
     return !IsWord(character);
 }
 
+bool IsBreaker(char c)
+{
+    return ( c == '.'  || c == '{' || c == '}' ||
+             c == ';' || c == ':' || c == '[' || c == ']' ||
+             c == '(' || c == ')' || c == '=' || c == '"' || c == '\'' );
+}
 
+bool IsDelimiter(char c)
+{
+    return IsSpace( c ) || IsBreaker( c );
+}
 
 //! Object's constructor.
 CEdit::CEdit()
@@ -449,6 +459,19 @@ bool CEdit::EventProcess(const Event &event)
             return true;
         }
 
+        if ( data->key == KEY(BACKSPACE) && bControl )
+        {
+            DeleteWord(-1);
+            SendModifEvent();
+            return true;
+        }
+        if ( data->key == KEY(DELETE) && bControl )
+        {
+            DeleteWord(1);
+            SendModifEvent();
+            return true;
+        }
+
         if ( data->key == KEY(RETURN) && !bControl )
         {
             Insert('\n');
@@ -2744,8 +2767,62 @@ void CEdit::DeleteOne(int dir)
     }
     m_len -= hole;
     m_cursor2 = m_cursor1;
-}
+}
+
+// Delete word
+
+void CEdit::DeleteWord(int dir)
+{
+    if ( !m_bEdit ) return;
+
+    if ( dir < 0 )
+    {
+        if ( m_cursor1 > 0) m_cursor2 = --m_cursor1;
+        else m_cursor2 = m_cursor1;
+
+        if ( IsBreaker(m_text[m_cursor1]) )
+        {
+            Delete(1);
+            return;
+        }
+        else ++m_cursor1;
+
+        while ( m_cursor1 < m_len && !IsDelimiter(m_text[m_cursor1]) ) ++m_cursor1;
+
+        while ( m_cursor2 > 0 && IsSpace(m_text[m_cursor2]) ) --m_cursor2;
+
+        if ( !IsDelimiter(m_text[m_cursor2]) )
+        {
+            while ( m_cursor2 > 0 && !IsDelimiter(m_text[m_cursor2]) ) --m_cursor2;
+            if ( IsBreaker(m_text[m_cursor2]) ) ++m_cursor2;
+        }
+
+        Delete(-1);
+    }
+    else
+    {
+        m_cursor2 = m_cursor1;
+
+        while ( m_cursor1 < m_len && IsSpace(m_text[m_cursor1]) ) ++m_cursor1;
 
+        if ( IsBreaker(m_text[m_cursor1]) )
+        {
+            ++m_cursor1;
+            Delete(1);
+            return;
+        }
+
+        while ( m_cursor1 < m_len && !IsDelimiter(m_text[m_cursor1]) ) ++m_cursor1;
+
+        if ( !IsDelimiter(m_text[m_cursor2]) )
+        {
+            while ( m_cursor2 > 0 && !IsDelimiter(m_text[m_cursor2]) ) --m_cursor2;
+            if ( IsBreaker(m_text[m_cursor2]) ) ++m_cursor2;
+        }
+
+        Delete(-1);
+    }
+}
 
 // Calculates the indentation level of brackets {and}.
 
diff --git a/src/ui/controls/edit.h b/src/ui/controls/edit.h
index 8beb114..380fbf5 100644
--- a/src/ui/controls/edit.h
+++ b/src/ui/controls/edit.h
@@ -207,6 +207,7 @@ protected:
     void        InsertOne(char character);
     void        Delete(int dir);
     void        DeleteOne(int dir);
+    void        DeleteWord(int dir);
     int         IndentCompute();
     int         IndentTabCount();
     void        IndentTabAdjust(int number);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list