From 003cedde5cbb1424851a54e8a95eee4cdbc18cd0 Mon Sep 17 00:00:00 2001 From: Eugenio Parodi Date: Sun, 27 Feb 2022 21:17:54 +0000 Subject: [PATCH] TextEdit, added extra logic to handle erase at the end/beginning of the line --- TermTk/TTkWidgets/texedit.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/TermTk/TTkWidgets/texedit.py b/TermTk/TTkWidgets/texedit.py index ad9a812e..85e7eb0d 100644 --- a/TermTk/TTkWidgets/texedit.py +++ b/TermTk/TTkWidgets/texedit.py @@ -263,18 +263,26 @@ class _TTkTextEditView(TTkAbstractScrollView): else: cpx,cpy = self._cursorPos l = self._lines[cpy] - if cpx < len(l): + if cpx < len(l): # Erase next caracter on the same line self._lines[cpy] = l.substring(to=cpx) + l.substring(fr=cpx+1) + elif (cpy+1) 0: + if cpx > 0: # Erase the previous character cpx-=1 self._lines[cpy] = l.substring(to=cpx) + l.substring(fr=cpx+1) - self._setCursorPos(cpx,cpy) + elif cpy>0: # Beginning of the line, remove "\n" and merge with the previous line + cpx = len(self._lines[cpy-1]) + self._lines[cpy-1] += l + self._lines = self._lines[:cpy] + self._lines[cpy+1:] + self._setCursorPos(cpx,cpy-1) if evt.key == TTkK.Key_Enter: self._eraseSelection() cpx,cpy = self._cursorPos