Skip to content

Instantly share code, notes, and snippets.

@OdatNurd
Created January 10, 2018 22:01
Show Gist options
  • Save OdatNurd/63de72944fec74577d926afe9bcedc59 to your computer and use it in GitHub Desktop.
Save OdatNurd/63de72944fec74577d926afe9bcedc59 to your computer and use it in GitHub Desktop.
Sublime Text font size limiting on "zoom"
import sublime
import sublime_plugin
# This is a modified version of the Default/font.py file that ships with
# sublime, which includes versions of the increase and decrease font size
# commands that limit the size the font can be at each extreme.
# This includes an event listener that catches any attempt to use the
# "standard" font commands and rewrites the command to use these ones instead.
min_font_size = 14
max_font_size = 26
class IncreaseFontSizeLimitCommand(sublime_plugin.ApplicationCommand):
def run(self):
s = sublime.load_settings("Preferences.sublime-settings")
current = s.get("font_size", 10)
if current >= 36:
current += 4
elif current >= 24:
current += 2
else:
current += 1
if current > max_font_size:
current = max_font_size
s.set("font_size", current)
sublime.save_settings("Preferences.sublime-settings")
class DecreaseFontSizeLimitCommand(sublime_plugin.ApplicationCommand):
def run(self):
s = sublime.load_settings("Preferences.sublime-settings")
current = s.get("font_size", 10)
# current -= 1
if current >= 40:
current -= 4
elif current >= 26:
current -= 2
else:
current -= 1
if current < min_font_size:
current = min_font_size
s.set("font_size", current)
sublime.save_settings("Preferences.sublime-settings")
class FontEventListener(sublime_plugin.EventListener):
def on_window_command(self, window, command, args):
if command == "increase_font_size":
return ("increase_font_size_limit", args)
elif command == "decrease_font_size":
return ("decrease_font_size_limit", args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment