aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
Diffstat (limited to 'slack')
-rw-r--r--slack/commands.py13
-rw-r--r--slack/register.py19
-rw-r--r--slack/slack_conversation.py14
3 files changed, 32 insertions, 14 deletions
diff --git a/slack/commands.py b/slack/commands.py
index 6e84536..6f06146 100644
--- a/slack/commands.py
+++ b/slack/commands.py
@@ -304,7 +304,7 @@ def completion_irc_channels_cb(
def complete_input(conversation: SlackConversation, query: str):
- if conversation.completion_context:
+ if conversation.completion_context == "ACTIVE_COMPLETION":
input_value = weechat.buffer_get_string(conversation.buffer_pointer, "input")
input_pos = weechat.buffer_get_integer(conversation.buffer_pointer, "input_pos")
result = conversation.completion_values[conversation.completion_index]
@@ -319,15 +319,18 @@ def complete_input(conversation: SlackConversation, query: str):
async def complete_user_next(conversation: SlackConversation, query: str):
- if not conversation.completion_context:
- conversation.completion_context = 1
+ if conversation.completion_context == "NO_COMPLETION":
+ conversation.completion_context = "PENDING_COMPLETION"
search = await conversation.workspace.api.fetch_users_search(query)
+ if conversation.completion_context != "PENDING_COMPLETION":
+ return
+ conversation.completion_context = "ACTIVE_COMPLETION"
conversation.completion_values = [
name_from_user_info_without_spaces(conversation.workspace, user)
for user in search["results"]
]
conversation.completion_index = 0
- else:
+ elif conversation.completion_context == "ACTIVE_COMPLETION":
conversation.completion_index += 1
if conversation.completion_index >= len(conversation.completion_values):
conversation.completion_index = 0
@@ -336,7 +339,7 @@ async def complete_user_next(conversation: SlackConversation, query: str):
def complete_previous(conversation: SlackConversation, query: str):
- if conversation.completion_context:
+ if conversation.completion_context == "ACTIVE_COMPLETION":
conversation.completion_index -= 1
if conversation.completion_index < 0:
conversation.completion_index = len(conversation.completion_values) - 1
diff --git a/slack/register.py b/slack/register.py
index fd38956..2994e7f 100644
--- a/slack/register.py
+++ b/slack/register.py
@@ -31,13 +31,21 @@ def signal_buffer_switch_cb(data: str, signal: str, buffer_pointer: str) -> int:
def input_text_changed_cb(data: str, signal: str, buffer_pointer: str) -> int:
- conversation = get_conversation_from_buffer_pointer(buffer_pointer)
- if conversation:
- if not conversation.is_completing and conversation.completion_context:
- conversation.completion_context = 0
+ reset_completion_context_on_input(buffer_pointer)
+ return weechat.WEECHAT_RC_OK
+
+
+def input_text_cursor_moved_cb(data: str, signal: str, buffer_pointer: str) -> int:
+ reset_completion_context_on_input(buffer_pointer)
return weechat.WEECHAT_RC_OK
+def reset_completion_context_on_input(buffer_pointer: str):
+ conversation = get_conversation_from_buffer_pointer(buffer_pointer)
+ if conversation and conversation.completion_context != "IN_PROGRESS_COMPLETION":
+ conversation.completion_context = "NO_COMPLETION"
+
+
def modifier_input_text_display_with_cursor_cb(
data: str, modifier: str, buffer_pointer: str, string: str
) -> str:
@@ -111,6 +119,9 @@ def register():
weechat.hook_signal(
"input_text_changed", get_callback_name(input_text_changed_cb), ""
)
+ weechat.hook_signal(
+ "input_text_cursor_moved", get_callback_name(input_text_cursor_moved_cb), ""
+ )
weechat.hook_modifier(
"input_text_display_with_cursor",
get_callback_name(modifier_input_text_display_with_cursor_cb),
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index bd727c4..d078ead 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -2,7 +2,7 @@ from __future__ import annotations
import time
from contextlib import contextmanager
-from typing import TYPE_CHECKING, List, Optional
+from typing import TYPE_CHECKING, List, Literal, Optional, Union
import weechat
@@ -37,8 +37,12 @@ class SlackConversation:
self.history_filled = False
self.history_pending = False
- self.is_completing = False
- self.completion_context = 0
+ self.completion_context: Union[
+ Literal["NO_COMPLETION"],
+ Literal["PENDING_COMPLETION"],
+ Literal["ACTIVE_COMPLETION"],
+ Literal["IN_PROGRESS_COMPLETION"],
+ ] = "NO_COMPLETION"
self.completion_values: List[str] = []
self.completion_index = 0
@@ -58,11 +62,11 @@ class SlackConversation:
@contextmanager
def completing(self):
- self.is_completing = True
+ self.completion_context = "IN_PROGRESS_COMPLETION"
try:
yield
finally:
- self.is_completing = False
+ self.completion_context = "ACTIVE_COMPLETION"
async def init(self):
with self.loading():