Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor improvements for sentence field #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

artjomsR
Copy link
Contributor

2 small commits to improve usability:

  • if no selection is made, define will pick up any word that is touching the cursor (i.e. if cursor is in the middle or on the edge of the word)
  • after the new word is defined, cursor position will be remembered after unbolding / bolding

@artjomsR artjomsR changed the title Feat/define without selection Cursor improvements for sentence field Mar 26, 2024
@1over137
Copy link
Contributor

Hmm, the current behavior is intended to make something like this possible:

  • You defined something using any method
  • You want to define it again, this time using shift-ctrl-D. The idea is that the current implementation would cause a lookup on the exact same word.

Would this change that?

Though, I think this would actually be the main method of lookup if I want to implement greedy phrase lookup (with a context and index of cursor position).

@artjomsR
Copy link
Contributor Author

You made realise there was an edge case when redefining the same word, but I've fixed that now in the latest commit. But yes, redefining is even easier now because the cursor stays in the same place

Desktop.2024.03.26.-.19.59.34.05.mp4

@1over137
Copy link
Contributor

Does this work when there are multiple words bolded at the same time?
Currently all words with the same lemma will be bolded, not just the selected.

@artjomsR
Copy link
Contributor Author

artjomsR commented Mar 26, 2024

It works, except I didn't account for multiple words being bolded and so the cursor is not shifted properly to account the two underscores on the right-hand side. I'll try to think of a good solution

Desktop.2024.03.26.-.22.16.39.03.mp4

Barring this, everything works as expected

@1over137
Copy link
Contributor

Rather than trying to compute offsets, I would just let it compute and remember the actual index of cursor from the beginning, skipping double underscores, and restore that after bolding occurs.

@artjomsR artjomsR force-pushed the feat/define_without_selection branch from c78bf0c to 2434d7d Compare March 27, 2024 14:08
@artjomsR
Copy link
Contributor Author

Ok I've tried that, and it would work for the most part. However, it would get complex very quickly when stripping punctuation and multiple lemmas are involved

So instead, I abandoned that and went for a simpler approach - set the cursor at the end of the bolded word. It's still not ideal when multiple lemmas are involved - it'll set the cursor to the last processed lemma. But I'd argue it's more of an edge case, and even then it's still an improvement over simply having the cursor at the beginning of the sentence

Desktop.2024.03.27.-.14.02.03.02.mp4


if word_start_position != word_end_position and (word_start_position <= cursor_position <= word_end_position):
selected = text_field.toPlainText()[word_start_position:word_end_position].replace('_', '')
logger.debug(f"Automatic selection of touched word: {selected} from text field {text_field}")
Copy link
Contributor

@1over137 1over137 Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really worth doing the cursor stuff on the two definition fields because their content is going to be overwritten so you can't assume the same text will be at the same position (or that the word will be present at all).

Maybe leave this loop unchanged, and add the handling of this only on sentence field after this loop.

@1over137
Copy link
Contributor

now that I think of it, a simpler approach is to use re.subn, and make use of the info about how many substitutions have actually been applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants