Skip to content

Commit

Permalink
bugfix: boxes/ui: Display mouse selection_hint for entire View.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zee-bit authored and neiljp committed Jul 18, 2021
1 parent 0fd7595 commit 14e3bf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
22 changes: 22 additions & 0 deletions zulipterminal/ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
import re
import time
from sys import platform
from typing import Any, List, Optional

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

self.message_view: Any = None
self.displaying_selection_hint = False

super().__init__(self.main_window())

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

def mouse_event(
self, size: urwid_Box, event: str, button: int, col: int, row: int, focus: bool
) -> bool:
if event == "mouse drag":
selection_key = "Fn + Alt" if platform == "darwin" else "Shift"
self.model.controller.view.set_footer_text(
[
"Try pressing ",
("footer_contrast", f" {selection_key} "),
" and dragging to select text.",
],
"task:warning",
)
self.displaying_selection_hint = True
elif event == "mouse release" and self.displaying_selection_hint:
self.model.controller.view.set_footer_text()
self.displaying_selection_hint = False

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


class Screen(urwid.raw_display.Screen):
def write(self, data: Any) -> None:
Expand Down
18 changes: 0 additions & 18 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import unicodedata
from collections import Counter, OrderedDict, defaultdict
from datetime import date, datetime, timedelta
from sys import platform
from time import sleep, time
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple, Union
from urllib.parse import urljoin, urlparse
Expand Down Expand Up @@ -837,9 +836,6 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
if recipient["id"] != self.model.user_id
]

# mouse_event helper variable
self.displaying_selection_hint = False

super().__init__(self.main_view())

def need_recipient_header(self) -> bool:
Expand Down Expand Up @@ -1575,20 +1571,6 @@ def mouse_event(
return True
self.keypress(size, primary_key_for_command("ENTER"))
return True
elif event == "mouse drag":
selection_key = "Fn + Alt" if platform == "darwin" else "Shift"
self.model.controller.view.set_footer_text(
[
"Try pressing ",
("footer_contrast", f" {selection_key} "),
" and dragging to select text.",
],
"task:warning",
)
self.displaying_selection_hint = True
elif event == "mouse release" and self.displaying_selection_hint:
self.model.controller.view.set_footer_text()
self.displaying_selection_hint = False

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

Expand Down

0 comments on commit 14e3bf1

Please sign in to comment.