Tue, 19 Dec 2017 19:46:23 +0100
Fixed an issue in the Python shell window executing pasted lines containing some indentation.
--- a/Documentation/Help/source.qhp Mon Dec 18 18:09:39 2017 +0100 +++ b/Documentation/Help/source.qhp Tue Dec 19 19:46:23 2017 +0100 @@ -14033,6 +14033,7 @@ <keyword name="Shell.__find" id="Shell.__find" ref="eric6.QScintilla.Shell.html#Shell.__find" /> <keyword name="Shell.__getBanner" id="Shell.__getBanner" ref="eric6.QScintilla.Shell.html#Shell.__getBanner" /> <keyword name="Shell.__getEndPos" id="Shell.__getEndPos" ref="eric6.QScintilla.Shell.html#Shell.__getEndPos" /> + <keyword name="Shell.__indentLength" id="Shell.__indentLength" ref="eric6.QScintilla.Shell.html#Shell.__indentLength" /> <keyword name="Shell.__initialise" id="Shell.__initialise" ref="eric6.QScintilla.Shell.html#Shell.__initialise" /> <keyword name="Shell.__insertHistory" id="Shell.__insertHistory" ref="eric6.QScintilla.Shell.html#Shell.__insertHistory" /> <keyword name="Shell.__insertText" id="Shell.__insertText" ref="eric6.QScintilla.Shell.html#Shell.__insertText" />
--- a/Documentation/Source/eric6.QScintilla.Shell.html Mon Dec 18 18:09:39 2017 +0100 +++ b/Documentation/Source/eric6.QScintilla.Shell.html Tue Dec 19 19:46:23 2017 +0100 @@ -203,6 +203,9 @@ <td><a href="#Shell.__getEndPos">__getEndPos</a></td> <td>Private method to return the line and column of the last character.</td> </tr><tr> +<td><a href="#Shell.__indentLength">__indentLength</a></td> +<td>Private method to determine the indentation length of the given line.</td> +</tr><tr> <td><a href="#Shell.__initialise">__initialise</a></td> <td>Private method to get ready for a new remote interpreter.</td> </tr><tr> @@ -793,6 +796,26 @@ <dd> tuple of two values (int, int) giving the line and column </dd> +</dl><a NAME="Shell.__indentLength" ID="Shell.__indentLength"></a> +<h4>Shell.__indentLength</h4> +<b>__indentLength</b>(<i>line</i>) +<p> + Private method to determine the indentation length of the given line. +</p><dl> +<dt><i>line</i> (str)</dt> +<dd> +line to determine the indentation length for +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +indentation length +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +int +</dd> </dl><a NAME="Shell.__initialise" ID="Shell.__initialise"></a> <h4>Shell.__initialise</h4> <b>__initialise</b>(<i></i>)
--- a/QScintilla/Shell.py Mon Dec 18 18:09:39 2017 +0100 +++ b/QScintilla/Shell.py Tue Dec 19 19:46:23 2017 +0100 @@ -966,20 +966,35 @@ if self.__isCursorOnLastLine(): line, col = self.getCursorPosition() lastLine = self.text(line) + if lastLine.startswith(sys.ps1): + lastLine = lastLine[len(sys.ps1):] + col -= len(sys.ps1) + prompt = sys.ps1 + elif lastLine.startswith(sys.ps2): + lastLine = lastLine[len(sys.ps2):] + col -= len(sys.ps2) + prompt = sys.ps2 + else: + prompt = "" + if col < 0: + col = 0 + prompt = "" # Remove if text is selected if self.hasSelectedText(): lineFrom, indexFrom, lineTo, indexTo = self.getSelection() if self.text(lineFrom).startswith(sys.ps1): - if indexFrom < len(sys.ps1): - indexFrom = len(sys.ps1) + indexFrom -= len(sys.ps1) + indexTo -= len(sys.ps1) elif self.text(lineFrom).startswith(sys.ps2): - if indexFrom < len(sys.ps2): - indexFrom = len(sys.ps2) + indexFrom -= len(sys.ps2) + indexTo -= len(sys.ps2) + if indexFrom < 0: + indexFrom = 0 lastLine = lastLine[:indexFrom] + lastLine[indexTo:] col = indexFrom - self.setCursorPosition(line, 0) + self.setCursorPosition(line, len(prompt)) self.deleteLineRight() lines = QApplication.clipboard().text() @@ -1006,7 +1021,19 @@ @param historyIndex history index to be set @type int """ - for line in lines.splitlines(True): + lines = lines.splitlines(True) + if not lines: + return + + indentLen = self.__indentLength(lines[0]) + for line in lines: + if line.startswith(sys.ps1): + line = line[len(sys.ps1) + indentLen:] + elif line.startswith(sys.ps2): + line = line[len(sys.ps2) + indentLen:] + else: + line = line[indentLen:] + if line.endswith("\r\n"): fullline = True cmd = line[:-2] @@ -1020,16 +1047,27 @@ self.__insertTextAtEnd(line) if fullline: self.incrementalSearchActive = False - if cmd.startswith(sys.ps1): - cmd = cmd[len(sys.ps1):] - elif cmd.startswith(sys.ps2): - cmd = cmd[len(sys.ps2):] self.__executeCommand(cmd, historyIndex=historyIndex) if self.interruptCommandExecution: self.__executeCommand("") break + + def __indentLength(self, line): + """ + Private method to determine the indentation length of the given line. + @param line line to determine the indentation length for + @type str + @return indentation length + @rtype int + """ + if line.startswith(sys.ps1): + line = line[len(sys.ps1):] + # If line starts with sys.ps2 or neither don't manipulate the line. + indentLen = len(line) - len(line.lstrip()) + return indentLen + def __clearCurrentLine(self): """ Private method to clear the line containing the cursor.