From 58c8acf23cffa448f058f571cc858a8423826338 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Fri, 12 Jul 2024 14:28:31 +0100 Subject: [PATCH] Fix some regex handling and add another example --- examples/full-screen/simple-demos/word-wrapping.py | 12 +++++++++++- src/prompt_toolkit/layout/containers.py | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/full-screen/simple-demos/word-wrapping.py b/examples/full-screen/simple-demos/word-wrapping.py index cdc6e1a8a..e6a160eb5 100755 --- a/examples/full-screen/simple-demos/word-wrapping.py +++ b/examples/full-screen/simple-demos/word-wrapping.py @@ -87,7 +87,7 @@ def get_line_prefix(lineno, wrap_count): if wrap_count else [], ), - # Truncating (only wrap the first timle around) + # Truncating (only wrap the first time around) Window( BufferControl(buffer=buff), wrap_lines=True, @@ -100,6 +100,16 @@ def get_line_prefix(lineno, wrap_count): if wrap_count > 0 else fallback(line, lineno, wrap_count, start, end), ), + # Split only after vowels + Window( + BufferControl(buffer=buff), + wrap_lines=True, + wrap_finder=Window._whitespace_wrap_finder( + sep="[aeiouyAEIOUY]", + split="after", + continuation=to_formatted_text("-"), + ), + ), ] ), floats=[ diff --git a/src/prompt_toolkit/layout/containers.py b/src/prompt_toolkit/layout/containers.py index f347373ba..19c134a42 100644 --- a/src/prompt_toolkit/layout/containers.py +++ b/src/prompt_toolkit/layout/containers.py @@ -1955,9 +1955,9 @@ def _whitespace_wrap_finder( f"Pattern {sep_re.pattern!r} has capture group – use non-capturing groups instead" ) elif split == "after": - sep_re = re.compile("(?<={sep_re.pattern})()") + sep_re = re.compile(f"(?={sep_re.pattern})()") elif split == "before": - sep_re = re.compile("(?={sep_re.pattern})()") + sep_re = re.compile(f"(?<={sep_re.pattern})()") elif split == "remove": sep_re = re.compile(f"({sep_re.pattern})") else: