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
base: master
Are you sure you want to change the base?
Cursor improvements for sentence field #149
Conversation
Hmm, the current behavior is intended to make something like this possible:
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). |
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 |
Does this work when there are multiple words bolded at the same time? |
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.mp4Barring this, everything works as expected |
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. |
make redefining easier by removing bolding
c78bf0c
to
2434d7d
Compare
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 |
vocabsieve/main.py
Outdated
|
||
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}") |
There was a problem hiding this comment.
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.
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. |
2 small commits to improve usability: