QScintilla/Shell.py

changeset 5712
f0d08bdeacf4
parent 5711
50b6867ffcd3
child 5730
6422afc7adc4
child 5736
000ea446ff4b
diff -r 50b6867ffcd3 -r f0d08bdeacf4 QScintilla/Shell.py
--- a/QScintilla/Shell.py	Sat Apr 22 15:37:18 2017 +0200
+++ b/QScintilla/Shell.py	Sun Apr 23 16:40:31 2017 +0200
@@ -297,8 +297,10 @@
             QsciScintilla.SCI_WORDRIGHT: self.__QScintillaWordRight,
             QsciScintilla.SCI_VCHOME: self.__QScintillaVCHome,
             QsciScintilla.SCI_LINEEND: self.__QScintillaLineEnd,
-            QsciScintilla.SCI_LINEUP: self.__QScintillaLineUp,
-            QsciScintilla.SCI_LINEDOWN: self.__QScintillaLineDown,
+            QsciScintilla.SCI_LINEUP: self.__QScintillaCommand,
+            QsciScintilla.SCI_LINEDOWN: self.__QScintillaCommand,
+            QsciScintilla.SCI_LINESCROLLUP: self.__QScintillaHistoryUp,
+            QsciScintilla.SCI_LINESCROLLDOWN: self.__QScintillaHistoryDown,
             
             QsciScintilla.SCI_PAGEUP: self.__QScintillaAutoCompletionCommand,
             QsciScintilla.SCI_PAGEDOWN: self.__QScintillaAutoCompletionCommand,
@@ -705,6 +707,9 @@
         Private method to write the prompt.
         """
         self.__write(self.inContinue and sys.ps2 or sys.ps1)
+        # little trick to get the cursor position registered within QScintilla
+        self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
+        self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
         
     def __clientStatement(self, more):
         """
@@ -1091,6 +1096,14 @@
         else:
             ev.ignore()
         
+    def __QScintillaCommand(self, cmd):
+        """
+        Private method to send the command to QScintilla.
+        
+        @param cmd QScintilla command
+        """
+        self.SendScintilla(cmd)
+        
     def __QScintillaTab(self, cmd):
         """
         Private method to handle the Tab key.
@@ -1210,6 +1223,22 @@
                     buf = buf.replace(sys.ps2, "")
                 self.insert('\n')
                 self.__executeCommand(buf)
+        else:
+            txt = ""
+            line, col = self.getCursorPosition()
+            if self.hasSelectedText():
+                lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
+                if line == lineFrom:
+                    txt = self.text(line)[indexFrom:].rstrip()
+                elif line == lineTo:
+                    txt = self.text(line)[:indexTo]
+            else:
+                txt = self.text(line)[col:].rstrip()
+            
+            if txt:
+                line, col = self.__getEndPos()
+                self.setCursorPosition(line, col)
+                self.insert(txt)
         
     def __QScintillaLeftCommand(self, method, allLinesAllowed=False):
         """
@@ -1229,6 +1258,8 @@
                     method()
             elif col > 0:
                 method()
+        else:
+            method()
         
     def __QScintillaCharLeft(self):
         """
@@ -1250,6 +1281,8 @@
         """
         if self.__isCursorOnLastLine():
             method()
+        else:
+            method()
         
     def __QScintillaCharRight(self):
         """
@@ -1304,73 +1337,67 @@
         elif self.__isCursorOnLastLine():
             self.moveCursorToEOL()
         
-    def __QScintillaLineUp(self, cmd):
+    def __QScintillaHistoryUp(self, cmd):
         """
