--- a/eric6/QScintilla/Editor.py Wed Apr 14 18:10:51 2021 +0200 +++ b/eric6/QScintilla/Editor.py Wed Apr 14 19:38:19 2021 +0200 @@ -3893,8 +3893,9 @@ if Preferences.getEditor("CommentColumn0"): self.insertAt(self.lexer_.commentStr(), line, 0) else: - self.insertAt(self.lexer_.commentStr(), line, - self.indentation(line)) + lineText = self.text(line) + pos = len(lineText.replace(lineText.lstrip(" \t"), "")) + self.insertAt(self.lexer_.commentStr(), line, pos) self.endUndoAction() def uncommentLine(self): @@ -3917,8 +3918,9 @@ if Preferences.getEditor("CommentColumn0"): self.setSelection(line, 0, line, len(commentStr)) else: - self.setSelection(line, self.indentation(line), - line, self.indentation(line) + len(commentStr)) + lineText = self.text(line) + pos = len(lineText.replace(lineText.lstrip(" \t"), "")) + self.setSelection(line, pos, line, pos + len(commentStr)) self.removeSelectedText() self.endUndoAction() @@ -3944,7 +3946,9 @@ if Preferences.getEditor("CommentColumn0"): self.insertAt(commentStr, line, 0) else: - self.insertAt(commentStr, line, self.indentation(line)) + lineText = self.text(line) + pos = len(lineText.replace(lineText.lstrip(" \t"), "")) + self.insertAt(commentStr, line, pos) # change the selection accordingly self.setSelection(lineFrom, 0, endLine + 1, 0) @@ -3977,10 +3981,9 @@ if Preferences.getEditor("CommentColumn0"): self.setSelection(line, 0, line, len(commentStr)) else: - self.setSelection(line, - self.indentation(line), - line, - self.indentation(line) + len(commentStr)) + lineText = self.text(line) + pos = len(lineText.replace(lineText.lstrip(" \t"), "")) + self.setSelection(line, pos, line, pos + len(commentStr)) self.removeSelectedText() # adjust selection start