Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/prompt_toolkit/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,11 @@ def get_word_before_cursor(
def _is_word_before_cursor_complete(
self, WORD: bool = False, pattern: Pattern[str] | None = None
) -> bool:
if not self.text_before_cursor == "" or self.text_before_cursor[-1:].isspace():
if self.text_before_cursor == "" or self.text_before_cursor[-1:].isspace():
return True
if pattern:
return self.find_start_of_previous_word(WORD=WORD, pattern=pattern) is None
return False

def find_start_of_previous_word(
self, count: int = 1, WORD: bool = False, pattern: Pattern[str] | None = None
Expand Down
7 changes: 4 additions & 3 deletions src/prompt_toolkit/shortcuts/dialogs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import functools
from asyncio import get_running_loop
from typing import Any, Callable, Sequence, TypeVar

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

def log_text(text: str) -> None:
app.loop.call_soon_threadsafe(text_area.buffer.insert_text, text)
app.invalidate()
loop = app.loop
if loop is not None:
loop.call_soon_threadsafe(text_area.buffer.insert_text, text)
app.invalidate()

# Run the callback in the executor. When done, set a return value for the
# UI, so that it quits.
Expand Down
5 changes: 3 additions & 2 deletions tests/test_document.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import pytest
import re

import pytest

from prompt_toolkit.document import Document


Expand Down Expand Up @@ -77,4 +78,4 @@ def test_get_word_before_cursor_with_whitespace_and_pattern():
assert document.get_word_before_cursor() == ""

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