From afada84f52bba2634617f3d6aa4979a9653e49b1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 31 Aug 2022 08:01:52 +0530 Subject: [PATCH] Cleanup previous PR Use wcswidth() for line width calculation. Works with emoji and ignores escape codes automatically. Add changelog entry. --- docs/changelog.rst | 2 ++ kittens/hints/main.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index e831433a6..939f970ad 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -44,6 +44,8 @@ Detailed list of changes - macOS: Fix regression in 0.26.0 that caused asking the user for a line of input such as for :ac:`set_tab_title` to not work (:iss:`5447`) +- hints kitten: hyperlink matching: Fix hints occasionally matching text on subsequent line as part of hyperlink (:pull:`5450`) + 0.26.1 [2022-08-30] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 42a2568b3..125a40145 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -16,7 +16,7 @@ from typing import ( from kitty.cli import parse_args from kitty.cli_stub import HintsCLIOptions from kitty.constants import website_url -from kitty.fast_data_types import get_options, set_clipboard_string +from kitty.fast_data_types import get_options, set_clipboard_string, wcswidth from kitty.key_encoding import KeyEvent from kitty.typing import BossType, KittyCommonOpts from kitty.utils import ( @@ -411,8 +411,10 @@ def convert_text(text: str, cols: int) -> str: appended = False for line in full_line.split('\r'): if line: - escape_codes_len = sum([len(match) for match in kitty_ansi_sanitizer_pat().findall(line)]) - lines.append(line.ljust(cols + escape_codes_len, '\0')) + line_sz = wcswidth(line) + if line_sz < cols: + line += '\0' * (cols - line_sz) + lines.append(line) lines.append('\r') appended = True if appended: