Skip to content

Commit 14e3bf1

Browse files
zee-bitneiljp
authored andcommitted
bugfix: boxes/ui: Display mouse selection_hint for entire View.
This commit fixes 2 bugs related to displaying selection_hint on mouse_drag events. This migrates the mouse_event from MessageBox to the entire View so that the selection_hint is displayed even when the user tries to perform mouse_drag events outside of MessageBox i.e. anywhere in View. This also fixes selection_hint getting stuck in the footer if the mouse is dragged in the MessageView but released outside of it.
1 parent 0fd7595 commit 14e3bf1

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

zulipterminal/ui.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import random
22
import re
33
import time
4+
from sys import platform
45
from typing import Any, List, Optional
56

67
import urwid
@@ -39,6 +40,7 @@ def __init__(self, controller: Any) -> None:
3940
self.search_box = SearchBox(self.controller)
4041

4142
self.message_view: Any = None
43+
self.displaying_selection_hint = False
4244

4345
super().__init__(self.main_window())
4446

@@ -297,6 +299,26 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
297299
key = "end"
298300
return super().keypress(size, key)
299301

302+
def mouse_event(
303+
self, size: urwid_Box, event: str, button: int, col: int, row: int, focus: bool
304+
) -> bool:
305+
if event == "mouse drag":
306+
selection_key = "Fn + Alt" if platform == "darwin" else "Shift"
307+
self.model.controller.view.set_footer_text(
308+
[
309+
"Try pressing ",
310+
("footer_contrast", f" {selection_key} "),
311+
" and dragging to select text.",
312+
],
313+
"task:warning",
314+
)
315+
self.displaying_selection_hint = True
316+
elif event == "mouse release" and self.displaying_selection_hint:
317+
self.model.controller.view.set_footer_text()
318+
self.displaying_selection_hint = False
319+
320+
return super().mouse_event(size, event, button, col, row, focus)
321+
300322

301323
class Screen(urwid.raw_display.Screen):
302324
def write(self, data: Any) -> None:

zulipterminal/ui_tools/boxes.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import unicodedata
44
from collections import Counter, OrderedDict, defaultdict
55
from datetime import date, datetime, timedelta
6-
from sys import platform
76
from time import sleep, time
87
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple, Union
98
from urllib.parse import urljoin, urlparse
@@ -837,9 +836,6 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
837836
if recipient["id"] != self.model.user_id
838837
]
839838

840-
# mouse_event helper variable
841-
self.displaying_selection_hint = False
842-
843839
super().__init__(self.main_view())
844840

845841
def need_recipient_header(self) -> bool:
@@ -1575,20 +1571,6 @@ def mouse_event(
15751571
return True
15761572
self.keypress(size, primary_key_for_command("ENTER"))
15771573
return True
1578-
elif event == "mouse drag":
1579-
selection_key = "Fn + Alt" if platform == "darwin" else "Shift"
1580-
self.model.controller.view.set_footer_text(
1581-
[
1582-
"Try pressing ",
1583-
("footer_contrast", f" {selection_key} "),
1584-
" and dragging to select text.",
1585-
],
1586-
"task:warning",
1587-
)
1588-
self.displaying_selection_hint = True
1589-
elif event == "mouse release" and self.displaying_selection_hint:
1590-
self.model.controller.view.set_footer_text()
1591-
self.displaying_selection_hint = False
15921574

15931575
return super().mouse_event(size, event, button, col, row, focus)
15941576

0 commit comments

Comments
 (0)