Dictionary, footnotes: highlight the selected text#12948
Conversation
poire-z
left a comment
There was a problem hiding this comment.
Lots of stuff at the bottom of TextBoxWidget.lua, that looks like it's just my stuff mostly unchanged and just moved around - hard to get back into all that, so trusting you on this logic.
| -- If display_highlight is true then highlight will be displayed. | ||
| -- If false then highlight will work as it did originally: no highlight will be displayed, and the | ||
| -- highlight will be updated only on hold release (so hold time might be incorrect). |
There was a problem hiding this comment.
You need to be clearer here with "highlight" and "text selection".
| -- If display_highlight is true then highlight will be displayed. | |
| -- If false then highlight will work as it did originally: no highlight will be displayed, and the | |
| -- highlight will be updated only on hold release (so hold time might be incorrect). | |
| -- If highlight_text_selection is true then text selection will be highlighted. | |
| -- If false then text selection will work as it did originally: no highlighting, and the | |
| -- text selection will be updated only on hold release (so hold time might be incorrect). |
Not sure I understand the second sentence: do we still get highlighting on hold release ? If not, what is updated on hold release ? And why hold time might be incorrect.
There was a problem hiding this comment.
Hold time works incorrectly in the original version (and currently when the highlight display is off) because it is not reset when you change the selection, so for example if you select an entire line slowly (>3s) then Wikipedia comes up instead of the expected dictionary.
I can easily fix this to work correctly regardless of the highlight display. What do you think?
There was a problem hiding this comment.
If it's indeed easy to fix I don't see why not.
There was a problem hiding this comment.
Oh, indeed. Yes, if you can, please fix it :)
There was a problem hiding this comment.
Done. It even made the code clearer. :)
| if start_line_num < 1 or end_line_num > #self.vertical_string_list then | ||
| return nil, nil, nil, nil |
There was a problem hiding this comment.
(I don't remember how all this works when we start or end text selection in a margin - and if you changed anything to this behaviour. I rarely do text selection in these text/htmlbox widgets, but in Reader, I often end them in the right or botto margin, so some people may be used to do it like me.)
There was a problem hiding this comment.
Yes, it works better in Reader. I will try to match its behavior.
| for _, xglyph in ipairs(line.xglyphs) do | ||
| if xglyph.text_index >= text_start_idx and (xglyph.text_index + xglyph.cluster_len) <= text_end_idx and (not xglyph.no_drawing) then | ||
| if draw_line then | ||
| if xglyph.x0 < line_x0 then line_x0 = xglyph.x0 end | ||
| if xglyph.x1 > line_x1 then line_x1 = xglyph.x1 end | ||
| else | ||
| draw_line = true | ||
| line_x0 = xglyph.x0 | ||
| line_x1 = xglyph.x1 | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
I think all this is new code - and I'm not keen on digging into that :) so trusting you.
I also don't know how this behave with BiDi text, and our text selection with fingers, and the resulting selected text in logical indices order - but I guess it's not impossible we should have multiple rectangles on a same line - your code would logically only emit one rectangle per line.
(Trying to see how this works in an Arabic with English bits EPUB, I don't get such multiple rectangles, so it's possible I screwed that recently...)
Anyway, just mentionning that; if the text selection was already crappy on BiDi text, let the highlighting be it too.
There was a problem hiding this comment.
Selecting within a single Arabic line does not work correctly. It is caused by koptinterface:getTextFromBoxes, I will fix that. But otherwise I have no idea how exactly it should behave. :)
There was a problem hiding this comment.
I did not get notification for the replies. :(
Yeah, this is definitely problematic. I will have to change the drawing from per line rectangle to per word rectangles.
|
Can you share some screenshots/videos of how these highlights look ? Also in case you didn't see it, CI complained with: |
|
I made a new commit that makes selection behave very close to Reader. But for right-to-left text I could not achieve the same behavior when holding+panning after the end of the line. In TextBoxWidget that selects the visually last word for RTL text, but in HtmlBoxWidget it selects the entire line.
Also I just noticed poire-z's comment about the BiDi selection, so to that will require more changes. |
|
|
||
| local text_boxes = koptinterface:getTextFromBoxes(self.page_boxes, self.hold_start_pos, self.hold_end_pos) | ||
| local changed = not HtmlBoxWidget:areTextBoxesEqual(self.highlight_rects, self.highlight_text, text_boxes.boxes, text_boxes.text) | ||
| local text, rects = HtmlBoxWidget:getSelectedText(self.page_boxes, self.hold_start_pos, self.hold_end_pos) |
There was a problem hiding this comment.
If you are not using self in these utilities functions, it's best to not document/expose them as method with the :, and this HtmlBoxWidget:getSelectedText() looking non-classic :)
You can either:
- make them module local function if you guess we'll never have to use them from elsewhere
- make the class function with a
.instead of the:, so you would use hereHtmlBoxWidget.getSelectedText()(which would read more classic and we would know from reading its a class function and not a method).
|
First check how text selection currently work with RTL and BiDi: if it's already messy, let it be messy, no need to make the drawing better if the text selection does not correspond to what's drawn. |
|
Okay, I will do that. I will check how BiDi text behaves and whether the drawing needs per word rects or not. |
|
I don't think darkening is good idea, IMHO invert is the only option that should not mess too much with contrast and work in all cases, no matter the text / background color. |
|
Not sure what's the status of this PR is (no time to reread/review). |
|
I think this PR is ready for merging, but if needed then I can do another PR for getSelectedWordIndices tomorrow. |
|
I'd rather just merge this one. Could you rebase it on master? |
|
|
||
| -- If highlight_text_selection is true then text selection will be highlighted. | ||
| -- If false then text selection will work as it did originally: no highlighting, and the | ||
| -- text selection will be updated only on hold release (so hold time might be incorrect). |
There was a problem hiding this comment.
Is (so hold time might be incorrect) still valid ? (Thought you had fixed something related while we discussed it.)
and the text selection will be updated only on hold release reads odd: on hold release, there is nothing different than when highlight_text_selection = true, we just don't highlight it, and in both cases, we update text_selection as we pan - and when we release, we return the last update of text_selection, isn't it?
Both here and in textboxwidget.lua.
There was a problem hiding this comment.
Nice catch. I forgot to update the comments.
| self.highlight_clear_and_redraw_function = function () | ||
| self.highlight_clear_and_redraw_function = nil |
There was a problem hiding this comment.
There is a little convention (not sure it's always followed) for these kind of scheduled function, we name them ending with _action, so possibly here self.highlight_clear_and_redraw_action.
| end | ||
|
|
||
| x = x + width | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return rects |
There was a problem hiding this comment.
(Not a fan of these random blank lines in these 4 functions where it does not really separate bits of work.)
There was a problem hiding this comment.
I reduced the number of blank lines in the new code.
| function TextBoxWidget:getXtextHighlightIndices(start_x, start_y, end_x, end_y) | ||
| -- With xtext and fribidi, words may not be laid out in logical order, | ||
| -- so the left of a visual word may be its end in logical order, | ||
| -- and the right its start. | ||
| -- So, just find out charpos (text indice) of both points and | ||
| -- find word edges in the logical order text/charlist. |
There was a problem hiding this comment.
No specific RTL/mixed BiDi stuff needed in textboxwidget.lua (unlike what you added in htmlboxwidget) ? It's messy, or it just all works fine because xtext does the right thing?
(When non-xtext, I guess we don't care as RTL/BiDi is not supported, that's why we introduced xtext.)
There was a problem hiding this comment.
With the BiDi text I tried the selection seemed to work correctly with xtext, so I did not add the code that I added to HtmlBoxWidget to prevent joining word rects.
When selecting text in the dictionary (including Wikipedia) or the pop-up footnotes highlight the selected text using an inverting rectangle. After closing the opened dictionary remove the highlight after a short delay just like in the reader.
f01a4b7 to
5aa280c
Compare
|
I made the requested changes, rebased it on master, and set base to that xtext getSelectedWordIndices change. |
|
I guess it's probably not related but I seem to get this when I try to test it: Edit: also an issue on master. That's strange, I wonder when that was introduced. O.o |
| end | ||
|
|
There was a problem hiding this comment.
Bunch of random blank lines around here and the previous local functions - and in HtmlBoxWidget:setPageNumber() and here and there. In a large functions or loops doing multiple things in steps, it's fine to separate the steps - in little ones, it's just useless and makes it bigger than it could be.
(And think about people with small computer screens reviewing :))
There was a problem hiding this comment.
Otherwise, fine with this PR.
There was a problem hiding this comment.
Okay, I removed even more blanks lines.
Never mind, I still had a purposefully broken gestures.lua from #13009 (comment) |
|
Little bug witnessed: |
When selecting text in the dictionary (including Wikipedia) or the pop-up footnotes highlight the selected text using an inverting rectangle. After closing the opened dictionary remove the highlight after a short delay just like in the reader. Depends on koreader/koreader-base#2013




When selecting text in the dictionary (including Wikipedia) or the pop-up footnotes highlight the selected text using an inverting rectangle. After closing the opened dictionary remove the highlight after a short delay just like in the reader.
Depends on koreader/koreader-base#2013
This change is