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

fix "resize_on_focus" feature and expose it in settings #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion ExpandGroup.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
// Put a float between 0 and 0.5
// The target group will expand to 0 < 0.5 + ratio <= 1
// Horizontally and Vertically
"ratio" : 0.3
"ratio" : 0.3,

// Whether to resize on mouse focus (default true)
"resize_on_focus" : true
}
14 changes: 13 additions & 1 deletion expand_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
"""
import sublime, sublime_plugin
import logging
import time

# time.time() for when we called "focus_group" command
LAST_FOCUS_GROUP_TIME = 0.
# amout of time (in seconds) that we expect "on_activated" event to arrive after calling "focus_group"
# so in that case we can assume "on_activated" was not triggered by mouse.
EVENT_TIME = 0.4

def getLogger():
logging.basicConfig(format='%(message)s')
Expand Down Expand Up @@ -57,7 +64,10 @@ def on_activated(self, view):
self.settings = sublime.load_settings("ExpandGroup.sublime-settings")

# If mouse focus disabled. Exit.
if self.settings.get('resize_on_focus') == False: return 0
triggered_by_command = time.time() - LAST_FOCUS_GROUP_TIME < EVENT_TIME
triggered_by_mouse = not triggered_by_command

if triggered_by_mouse and self.settings.get('resize_on_focus') == False: return 0

# If theres only one group in current window. Do nothing.
if win.num_groups() == 1: return 0
Expand Down Expand Up @@ -117,6 +127,8 @@ def run(self, direction, withCurrentFile=False):
#logger.info('group : %d', group)
#logger.info('action: %s', action)

global LAST_FOCUS_GROUP_TIME
LAST_FOCUS_GROUP_TIME = time.time()
win.run_command(action, {"group": group})
#logger.info('===================================================')

Expand Down