From 6b5b5631960317c89150426330a20618b7c7e210 Mon Sep 17 00:00:00 2001 From: Kamil Kujawinski Date: Wed, 19 Aug 2015 18:57:44 +0200 Subject: [PATCH] executing isort on select code only --- isort_file.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/isort_file.py b/isort_file.py index 103d7a7..20f3022 100644 --- a/isort_file.py +++ b/isort_file.py @@ -13,7 +13,16 @@ class IsortCommand(sublime_plugin.TextCommand): view = None def get_region(self, view): - return sublime.Region(0, view.size()) + selection = view.sel()[0] + if selection.empty(): + return sublime.Region(0, view.size()) + + begin_line, begin_column = view.rowcol(selection.begin()) + end_line, end_column = view.rowcol(selection.end()) + return sublime.Region( + view.text_point(begin_line, 0), + view.text_point(end_line, 0) + ) def get_buffer_contents(self, view): return view.substr(self.get_region(view))