diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-03 21:02:55 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-03 21:34:12 +0200 |
commit | ccdaa1bea9291bdf035181245c6df044a41e8ede (patch) | |
tree | ee16315aa5a4a73173948c8b3a1ab20bf1f94890 /Libraries | |
parent | f7ef6c65b4ca843cf658e3a336dcdcd5755354cf (diff) | |
download | serenity-ccdaa1bea9291bdf035181245c6df044a41e8ede.zip |
LibWeb: Insert newlines at <br> and block boundaries in copied text :^)
To make the plain text we copy out from LibWeb look at least somewhat
like its original form, let's insert newlines at <br> elements and when
we exit a block-level element.
This is far from perfect, but seems to work pretty okay.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/PageView.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Libraries/LibWeb/PageView.cpp b/Libraries/LibWeb/PageView.cpp index 0bce94c408..84c24bc2b1 100644 --- a/Libraries/LibWeb/PageView.cpp +++ b/Libraries/LibWeb/PageView.cpp @@ -46,6 +46,7 @@ #include <LibWeb/Frame/EventHandler.h> #include <LibWeb/Frame/Frame.h> #include <LibWeb/Layout/LayoutDocument.h> +#include <LibWeb/Layout/LayoutBreak.h> #include <LibWeb/Layout/LayoutNode.h> #include <LibWeb/Layout/LayoutText.h> #include <LibWeb/Loader/ResourceLoader.h> @@ -141,6 +142,9 @@ String PageView::selected_text() const while (layout_node && layout_node != selection.end().layout_node) { if (is<LayoutText>(*layout_node)) builder.append(to<LayoutText>(*layout_node).text_for_rendering()); + else if (is<LayoutBreak>(*layout_node) || is<LayoutBlock>(*layout_node)) + builder.append('\n'); + layout_node = layout_node->next_in_pre_order(); } |