src/eric7/QScintilla/Shell.py

branch
eric7
changeset 10432
2fe91fe443dd
parent 10431
64157aeb0312
child 10439
21c28b0f9e41
--- a/src/eric7/QScintilla/Shell.py	Thu Dec 21 12:03:40 2023 +0100
+++ b/src/eric7/QScintilla/Shell.py	Thu Dec 21 15:46:22 2023 +0100
@@ -1133,6 +1133,7 @@
             # move cursor to end of line
             self.moveCursorToEOL()
 
+    @pyqtSlot()
     def paste(self, lines=None):
         """
         Public slot to handle the paste action.
@@ -1557,29 +1558,24 @@
                 self.setCursorPosition(line, col)
                 self.insert(txt)
 
-    def __QScintillaLeftCommand(self, method, allLinesAllowed=False):
+    def __QScintillaLeftCommand(self, method):
         """
         Private method to handle a QScintilla command working to the left.
 
         @param method shell method to execute
         @type int
-        @param allLinesAllowed flag indicating that the command may be executed
-            on any line
-        @type bool
         """
-        if self.__isCursorOnLastLine() or allLinesAllowed:
-            line, col = self.getCursorPosition()
-            if self.text(line).startswith(sys.ps1):
-                if col > len(sys.ps1):
-                    method()
-            elif self.text(line).startswith(sys.ps2):
-                if col > len(sys.ps2):
-                    method()
-            elif col > 0:
-                method()
-        else:
+        line, col = self.getCursorPosition()
+        if col > 0:
             method()
 
+        # adjust cursor position
+        line, col = self.getCursorPosition()
+        if self.text(line).startswith(sys.ps1) and col < len(sys.ps1):
+            self.setCursorPosition(line, len(sys.ps1))
+        elif self.text(line).startswith(sys.ps2) and col < len(sys.ps2):
+            self.setCursorPosition(line, len(sys.ps2))
+
     def __QScintillaCharLeft(self):
         """
         Private method to handle the Cursor Left command.
@@ -1599,11 +1595,14 @@
         @param method shell method to execute
         @type function
         """
-        # TODO: check this!
-        if self.__isCursorOnLastLine():
-            method()
-        else:
-            method()
+        method()
+
+        # adjust cursor position
+        line, col = self.getCursorPosition()
+        if self.text(line).startswith(sys.ps1) and col < len(sys.ps1):
+            self.setCursorPosition(line, len(sys.ps1))
+        elif self.text(line).startswith(sys.ps2) and col < len(sys.ps2):
+            self.setCursorPosition(line, len(sys.ps2))
 
     def __QScintillaCharRight(self):
         """
@@ -1621,13 +1620,17 @@
         """
         Private method to handle the Delete Word Right command.
         """
-        self.__QScintillaRightCommand(self.deleteWordRight)
+        # delete is only allowed on the last line
+        if self.__isCursorOnLastLine():
+            self.__QScintillaRightCommand(self.deleteWordRight)
 
     def __QScintillaDeleteLineRight(self):
         """
         Private method to handle the Delete Line Right command.
         """
-        self.__QScintillaRightCommand(self.deleteLineRight)
+        # delete is only allowed on the last line
+        if self.__isCursorOnLastLine():
+            self.__QScintillaRightCommand(self.deleteLineRight)
 
     def __QScintillaVCHome(self, cmd):
         """
@@ -1638,7 +1641,7 @@
         """
         if self.isListActive():
             self.SendScintilla(cmd)
-        elif self.__isCursorOnLastLine():
+        else:
             line, col = self.getCursorPosition()
             if self.text(line).startswith(sys.ps1):
                 col = len(sys.ps1)
@@ -1657,7 +1660,7 @@
         """
         if self.isListActive():
             self.SendScintilla(cmd)
-        elif self.__isCursorOnLastLine():
+        else:
             self.moveCursorToEOL()
 
     def __QScintillaCursorCommand(self, cmd):
@@ -1812,13 +1815,13 @@
         """
         Private method to handle the Extend Selection Left command.
         """
-        self.__QScintillaLeftCommand(self.extendSelectionLeft, True)
+        self.__QScintillaLeftCommand(self.extendSelectionLeft)
 
     def __QScintillaWordLeftExtend(self):
         """
         Private method to handle the Extend Selection Left one word command.
         """
-        self.__QScintillaLeftCommand(self.extendSelectionWordLeft, True)
+        self.__QScintillaLeftCommand(self.extendSelectionWordLeft)
 
     def __QScintillaVCHomeExtend(self):
         """

eric ide

mercurial