Skip to content

Commit

Permalink
refactor: tidy codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
  • Loading branch information
jfcherng committed May 27, 2024
1 parent b3e4d31 commit 7cf4c65
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion plugin/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

POINT = int
TUPLE_REGION = Tuple[POINT, POINT]
INDENT_LEVEL = int

if sys.version_info >= (3, 11):
from enum import StrEnum
Expand Down Expand Up @@ -41,7 +42,7 @@ def indent_length(self) -> int:

@cached_property
def indent_pattern(self) -> str:
return rf"^({self.indent_chars})+"
return rf"^(?:{self.indent_chars})+"

@cached_property
def indent_pattern_compiled(self) -> Pattern[str]:
Expand Down
2 changes: 1 addition & 1 deletion plugin/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def is_renderable_view(view: sublime.View) -> bool:
# activation by plugin's logics
return bool(
view.is_valid()
and view.element() is None
and not view.element()
and not is_transient_view(view)
and (syntax := view.syntax())
and sublime.score_selector(syntax.scope, get_enabled_selector()) > 0
Expand Down
2 changes: 0 additions & 2 deletions plugin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def get_plugin_setting(key: str) -> Any: ...
def get_plugin_setting(key: str, default: None) -> Any: ...
@overload
def get_plugin_setting(key: str, default: _T) -> _T: ...


def get_plugin_setting(key: str, default: Any = None) -> Any:
return get_plugin_settings().get(key, default)

Expand Down
8 changes: 4 additions & 4 deletions plugin/view_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import sublime

from .data_types import IndentInfo, LevelStyle
from .data_types import INDENT_LEVEL, IndentInfo, LevelStyle
from .helpers import get_regions_key
from .indent_renderer import AbstractIndentRenderer, find_indent_renderer
from .settings import get_level_colors, get_level_style
Expand All @@ -17,9 +17,9 @@ def calcualte_level_regions(
*,
indent_info: IndentInfo | None = None,
regions: Sequence[sublime.Region] | None = None,
) -> defaultdict[int, list[sublime.Region]]:
) -> defaultdict[INDENT_LEVEL, list[sublime.Region]]:
"""
Calculates the begin point of indents for each level.
Calculates regions of indents for each level.
:param view: The view.
:param indent_info: The indent information.
Expand All @@ -36,7 +36,7 @@ def calcualte_level_regions(
regions = (sublime.Region(0, view.size()),)

whole_content = view.substr(sublime.Region(0, view.size()))
level_regions: defaultdict[int, list[sublime.Region]] = defaultdict(list)
level_regions: defaultdict[INDENT_LEVEL, list[sublime.Region]] = defaultdict(list)
for region in regions:
for m in indent_info.indent_pattern_compiled.finditer(whole_content, region.begin(), region.end()):
for level, level_pt in enumerate(range(m.start(), m.end(), indent_info.indent_length)):
Expand Down

0 comments on commit 7cf4c65

Please sign in to comment.