Skip to content

Commit

Permalink
Handling comments that target part of a line in the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
pauliyobo committed Dec 1, 2024
1 parent 9d68d71 commit 4eccb50
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions bookworm/annotation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,17 @@ def onCaretMoved(self, event):
evtdata["line_contains_highlight"] = True
break
for comment in NoteTaker(self.reader).get_for_page():
if comment.position in pos_range:
evtdata["comment"] = True
break
start_pos, end_pos = (comment.start_pos, comment.end_pos)
# If the comment has a selection, we check if the caret position is inside the selection. Otherwise, we check that the ocmment position is in the pos_range, typically the whole line.
condition = (start_pos <= position <= end_pos) if (start_pos, end_pos) != (None, None) else comment.position in pos_range
if condition:
# Previously comment would have the value True
# Now, since it is possible that two comments overlap, we set how many comments are present in the given position
# TODO: Understand whether htis is worth it, or if we should prevent comments from overlapping
if "comment" in evtdata:
evtdata["comment"] += 1
else:
evtdata["comment"] = 1
wx.CallAfter(self._process_caret_move, evtdata)

def _process_caret_move(self, evtdata):
Expand All @@ -252,8 +260,15 @@ def _process_caret_move(self, evtdata):
# Translators: spoken message indicating the presence of an annotation when the user navigates the text
to_speak.append(_("Line contains highlight"))
if "comment" in evtdata:
# Translators: spoken message indicating the presence of an annotation when the user navigates the text
to_speak.append(_("Has comment"))
# Translators: Text that appears when only a comment is present
single_comment_msg = _("Has comment")
# Translators: text that appears if multiple comments are present
multiple_comments_msg = _("Has {} comments")
comments = evtdata["comment"]
if comments == 1:
to_speak.append(single_comment_msg)
else:
to_speak.append(multiple_comments_msg.format(comments))
speech.announce(" ".join(to_speak), False)

def get_annotation(self, annotator_cls, *, foreword):
Expand Down

0 comments on commit 4eccb50

Please sign in to comment.