From a8dc7fb16e1978db0def762422b2cebc7ddfbd9b Mon Sep 17 00:00:00 2001 From: LeonSnajdr <94352142+LeonSnajdr@users.noreply.github.com> Date: Wed, 19 Apr 2023 10:19:50 +0200 Subject: [PATCH 1/2] Add Cmd+a and deletion of selected text --- src/TerminalScreen.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/TerminalScreen.py b/src/TerminalScreen.py index 92cd795..3d961fc 100644 --- a/src/TerminalScreen.py +++ b/src/TerminalScreen.py @@ -353,6 +353,8 @@ def bind_keys(self): self.TerminalScreen.bind("", self.do_middleClickRelease) self.TerminalScreen.bind("", self.do_keyTab) self.TerminalScreen.bind("", self.do_keyHome) + self.TerminalScreen.bind("", self.do_selectAll) + self.TerminalScreen.bind("", self.do_selectAll) self.TerminalScreen.unbind("") def unbind_keys(self): @@ -369,6 +371,8 @@ def unbind_keys(self): self.TerminalScreen.bind("", lambda event: "break") self.TerminalScreen.bind("", lambda event: "break") self.TerminalScreen.bind("", lambda event: "break") + self.TerminalScreen.bind("", lambda event: "break") + self.TerminalScreen.bind("", lambda event: "break") self.TerminalScreen.bind("", lambda event: "break") def rollWheel(self, event): @@ -636,6 +640,16 @@ def do_keyTab(self, *args): self.stdout.write(return_cmd, end='') return "break" + + def do_selectAll(self, *args): + """ Select typed text """ + + endIndex = self.TerminalScreen.index("end-1c") + firstIndex = str(endIndex.split(".")[0]) + "." + str(len(self.get_last_basename())) + + self.TerminalScreen.tag_add("sel", firstIndex, endIndex) + + return "break" def do_leftClickRelease(self, *args): @@ -758,8 +772,14 @@ def do_keyReturn(self, *args): def do_keyBackspace(self, *args): """ Delete a character until the basename """ - index = self.TerminalScreen.index("insert-1c") + if self.TerminalScreen.tag_ranges("sel"): + firstSelectedIndex = self.TerminalScreen.index("sel.first").split(".")[1] + if int(firstSelectedIndex)>= len(self.get_last_basename()): + self.TerminalScreen.delete("sel.first", "sel.last") + return "break" + index = self.TerminalScreen.index("insert-1c") + if int(str(index).split('.')[1]) >= len(self.get_last_basename()): self.TerminalScreen.delete(index) @@ -846,4 +866,4 @@ def run_command(self, cmd): while self.terminalThread: pass self.stdout.write(cmd, end='') - self.do_keyReturn() \ No newline at end of file + self.do_keyReturn() From 84bccebc904e2ea095459d6c66d31cf6c9bfe3d1 Mon Sep 17 00:00:00 2001 From: LeonSnajdr <94352142+LeonSnajdr@users.noreply.github.com> Date: Wed, 19 Apr 2023 10:28:29 +0200 Subject: [PATCH 2/2] Fix code style --- src/TerminalScreen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TerminalScreen.py b/src/TerminalScreen.py index 3d961fc..a2cb014 100644 --- a/src/TerminalScreen.py +++ b/src/TerminalScreen.py @@ -774,7 +774,7 @@ def do_keyBackspace(self, *args): if self.TerminalScreen.tag_ranges("sel"): firstSelectedIndex = self.TerminalScreen.index("sel.first").split(".")[1] - if int(firstSelectedIndex)>= len(self.get_last_basename()): + if int(firstSelectedIndex) >= len(self.get_last_basename()): self.TerminalScreen.delete("sel.first", "sel.last") return "break"