-        Private method to handle the Up key.
+        Private method to handle the Ctrl+Up key.
         
         @param cmd QScintilla command
         """
-        if self.isListActive():
-            self.SendScintilla(cmd)
+        line, col = self.__getEndPos()
+        buf = self.text(line)
+        if buf.startswith(sys.ps1):
+            buf = buf.replace(sys.ps1, "")
+        if buf.startswith(sys.ps2):
+            buf = buf.replace(sys.ps2, "")
+        if buf and self.incrementalSearchActive:
+            if self.incrementalSearchString:
+                idx = self.__rsearchHistory(self.incrementalSearchString,
+                                            self.histidx)
+                if idx >= 0:
+                    self.histidx = idx
+                    self.__useHistory()
+            else:
+                idx = self.__rsearchHistory(buf)
+                if idx >= 0:
+                    self.histidx = idx
+                    self.incrementalSearchString = buf
+                    self.__useHistory()
         else:
-            line, col = self.__getEndPos()
-            buf = self.text(line)
-            if buf.startswith(sys.ps1):
-                buf = buf.replace(sys.ps1, "")
-            if buf.startswith(sys.ps2):
-                buf = buf.replace(sys.ps2, "")
-            if buf and self.incrementalSearchActive:
-                if self.incrementalSearchString:
-                    idx = self.__rsearchHistory(self.incrementalSearchString,
-                                                self.histidx)
-                    if idx >= 0:
-                        self.histidx = idx
-                        self.__useHistory()
-                else:
-                    idx = self.__rsearchHistory(buf)
-                    if idx >= 0:
-                        self.histidx = idx
-                        self.incrementalSearchString = buf
-                        self.__useHistory()
-            else:
-                if self.histidx < 0:
-                    self.histidx = len(self.history)
-                if self.histidx > 0:
-                    self.histidx = self.histidx - 1
-                    self.__useHistory()
+            if self.histidx < 0:
+                self.histidx = len(self.history)
+            if self.histidx > 0:
+                self.histidx = self.histidx - 1
+                self.__useHistory()
         
-    def __QScintillaLineDown(self, cmd):
+    def __QScintillaHistoryDown(self, cmd):
         """
-        Private method to handle the Down key.
+        Private method to handle the Ctrl+Down key.
         
         @param cmd QScintilla command
         """
-        if self.isListActive():
-            self.SendScintilla(cmd)
+        line, col = self.__getEndPos()
+        buf = self.text(line)
+        if buf.startswith(sys.ps1):
+            buf = buf.replace(sys.ps1, "")
+        if buf.startswith(sys.ps2):
+            buf = buf.replace(sys.ps2, "")
+        if buf and self.incrementalSearchActive:
+            if self.incrementalSearchString:
+                idx = self.__searchHistory(
+                    self.incrementalSearchString, self.histidx)
+                if idx >= 0:
+                    self.histidx = idx
+                    self.__useHistory()
+            else:
+                idx = self.__searchHistory(buf)
+                if idx >= 0:
+                    self.histidx = idx
+                    self.incrementalSearchString = buf
+                    self.__useHistory()
         else:
-            line, col = self.__getEndPos()
-            buf = self.text(line)
-            if buf.startswith(sys.ps1):
-                buf = buf.replace(sys.ps1, "")
-            if buf.startswith(sys.ps2):
-                buf = buf.replace(sys.ps2, "")
-            if buf and self.incrementalSearchActive:
-                if self.incrementalSearchString:
-                    idx = self.__searchHistory(
-                        self.incrementalSearchString, self.histidx)
-                    if idx >= 0:
-                        self.histidx = idx
-                        self.__useHistory()
-                else:
-                    idx = self.__searchHistory(buf)
-                    if idx >= 0:
-                        self.histidx = idx
-                        self.incrementalSearchString = buf
-                        self.__useHistory()
-            else:
-                if self.histidx >= 0 and self.histidx < len(self.history):
-                    self.histidx += 1
-                    self.__useHistory()
+            if self.histidx >= 0 and self.histidx < len(self.history):
+                self.histidx += 1
+                self.__useHistory()
         
     def __QScintillaCharLeftExtend(self):
         """

eric ide

mercurial