From 9804f3d636a6c074a33d2e70ff8c0ee39b8f7ac9 Mon Sep 17 00:00:00 2001 From: Matthias Goerner <1239022+unhyperbolic@users.noreply.github.com> Date: Sun, 18 Jan 2026 11:45:47 +0100 Subject: [PATCH] SnapPy app adding multiline input: allowing the body of, e.g., a for loop, to have multiple lines. That is, we do not run code after adding the first line, only after adding an empty line. --- python/tkterminal.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/python/tkterminal.py b/python/tkterminal.py index 0f26a04c..349804d4 100644 --- a/python/tkterminal.py +++ b/python/tkterminal.py @@ -788,7 +788,8 @@ def interact_handle_input(self, cell, script=False): self._input_buffer = self.clean_code(cell) transformed_cell = self.IP.transform_cell(self._input_buffer) status, indent = self.IP.check_complete(transformed_cell) - self._current_indent = indent or '' + if indent: + self._current_indent = indent if status == 'incomplete': self.IP.more = True return @@ -805,7 +806,15 @@ def interact_handle_input(self, cell, script=False): insert_line = int(self.text.index(Tk_.INSERT).split('.')[0]) prompt_line = int(self.text.index('output_end').split('.')[0]) tail = self.text.get('%d.%d' % (insert_line, self._prompt_size), Tk_.END) - if not tail.strip(): + if tail.strip(): + run_cell = False + else: + lines = cell.split('\n') + if len(lines) <= 2: + run_cell = True + else: + run_cell = not lines[-2][self._prompt_size:].strip() + if run_cell: self.text.tag_delete('history') self._input_buffer = self._input_buffer.rstrip() + '\n' self.text.delete(Tk_.INSERT, Tk_.END)