From 6b8630ee8756c14228fa04198652c5db302a4630 Mon Sep 17 00:00:00 2001 From: Paul Nameless Date: Tue, 5 May 2020 13:12:42 +0800 Subject: [PATCH 1/2] Update keybindings and remove some useless code --- tg/controllers/__init__.py | 22 ++++++++++++++++------ tg/models/__init__.py | 14 -------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/tg/controllers/__init__.py b/tg/controllers/__init__.py index 114b385..cd71f60 100644 --- a/tg/controllers/__init__.py +++ b/tg/controllers/__init__.py @@ -54,15 +54,15 @@ class Controller: if self.model.prev_chat(): self.refresh_chats() elif keys == "J": - if self.model.jump_next_msg(): + if self.model.next_msg(10): self.refresh_msgs() elif keys == "K": - if self.model.jump_prev_msg(): + if self.model.prev_msg(10): self.refresh_msgs() - elif keys in ("j", "^B"): + elif keys in ("j", "^P"): if self.model.next_msg(repeat_factor): self.refresh_msgs() - elif keys in ("k", "^C"): + elif keys in ("k", "^N"): if self.model.prev_msg(repeat_factor): self.refresh_msgs() elif keys == "G": @@ -120,16 +120,26 @@ class Controller: self.view.msgs.resize(0.5) self.refresh_chats() - elif keys in ("j", "^B"): + elif keys in ("j", "^N"): is_changed = self.model.next_chat(repeat_factor) if is_changed: self.refresh_chats() - elif keys in ("k", "^C"): + elif keys in ("k", "^P"): is_changed = self.model.prev_chat(repeat_factor) if is_changed: self.refresh_chats() + elif keys in ("J",): + is_changed = self.model.next_chat(10) + if is_changed: + self.refresh_chats() + + elif keys in ("K",): + is_changed = self.model.prev_chat(10) + if is_changed: + self.refresh_chats() + elif keys == "gg": is_changed = self.model.first_chat() if is_changed: diff --git a/tg/models/__init__.py b/tg/models/__init__.py index 98c1e40..ddc2deb 100644 --- a/tg/models/__init__.py +++ b/tg/models/__init__.py @@ -65,14 +65,6 @@ class Model: chat_id = self.chats.chat_ids[self.current_chat] return self.msgs.prev_msg(chat_id, step) - def jump_next_msg(self): - chat_id = self.chats.chat_ids[self.current_chat] - return self.msgs.jump_next_msg(chat_id) - - def jump_prev_msg(self): - chat_id = self.chats.chat_ids[self.current_chat] - return self.msgs.jump_prev_msg(chat_id) - def get_chats(self, offset=0, limit=10): return self.chats.fetch_chats(offset=offset, limit=limit) @@ -189,12 +181,6 @@ class MsgModel: self.current_msgs[chat_id] = 0 return True - def jump_next_msg(self, chat_id): - return self.next_msg(chat_id, step=10) - - def jump_prev_msg(self, chat_id): - return self.prev_msg(chat_id, step=10) - def prev_msg(self, chat_id, step=1): new_idx = self.current_msgs[chat_id] + step if new_idx < len(self.msgs[chat_id]): From c70933c4b125deb5314f230604be78a9922450c9 Mon Sep 17 00:00:00 2001 From: Paul Nameless Date: Tue, 5 May 2020 13:17:56 +0800 Subject: [PATCH 2/2] Add enter to act as "l" and "a" to send msg --- tg/controllers/__init__.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tg/controllers/__init__.py b/tg/controllers/__init__.py index cd71f60..c723881 100644 --- a/tg/controllers/__init__.py +++ b/tg/controllers/__init__.py @@ -88,7 +88,7 @@ class Controller: elif keys == "I": # open vim or emacs to write long messages pass - elif keys == "i": + elif keys in ("i", "a"): # write new message msg = self.view.get_input() if msg: @@ -112,7 +112,7 @@ class Controller: log.info("Pressed keys: %s", keys) if keys == "q": return - elif keys in ("l", "^E"): + elif keys in ("l", "^J"): rc = self.handle_msgs() if rc == "QUIT": return @@ -121,28 +121,23 @@ class Controller: self.refresh_chats() elif keys in ("j", "^N"): - is_changed = self.model.next_chat(repeat_factor) - if is_changed: + if self.model.next_chat(repeat_factor): self.refresh_chats() elif keys in ("k", "^P"): - is_changed = self.model.prev_chat(repeat_factor) - if is_changed: + if self.model.prev_chat(repeat_factor): self.refresh_chats() elif keys in ("J",): - is_changed = self.model.next_chat(10) - if is_changed: + if self.model.next_chat(10): self.refresh_chats() elif keys in ("K",): - is_changed = self.model.prev_chat(10) - if is_changed: + if self.model.prev_chat(10): self.refresh_chats() elif keys == "gg": - is_changed = self.model.first_chat() - if is_changed: + if self.model.first_chat(): self.refresh_chats() def refresh_chats(self):