Created
January 18, 2021 04:36
-
-
Save OdatNurd/94db30476f1560e49d5d7bf2f09ff119 to your computer and use it in GitHub Desktop.
Plugin 101 Lesson 21 examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sublime | |
| import sublime_plugin | |
| class ReverseSelectAllCommand(sublime_plugin.TextCommand): | |
| def run(self, edit): | |
| span = sublime.Region(len(self.view), 0) | |
| self.view.sel().add(span) | |
| class RemoveSomeSelectionCommand(sublime_plugin.TextCommand): | |
| def run(self, edit): | |
| span = sublime.Region(7, 14) # "sublime" on line one | |
| self.view.sel().subtract(span) | |
| class FlipCaretCommand(sublime_plugin.TextCommand): | |
| def run(self, edit): | |
| new_sel = [] | |
| for sel in self.view.sel(): | |
| new_sel.append(sublime.Region(sel.b, sel.a)) | |
| self.view.sel().clear() | |
| self.view.sel().add_all(new_sel) | |
| class BrokenSelectCommand(sublime_plugin.WindowCommand): | |
| def run(self): | |
| view = self.window.active_view() | |
| view.sel().clear() | |
| view.sel().add(sublime.Region(14, 14)) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These plugin examples are from Plugin 101 Lesson 21 on my YouTube Channel, which shows how to query and modify the selection in any file, including a demonstration of a common pitfall to fall into, why it happens and how to solve it.