Skip to content

Commit

Permalink
Added support for comments targeting selected text
Browse files Browse the repository at this point in the history
  • Loading branch information
pauliyobo committed Dec 1, 2024
1 parent 32a1338 commit 9d68d71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bookworm/annotation/annotation_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,11 @@ class CommentsDialog(AnnotationWithContentDialog):
def go_to_item(self, item):
super().go_to_item(item)
self.service.view.set_insertion_point(item.position)

start_pos, end_pos = (item.start_pos, item.end_pos)
if (start_pos, end_pos) != (None, None):
# We have a selection, let's select the text
self.service.view.contentTextCtrl.SetSelection(start_pos, end_pos)


class QuotesDialog(AnnotationWithContentDialog):
def go_to_item(self, item):
Expand Down
7 changes: 6 additions & 1 deletion bookworm/annotation/annotation_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def onAddNamedBookmark(self, event):
def onAddNote(self, event):
_with_tags = wx.GetKeyState(wx.WXK_SHIFT)
insertionPoint = self.view.contentTextCtrl.GetInsertionPoint()
start_pos, end_pos = self.view.contentTextCtrl.GetSelection()
# if start_pos and end_pos are equal, there is no selection
# see: https://docs.wxpython.org/wx.TextEntry.html#wx.TextEntry.GetSelection
if start_pos == end_pos:
start_pos, end_pos = (None, None)
comment_text = self.view.get_text_from_user(
# Translators: the title of a dialog to add a comment
_("New Comment"),
Expand All @@ -213,7 +218,7 @@ def onAddNote(self, event):
if not comment_text:
return
note = NoteTaker(self.reader).create(
title="", content=comment_text, position=insertionPoint
title="", content=comment_text, position=insertionPoint, start_pos=start_pos, end_pos=end_pos
)
self.service.style_comment(self.view, insertionPoint)
if _with_tags:
Expand Down

0 comments on commit 9d68d71

Please sign in to comment.