diff --git a/typescript/libs/view_helpers.py b/typescript/libs/view_helpers.py index 60c21318..692a2df4 100644 --- a/typescript/libs/view_helpers.py +++ b/typescript/libs/view_helpers.py @@ -95,24 +95,29 @@ def active_window(): """Return currently active window""" return sublime.active_window() +def selector_matches_whole_file(view, selector): + regions = view.find_by_selector(selector) + return len(regions) == 1 and regions[0].size() == view.size() def is_typescript(view): """Test if the outer syntactic scope is 'source.ts' or 'source.tsx' """ if not view.file_name(): return False - try: - location = view.sel()[0].begin() - except: - return False - - is_ts_file = view.match_selector(location, 'source.ts, source.tsx') + # Check if the *entire file* is one contiguous TypeScript/JavaScript region. + # + # Why am I writing this note? We used to test for the *current selection*. + # This meant that as soon as a user clicked into an html `