Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 3 column mode #2

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions ResizeActiveGroup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sublime_plugin
import time
from copy import deepcopy


class ResizeActiveGroup(sublime_plugin.EventListener):

def __init__(self):
self.col_times = []
# based on the active group we calculate the cols/rows array
def get_big(self, arr, activeGroup):
return [arr[0], arr[1] if (activeGroup == 1) ^ (arr[1] > 0.5) else 1 - arr[1], arr[2]]
Expand All @@ -27,10 +29,6 @@ def on_activated(self, view):
else:
newLayout["rows"] = self.get_big(oldLayout["rows"], activeGroup)

# 3 cells
elif len(oldLayout["cells"]) == 3:
pass

# 4 cells
elif len(oldLayout["cells"]) == 4:
# Grid: 4
Expand All @@ -48,5 +46,33 @@ def on_activated(self, view):
newLayout["cols"] = self.get_big(oldLayout["cols"], activeGroup - 2)
newLayout["rows"] = self.get_big(oldLayout["rows"], activeGroup - 2)


# 3 cols/cells? not sure how it works
elif len(oldLayout["cells"]) == 3 and len(oldLayout["cols"]) == 4:
import sys
if sys.version_info[0] >= 3:
xrange = range
widths = []
for i in xrange(len(oldLayout["cols"])-1):
widths += [oldLayout["cols"][i+1]-oldLayout["cols"][i]]
widths = sorted(widths)
w2 = [0 for i in xrange(len(widths))]


for i in xrange(len(oldLayout["cols"])-len(self.col_times)-1):
self.col_times += [0];

self.col_times[activeGroup] = time.time()
order = sorted(zip(xrange(len(self.col_times)),self.col_times), key=lambda value:value[1])
order = [o[0] for o in order]

for i in xrange(len(widths)):
w2[order[i]] = widths[i]

left = 0
for i in xrange(len(w2)):
left += w2[i]
newLayout["cols"][i+1] = left;

if oldLayout != newLayout:
window.set_layout(newLayout)