From 3fb631b91caec163707858bd1d435015e6e6cb18 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 9 Jan 2020 23:06:41 +0000 Subject: Fix cut off full width glyphs in last column This resolves the issue with full width glyphs getting rendered in the last column. Since they need at least two glyphs, it is not possible to properly render them in the last column. Instead of rendering half of the glyph in the last column, with the other half cut off, an additional spacer is now inserted before the wide glyph. This means that the specific glyph in question is then three cells wide. Fixes #2385. --- alacritty/src/url.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/url.rs b/alacritty/src/url.rs index e510aa2b..b32a6812 100644 --- a/alacritty/src/url.rs +++ b/alacritty/src/url.rs @@ -42,7 +42,7 @@ impl Url { } pub fn end(&self) -> Point { - self.lines[self.lines.len() - 1].end.sub(self.num_cols, self.end_offset as usize) + self.lines[self.lines.len() - 1].end.sub(self.num_cols, self.end_offset as usize, false) } } @@ -73,11 +73,6 @@ impl Urls { // Update tracked URLs pub fn update(&mut self, num_cols: usize, cell: RenderableCell) { - // Ignore double-width spacers to prevent reset - if cell.flags.contains(Flags::WIDE_CHAR_SPACER) { - return; - } - // Convert cell to character let c = match cell.inner { RenderableCellContent::Chars(chars) => chars[0], @@ -85,20 +80,28 @@ impl Urls { }; let point: Point = cell.into(); - let mut end = point; + let end = point; // Reset URL when empty cells have been skipped - if point != Point::default() && Some(point.sub(num_cols, 1)) != self.last_point { + if point != Point::default() && Some(point.sub(num_cols, 1, false)) != self.last_point { self.reset(); } - // Extend by one cell for double-width characters - if cell.flags.contains(Flags::WIDE_CHAR) { - end.col += 1; - } - self.last_point = Some(end); + // Extend current state if a wide char spacer is encountered + if cell.flags.contains(Flags::WIDE_CHAR_SPACER) { + if let UrlLocation::Url(_, mut end_offset) = self.state { + if end_offset != 0 { + end_offset += 1; + } + + self.extend_url(point, end, cell.fg, end_offset); + } + + return; + } + // Advance parser let last_state = mem::replace(&mut self.state, self.locator.advance(c)); match (self.state, last_state) { -- cgit