-
Notifications
You must be signed in to change notification settings - Fork 0
/
behindFold.py
35 lines (27 loc) · 1.09 KB
/
behindFold.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sublime
import sublime_plugin
# Makes code-folding safer, backspace unfolds code
# Taken from StackOverflow
# https://stackoverflow.com/questions/41460907/is-there-a-way-to-set-the-fold-symbol-in-sublimetext-read-only
class UnfoldBeforeCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
for sel in view.sel():
# fold the position before the selection
view.unfold(sublime.Region(sel.b - 1))
class IsBehindFoldContext(sublime_plugin.EventListener):
def on_query_context(self, view, key, operator, operand, match_all):
if key != "is_behind_fold":
return
quantor = all if match_all else any
result = quantor(
view.is_folded(sel) and view.is_folded(sublime.Region(sel.b - 1))
for sel in view.sel()
)
if operator == sublime.OP_EQUAL:
result = result == operand
elif operator == sublime.OP_NOT_EQUAL:
result = result != operand
else:
raise Exception("Operator type not supported")
return result