From fd4b5c11694310197a10c5ad9e351e75d0afc17d Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sat, 16 Feb 2019 10:57:09 +0100 Subject: [PATCH] Print-wrap current line rather than the entire field Also: Avoid duplicate wraps, retain cursor position, and preserve undo history. --- aqt/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/aqt/main.py b/aqt/main.py index 4c0b38f4d..279e9f1d2 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -1209,7 +1209,16 @@ will be lost. Continue?""")) return aqt.dialogs._dialogs['Browser'][1].card.__dict__ def onDebugPrint(self, frm): - frm.text.setPlainText("pp(%s)" % frm.text.toPlainText()) + cursor = frm.text.textCursor() + position = cursor.position() + cursor.select(QTextCursor.LineUnderCursor) + line = cursor.selectedText() + pfx, sfx = "pp(", ")" + if not line.startswith(pfx): + line = "{}{}{}".format(pfx, line, sfx) + cursor.insertText(line) + cursor.setPosition(position + len(pfx)) + frm.text.setTextCursor(cursor) self.onDebugRet(frm) def onDebugRet(self, frm):