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 Jul 12, 2024
1 parent 761cefa commit e5e7bf2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions plugin/view_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def calcualte_level_regions(


class ViewManager:
__instances: dict[weakref.ref[sublime.View], ViewManager] = {}
__instances: weakref.WeakKeyDictionary[sublime.View, ViewManager] = weakref.WeakKeyDictionary()

def __init__(self, view: sublime.View, *, _from_init: bool = True) -> None:
if _from_init:
Expand All @@ -56,11 +56,9 @@ def __init__(self, view: sublime.View, *, _from_init: bool = True) -> None:

@classmethod
def get_instance(cls, view: sublime.View) -> ViewManager:
view_proxy = weakref.proxy(view)
view_ref = weakref.ref(view)
if not cls.__instances.get(view_ref):
cls.__instances[view_ref] = cls(view_proxy, _from_init=False)
return cls.__instances[view_ref]
if view not in cls.__instances:
cls.__instances[view] = cls(view, _from_init=False)
return cls.__instances[view]

def clear_view(self) -> None:
for level in range(self.max_level + 1):
Expand Down

0 comments on commit e5e7bf2

Please sign in to comment.