From 1ca7486dc6b8d4a3d23c65c64f7512df012e7b92 Mon Sep 17 00:00:00 2001 From: Moosems <95927277+Moosems@users.noreply.github.com> Date: Fri, 18 Oct 2024 05:33:35 -0600 Subject: [PATCH] Check that the file has a character to reference --- porcupine/plugins/trailing_newline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/porcupine/plugins/trailing_newline.py b/porcupine/plugins/trailing_newline.py index bdbc1103d..da9509738 100644 --- a/porcupine/plugins/trailing_newline.py +++ b/porcupine/plugins/trailing_newline.py @@ -9,7 +9,8 @@ def on_save(event: tkinter.Event[tabs.FileTab]) -> None: if event.widget.settings.get("insert_final_newline", bool): textwidget = event.widget.textwidget - if textwidget.get("end - 2 chars", "end - 1 char") != "\n": + char = textwidget.get("end - 2 chars", "end - 1 char") + if char and char != "\n": # doesn't end with a \n yet, be sure not to annoyingly move the # cursor like IDLE does cursor = textwidget.index("insert")