Added block comment/uncomment feature to CodeEditor.

This commit is contained in:
Jeremy Mack Wright 2018-12-24 17:46:50 -05:00
parent e8cf3241de
commit 70836f43d2

View File

@ -224,6 +224,30 @@ class CodeEditor(QPlainTextEdit):
if currBlock.text().left(1) == "\t": if currBlock.text().left(1) == "\t":
cur.deleteChar() cur.deleteChar()
currBlock=currBlock.next() currBlock=currBlock.next()
# Allow commenting and uncommenting of blocks of code
if event.key() == Qt.Key_Slash and event.modifiers() == Qt.ControlModifier:
customKey = True
selStart = self.textCursor().selectionStart()
selEnd = self.textCursor().selectionEnd()
cur = self.textCursor()
endBlock = self.document().findBlock(selEnd)
currBlock = self.document().findBlock(selStart)
while currBlock.position() <= endBlock.position():
cur.setPosition(currBlock.position())
if currBlock.text()[0] == "#":
cur.deleteChar()
# Make sure we remove extra spaces
while currBlock.text()[0] == " ":
cur.deleteChar()
else:
cur.insertText("# ")
currBlock = currBlock.next()
if not customKey: if not customKey:
QPlainTextEdit.keyPressEvent(self, event) QPlainTextEdit.keyPressEvent(self, event)