Sublime Forum

New Style Tabs

#21

no, I’ve not installed that.

The menu item does the same, and is displayed with the shift+f11 keybinding.

0 Likes

#22

I’ve figured this one out; the distractionFree command in /Default/DistractionFree.py uses the drawcentred option to determine if distractionfree mode is currently running. Since I always run sublime in centred mode, the plugin always thinks I’ve got distractionfree mode on, and running the command attempts to turn it off again. Which exits fullscreen mode and puts all the furniture back.

The fix is to add in an extra property to distinguish distractionfree from not;

import sublime, sublimeplugin

class DistractionFreeCommand(sublimeplugin.TextCommand): def run(self, view, args): if not view.options().get('distractionfree'): view.options().set('distractionfree', True) ...] else: # Drop the explicit options previously set, letting the defaults # show through. view.options().erase('distractionfree') ...]

0 Likes

#23

Actually, a little better is to push and pop options, using an option backup system to save off old values. When you leave distractionfree, you pop off the most recent values for the old values.

import sublime, sublimeplugin

def pushOption(view, name, value):
    backupKey = "%s.backup" % name
    oldValue = view.options().get(name)
    print "saving %s=%s" % (backupKey, oldValue)
    view.options().set(backupKey, oldValue)
    view.options().set(name, value)
    
def popOption(view, name):
    backupKey = "%s.backup" % name
    oldValue = view.options().get(backupKey)
    print "restoring %s=%s" % (name, oldValue)
    view.options().set(name, oldValue)
    view.options().erase(backupKey)

class DistractionFreeCommand(sublimeplugin.TextCommand):
    
    def run(self, view, args):
        
        if not view.options().get('distractionfree'):
            view.options().set('distractionfree', True)
            
            pushOption(view, 'drawCentered', True)
            pushOption(view, 'lineNumbers', False)
            pushOption(view, 'highlightLine', False)
            pushOption(view, 'wrapWidth', 80)
            pushOption(view, 'wordWrap', True)
            pushOption(view, 'wantScrollBars', False)
            pushOption(view, 'rulers', '')

            window = view.window()
            if not window.isFullScreen():
                window.runCommand('toggleFullScreen')
                pass

        else:
            # Drop the explicit options previously set, letting the defaults
            # show through.
            view.options().erase('distractionfree')
            popOption(view, 'drawCentered')
            popOption(view, 'lineNumbers')
            popOption(view, 'highlightLine')
            popOption(view, 'wrapWidth')
            popOption(view, 'wordWrap')
            popOption(view, 'wantScrollBars')
            popOption(view, 'rulers')

            window = view.window()            
            if window.isFullScreen():
                window.runCommand('toggleFullScreen')
0 Likes

#24

Not all the way there yet, actually. You should probably not take the code above as 100% … y’know… working.

0 Likes