Skip to content

Commit

Permalink
refactor: tidy codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Feb 27, 2024
1 parent 51ca16c commit e7ed54b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugin/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def names_as_str(items: Iterable[Any], *, sep: str = ", ") -> str:
def _configured_debounce(func: _T_Callable) -> _T_Callable:
"""Debounce a function so that it's called once in seconds."""

def debounced(*args: Any, **kwargs: Any) -> None:
def debounced(*args: Any, **kwargs: Any) -> Any:
if (time_s := get_merged_plugin_setting("debounce", 0)) > 0:
return debounce(time_s)(func)(*args, **kwargs)
return func(*args, **kwargs)
Expand Down
6 changes: 5 additions & 1 deletion plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ def list_all_views(*, include_transient: bool = False) -> Generator[sublime.View


def get_view_by_id(id: int) -> sublime.View | None:
return first_true(list_all_views(include_transient=True), pred=lambda view: view.id() == id)
return view if (view := sublime.View(id)).is_valid() else None


def get_window_by_id(id: int) -> sublime.Window | None:
return window if (window := sublime.Window(id)).is_valid() else None


def head_tail_content(content: str, partial: int) -> str:
Expand Down

0 comments on commit e7ed54b

Please sign in to comment.