QScintilla/Shell.py

changeset 6029
0ce26b97e2c0
parent 5991
1ab3f4de8a4b
child 6037
9aec96a3a82a
equal deleted inserted replaced
6028:859f6894eed9 6029:0ce26b97e2c0
964 Public slot to handle the paste action. 964 Public slot to handle the paste action.
965 """ 965 """
966 if self.__isCursorOnLastLine(): 966 if self.__isCursorOnLastLine():
967 line, col = self.getCursorPosition() 967 line, col = self.getCursorPosition()
968 lastLine = self.text(line) 968 lastLine = self.text(line)
969 if lastLine.startswith(sys.ps1):
970 lastLine = lastLine[len(sys.ps1):]
971 col -= len(sys.ps1)
972 prompt = sys.ps1
973 elif lastLine.startswith(sys.ps2):
974 lastLine = lastLine[len(sys.ps2):]
975 col -= len(sys.ps2)
976 prompt = sys.ps2
977 else:
978 prompt = ""
979 if col < 0:
980 col = 0
981 prompt = ""
969 982
970 # Remove if text is selected 983 # Remove if text is selected
971 if self.hasSelectedText(): 984 if self.hasSelectedText():
972 lineFrom, indexFrom, lineTo, indexTo = self.getSelection() 985 lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
973 if self.text(lineFrom).startswith(sys.ps1): 986 if self.text(lineFrom).startswith(sys.ps1):
974 if indexFrom < len(sys.ps1): 987 indexFrom -= len(sys.ps1)
975 indexFrom = len(sys.ps1) 988 indexTo -= len(sys.ps1)
976 elif self.text(lineFrom).startswith(sys.ps2): 989 elif self.text(lineFrom).startswith(sys.ps2):
977 if indexFrom < len(sys.ps2): 990 indexFrom -= len(sys.ps2)
978 indexFrom = len(sys.ps2) 991 indexTo -= len(sys.ps2)
992 if indexFrom < 0:
993 indexFrom = 0
979 lastLine = lastLine[:indexFrom] + lastLine[indexTo:] 994 lastLine = lastLine[:indexFrom] + lastLine[indexTo:]
980 col = indexFrom 995 col = indexFrom
981 996
982 self.setCursorPosition(line, 0) 997 self.setCursorPosition(line, len(prompt))
983 self.deleteLineRight() 998 self.deleteLineRight()
984 999
985 lines = QApplication.clipboard().text() 1000 lines = QApplication.clipboard().text()
986 lines = lastLine[:col] + lines + lastLine[col:] 1001 lines = lastLine[:col] + lines + lastLine[col:]
987 self.executeLines(lines) 1002 self.executeLines(lines)
1004 single commands 1019 single commands
1005 @type str 1020 @type str
1006 @param historyIndex history index to be set 1021 @param historyIndex history index to be set
1007 @type int 1022 @type int
1008 """ 1023 """
1009 for line in lines.splitlines(True): 1024 lines = lines.splitlines(True)
1025 if not lines:
1026 return
1027
1028 indentLen = self.__indentLength(lines[0])
1029 for line in lines:
1030 if line.startswith(sys.ps1):
1031 line = line[len(sys.ps1) + indentLen:]
1032 elif line.startswith(sys.ps2):
1033 line = line[len(sys.ps2) + indentLen:]
1034 else:
1035 line = line[indentLen:]
1036
1010 if line.endswith("\r\n"): 1037 if line.endswith("\r\n"):
1011 fullline = True 1038 fullline = True
1012 cmd = line[:-2] 1039 cmd = line[:-2]
1013 elif line.endswith("\r") or line.endswith("\n"): 1040 elif line.endswith("\r") or line.endswith("\n"):
1014 fullline = True 1041 fullline = True
1018 1045
1019 self.incrementalSearchActive = True 1046 self.incrementalSearchActive = True
1020 self.__insertTextAtEnd(line) 1047 self.__insertTextAtEnd(line)
1021 if fullline: 1048 if fullline:
1022 self.incrementalSearchActive = False 1049 self.incrementalSearchActive = False
1023 if cmd.startswith(sys.ps1):
1024 cmd = cmd[len(sys.ps1):]
1025 elif cmd.startswith(sys.ps2):
1026 cmd = cmd[len(sys.ps2):]
1027 1050
1028 self.__executeCommand(cmd, historyIndex=historyIndex) 1051 self.__executeCommand(cmd, historyIndex=historyIndex)
1029 if self.interruptCommandExecution: 1052 if self.interruptCommandExecution:
1030 self.__executeCommand("") 1053 self.__executeCommand("")
1031 break 1054 break
1032 1055
1056 def __indentLength(self, line):
1057 """
1058 Private method to determine the indentation length of the given line.
1059
1060 @param line line to determine the indentation length for
1061 @type str
1062 @return indentation length
1063 @rtype int
1064 """
1065 if line.startswith(sys.ps1):
1066 line = line[len(sys.ps1):]
1067 # If line starts with sys.ps2 or neither don't manipulate the line.
1068 indentLen = len(line) - len(line.lstrip())
1069 return indentLen
1070
1033 def __clearCurrentLine(self): 1071 def __clearCurrentLine(self):
1034 """ 1072 """
1035 Private method to clear the line containing the cursor. 1073 Private method to clear the line containing the cursor.
1036 """ 1074 """
1037 line, col = self.getCursorPosition() 1075 line, col = self.getCursorPosition()

eric ide

mercurial