Skip to content

Commit 2aec820

Browse files
Fix nested completer which got broken in previous 'get_word_before_cursor' fix (#2034)
* Fix nested completer which got broken in previous 'get_word_before_cursor' fix. * Ruff-related fixes. * Fix typing issue in dialogs.py.
1 parent 9dbffd7 commit 2aec820

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/prompt_toolkit/document.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,11 @@ def get_word_before_cursor(
457457
def _is_word_before_cursor_complete(
458458
self, WORD: bool = False, pattern: Pattern[str] | None = None
459459
) -> bool:
460-
if not self.text_before_cursor == "" or self.text_before_cursor[-1:].isspace():
460+
if self.text_before_cursor == "" or self.text_before_cursor[-1:].isspace():
461461
return True
462462
if pattern:
463463
return self.find_start_of_previous_word(WORD=WORD, pattern=pattern) is None
464+
return False
464465

465466
def find_start_of_previous_word(
466467
self, count: int = 1, WORD: bool = False, pattern: Pattern[str] | None = None

src/prompt_toolkit/shortcuts/dialogs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import functools
4-
from asyncio import get_running_loop
54
from typing import Any, Callable, Sequence, TypeVar
65

76
from prompt_toolkit.application import Application
@@ -290,8 +289,10 @@ def set_percentage(value: int) -> None:
290289
app.invalidate()
291290

292291
def log_text(text: str) -> None:
293-
app.loop.call_soon_threadsafe(text_area.buffer.insert_text, text)
294-
app.invalidate()
292+
loop = app.loop
293+
if loop is not None:
294+
loop.call_soon_threadsafe(text_area.buffer.insert_text, text)
295+
app.invalidate()
295296

296297
# Run the callback in the executor. When done, set a return value for the
297298
# UI, so that it quits.

tests/test_document.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
import pytest
43
import re
54

5+
import pytest
6+
67
from prompt_toolkit.document import Document
78

89

@@ -77,4 +78,4 @@ def test_get_word_before_cursor_with_whitespace_and_pattern():
7778
assert document.get_word_before_cursor() == ""
7879

7980
_FIND_WORD_RE = re.compile(r"([a-zA-Z0-9_]+|[^a-zA-Z0-9_\s]+)")
80-
assert document.get_word_before_cursor(pattern=_FIND_WORD_RE) == ""
81+
assert document.get_word_before_cursor(pattern=_FIND_WORD_RE) == ""

0 commit comments

Comments
 (0)