From fa4eeca0ac3330ba6fee226b315ca06652a7ea11 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sat, 28 Aug 2021 02:08:15 +0000 Subject: [PATCH] LibWeb: Properly handle newlines at the end of LineBoxes This always subtracted the glyph width of a space, despite isspace also accepting newlines and a few other characters. It now also uses AK/CharacterTypes.h. :^) --- Userland/Libraries/LibWeb/Layout/LineBox.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/LineBox.cpp b/Userland/Libraries/LibWeb/Layout/LineBox.cpp index 5f2a342dd9..894344fe5c 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBox.cpp @@ -4,12 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include #include #include -#include namespace Web::Layout { @@ -40,16 +40,20 @@ void LineBox::trim_trailing_whitespace() if (m_fragments.is_empty()) return; - auto last_text = m_fragments.last().text(); + auto& last_fragment = m_fragments.last(); + auto last_text = last_fragment.text(); if (last_text.is_null()) return; - auto& last_fragment = m_fragments.last(); - int space_width = last_fragment.layout_node().font().glyph_width(' '); - while (last_fragment.length() && isspace(last_text[last_fragment.length() - 1])) { + while (last_fragment.length()) { + auto last_character = last_text[last_fragment.length() - 1]; + if (!is_ascii_space(last_character)) + break; + + int last_character_width = last_fragment.layout_node().font().glyph_width(last_character); last_fragment.m_length -= 1; - last_fragment.set_width(last_fragment.width() - space_width); - m_width -= space_width; + last_fragment.set_width(last_fragment.width() - last_character_width); + m_width -= last_character_width; } }