From d29c30b137d0759baa7cb2facb3a76626cc18c67 Mon Sep 17 00:00:00 2001 From: Silas Kraume Date: Mon, 29 Jan 2024 15:38:14 +0100 Subject: [PATCH] added back tab functionality --- cat_win/util/editor.py | 18 ++++++++++++++++++ cat_win/util/editorhelper.py | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cat_win/util/editor.py b/cat_win/util/editor.py index a41eda7b..fb53277e 100644 --- a/cat_win/util/editor.py +++ b/cat_win/util/editor.py @@ -343,6 +343,24 @@ def _scroll_key_home(self) -> None: self.wpos.row = 0 self.wpos.col = 0 + def _key_btab(self, _) -> str: + c_row = self.window_content[self.cpos.row] + if c_row[:1] == '\t': + self.window_content[self.cpos.row] = c_row[1:] + self.cpos.col = max(self.cpos.col-1, 0) + return '\t' + if c_row[:4] == ' ': + self.window_content[self.cpos.row] = c_row[4:] + self.cpos.col = max(self.cpos.col-4, 0) + return ' ' + return None + + def _key_btab_reverse(self, tab) -> str: + c_row = self.window_content[self.cpos.row] + self.window_content[self.cpos.row] = tab + c_row + self.cpos.col += len(tab) + return tab + def _key_string(self, wchars) -> str: """ tries to append (a) char(s) to the screen. diff --git a/cat_win/util/editorhelper.py b/cat_win/util/editorhelper.py index 45a0a5e2..833db201 100644 --- a/cat_win/util/editorhelper.py +++ b/cat_win/util/editorhelper.py @@ -131,6 +131,9 @@ # shift - pos/home b'KEY_SHOME' : b'_scroll_key_home', # windows & xterm + # shift + tab + b'KEY_BTAB' : b'_key_btab', # windows & xterm + # default alnum key b'_key_string' : b'_key_string', # history @@ -152,7 +155,8 @@ b'_key_dl' : b'_key_string', b'_key_backspace' : b'_key_string', b'_key_ctl_backspace': b'_key_string', - b'_key_string' : b'_key_backspace', + b'_key_string' : b'_key_backspace', + b'_key_btab' : b'_key_btab_reverse', } # defines the counter action if the file has the same amount of lines REVERSE_ACTION_SIZE_CHANGE = {