Skip to content

Commit

Permalink
fixed issue with inserting and replacing regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Gornostal committed Feb 16, 2013
1 parent 5e2baa9 commit a1654da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
30 changes: 19 additions & 11 deletions Modific.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FULL_PLUGIN_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
PLUGIN_DIRECTORY = FULL_PLUGIN_DIRECTORY.replace(os.path.normpath(os.path.join(FULL_PLUGIN_DIRECTORY, '..', '..')) + os.path.sep, '').replace(os.path.sep, '/')


def get_settings():
return sublime.load_settings("Modific.sublime-settings")

Expand Down Expand Up @@ -132,21 +133,29 @@ def run(self):

class EditViewCommand(sublime_plugin.TextCommand):

def run(self, edit, command='replace', output='', region=None, begin=0):
def run(self, edit, command=None, output='', begin=0, region=None):
"""
For some reason Sublime's view.run_command() doesn't allow to pass tuples,
therefore region must be a list
"""
region = sublime.Region(int(region[0]), int(region[1])) if region else None
if command == 'insert':
self.view.insert(edit, begin, output)
self.view.insert(edit, int(begin), output)
elif command == 'replace':
self.view.replace(edit, region, output)
else:
elif command == 'erase':
self.view.erase(edit, region)
else:
print('Invalid command: ', command)
raise


class VcsCommand(object):
may_change_files = False

def __init__(self, view=None):
def __init__(self, *args, **kwargs):
self.settings = get_settings()
super().__init__(view)
super(VcsCommand, self).__init__(*args, **kwargs)

def run_command(self, command, callback=None, show_status=True,
filter_empty_args=True, **kwargs):
Expand Down Expand Up @@ -190,10 +199,9 @@ def _output_to_view(self, output_file, output, clear=False,
syntax="Packages/Diff/Diff.tmLanguage"):
output_file.set_syntax_file(syntax)
if clear:
region = sublime.Region(0, self.output_view.size())
output_file.run_command('edit_view', {'command': 'replace', 'region': region, 'output': output})
output_file.run_command('edit_view', dict(command='replace', region=[0, self.output_view.size()], output=output))
else:
output_file.run_command('edit_view', {'command': 'insert', 'output': output})
output_file.run_command('edit_view', dict(command='insert', output=output))

def scratch(self, output, title=False, position=None, **kwargs):
scratch_file = self.get_window().new_file()
Expand Down Expand Up @@ -467,12 +475,12 @@ def run(self, edit):
end = self.view.line(self.view.text_point(replace_lines + current - 2, 0)).end()
region = sublime.Region(begin, end)
if lines:
self.view.run_command('edit_view', {'command': 'replace', 'region': region, 'output': content})
self.view.run_command('edit_view', dict(command='replace', region=[region.begin(), region.end()], output=content))
else:
region = self.view.full_line(region)
self.view.run_command('edit_view', {'command': 'erase', 'region': region})
self.view.run_command('edit_view', dict(command='erase', region=[region.begin(), region.end()]))
else:
self.view.run_command('edit_view', {'command': 'insert', 'begin': begin, 'output': content + os.linesep})
self.view.run_command('edit_view', dict(command='insert', begin=begin, output=content + os.linesep))
self.view.run_command('save')


Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Modific
=========

Modific is a ST3 plugin for highlighting lines changed from the last commit (you know what I mean if you used Netbeans).
Modific is a ST2(3) plugin for highlighting lines changed since the last commit (you know what I mean if you used Netbeans).

For now it supports **Git**, **SVN**, **Bazaar** and **Mercurial**.

Expand All @@ -24,15 +24,15 @@ The "Packages" directory is located at:

* OS X:

~/Library/Application Support/Sublime Text 3/Packages/
~/Library/Application Support/Sublime Text 2/Packages/

* Linux:

~/.config/sublime-text-3/Packages/
~/.config/sublime-text-2/Packages/

* Windows:

%APPDATA%/Sublime Text 3/Packages/
%APPDATA%/Sublime Text 2/Packages/

Please, make sure your VCS binaries is in the PATH (**especially if you are on Windows**).

Expand All @@ -59,7 +59,7 @@ This command reverts modifications if your cursor stays on modified line (or if

**Go through changed lines** `Ctrl+Shift+Page Up(Down)`

For those who expected to see a clone of Netbeans feature - unfortunately, with existing ST3 API that is impossible :(
For those who expected to see a clone of Netbeans feature - unfortunately, with existing Sublime Text API that is impossible :(

[Discussion on the forum](http://www.sublimetext.com/forum/viewtopic.php?f=5&t=7468)

Expand Down

0 comments on commit a1654da

Please sign in to comment.