1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:48:14 +00:00

LibWeb: Calculate selection based on glyph centers

Previously you had to drag all the way to the end of a glyph to select
it; now you just need to drag past the center.  Also fixes #2959.
This commit is contained in:
Rewi Haar 2020-08-26 11:31:11 +12:00 committed by Andreas Kling
parent dd83f6a266
commit 521e730df1
2 changed files with 10 additions and 7 deletions

View file

@ -26,12 +26,12 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/LayoutBreak.h>
#include <LibWeb/Layout/LayoutDocument.h>
#include <LibWeb/Layout/LayoutText.h>
#include <LibWeb/Layout/LayoutWidget.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/InProcessWebView.h>
namespace Web {
@ -221,7 +221,7 @@ String Frame::selected_text() const
if (selection.start().layout_node == selection.end().layout_node) {
if (!is<LayoutText>(*selection.start().layout_node))
return "";
return downcast<LayoutText>(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node + 1);
return downcast<LayoutText>(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node);
}
// Start node
@ -246,7 +246,7 @@ String Frame::selected_text() const
ASSERT(layout_node == selection.end().layout_node);
if (is<LayoutText>(*layout_node)) {
auto& text = downcast<LayoutText>(*layout_node).text_for_rendering();
builder.append(text.substring(0, selection.end().index_in_node + 1));
builder.append(text.substring(0, selection.end().index_in_node));
}
return builder.to_string();