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

TextViewer: make find result bold #11427

Merged
merged 4 commits into from Feb 3, 2024

Conversation

hius07
Copy link
Member

@hius07 hius07 commented Jan 31, 2024

1


This change is Reviewable

Comment on lines +1418 to 1420
-- @treturn table Text char list
-- @treturn table Search string char list
function util.stringSearch(txt, str, case_sensitive, start_pos)
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels a little odd that this function in util would return some of its internal stuff.
I know it costs nothing (even if the caller does not use and store them, they will soon be GC'ed), and it's a good optimisation for TextViewer so it doesn't have to re-do it again, but it still feels a little odd and ad-hoc.
(Alternatives that don't feel better: duplicate it with this extended return values in TextViewer. Or add a param return_charlists=true so it still looks plain as before when not provided.)

end
self.text = table.concat(charlist)
self:reinit()
self.text = text
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this strange double self.text = assignment is what makes it work multiple times, so might be worth a comment on the last line: -- restore original text.
Does it really work when doing multiple searches, when no match, when matching, when moving, when again no match, when matching some pattern overlapping a previous match ?
In no case we would re-use the self.charlist with the PTF_BOLD_START/END in it which would prevent a match of some pattern because they are there in the middle ?

(It also feels it would be better to make bold ALL matches, so one may not need to use Find next - but then, it is quite some different code, and you would need a util.stringSearchAll() :))

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it really work

Yes it works good.

@hius07
Copy link
Member Author

hius07 commented Jan 31, 2024

We could also make bold the selected text (not while selecting, but after copying) to see the copied result, if we get actual boundaries in

local selected_text = self._xtext:getSelectedWords(sel_start_idx, sel_end_idx, 50)

@poire-z
Copy link
Contributor

poire-z commented Jan 31, 2024

We could also make bold the selected text (not while selecting, but after copying) to see the copied result

Well, it's not really something cheap this rebuilding of charlist and rerendering - and it doesn't really feel necessary (people who copied may soon go do other things with it).

Also, I get there is no feedback of what has been selected/copied, but making it bold in the original text feels like no other app does that (they may do some kind of reverse video/color like our text selection in a book).
(No idea how complex it would be to just gather rectangle coordinates of the selected stuff, and do some kind of bb:invertRect() at :paintTo() time.)

Also, I think this kind of feedback has been more requested for in the dictlookup result - but there, half of our results could be from html dicts and use htmlboxwidget, where it would not happen, so we would get this kind of highlighting only in half of cases, which makes it too inconsistent, and it feels it's better to just not have it :)

Copy link
Contributor

@poire-z poire-z left a comment

Choose a reason for hiding this comment

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

Not super happy with the odd extra returned values of util.stringSearch(), but it's so simple that I can ignore my feeling :) (maybe add a comment just before the return -- TextViewer:findCallback() will benefit from getting these extra charlists we have just computed or something.

The rest of the magic is quite localized in TextViewer, so fine with me.

@Frenzie Frenzie added this to the 2024.02 milestone Feb 2, 2024
@hius07 hius07 merged commit 962477e into koreader:master Feb 3, 2024
3 checks passed
@hius07 hius07 deleted the textviewer-find-result-bold branch February 3, 2024 08:32
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

3 participants