Skip to content

Commit

Permalink
Merge pull request #1138 from kaste/stoivo/inline_diff_big_files
Browse files Browse the repository at this point in the history
Stoivo/inline diff big files
  • Loading branch information
stoivo committed Sep 25, 2019
2 parents 30172d9 + b9fcd15 commit b5f7776
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
13 changes: 7 additions & 6 deletions common/commands/view_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ class GsReplaceViewTextCommand(TextCommand):

def run(self, edit, text, nuke_cursors=False, restore_cursors=False):
cursors_num = len(self.view.sel())

if restore_cursors:
save_cursors = [self.view.rowcol(s.a) for s in self.view.sel()]
self.view.sel().clear()

# Always clear the selection before replacing the view. Otherwise you
# will have a flash where all the text is selected.
self.view.sel().clear()

is_read_only = self.view.is_read_only()
self.view.set_read_only(False)
self.view.replace(edit, sublime.Region(0, self.view.size()), text)
self.view.set_read_only(is_read_only)

if not cursors_num or nuke_cursors:
selections = self.view.sel()
selections.clear()
if cursors_num == 0 or nuke_cursors:
self.view.sel().clear()
pt = sublime.Region(0, 0)
selections.add(pt)
self.view.sel().add(pt)

elif restore_cursors:
self.view.sel().clear()
Expand Down
7 changes: 7 additions & 0 deletions common/util/diff_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def get_indices(chunks):


def get_changes(old, new):
# if one of the inputs, either old or new is more then 10 000 characters
# we skip trying to find the words which changed. If a hunk is more than
# 10 000 characters it is most likely a generated change.
# We skip since this calculation take a lot of time then it gets bigger.
if max(len(old), len(new)) > 10000:
return []

old_chunks = tuple(filter(lambda x: x, boundary.split(old)))
new_chunks = tuple(filter(lambda x: x, boundary.split(new)))
old_indices = get_indices(old_chunks)
Expand Down
24 changes: 17 additions & 7 deletions core/commands/inline_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def run(self, settings=None, cached=False, match_current_position=False):

self.window.focus_view(diff_view)

diff_view.run_command("gs_inline_diff_refresh", {"match_position": cur_pos})
diff_view.run_command("gs_inline_diff_refresh", {
"match_position": cur_pos,
"sync": False
})
diff_view.run_command("gs_handle_vintageous")

def augment_color_scheme(self, target_view, file_ext):
Expand Down Expand Up @@ -177,7 +180,14 @@ class GsInlineDiffRefreshCommand(TextCommand, GitCommand):
are not supported in `cached` mode.
"""

def run(self, edit, match_position=None):
def run(self, edit, sync=True, match_position=None):
if sync:
self._run(match_position=match_position)
else:
sublime.set_timeout_async(lambda: self._run(match_position=match_position))

def _run(self, match_position=None):

file_path = self.file_path
in_cached_mode = self.view.settings().get("git_savvy.inline_diff_view.in_cached_mode")
ignore_eol_arg = (
Expand Down Expand Up @@ -212,8 +222,10 @@ def run(self, edit, match_position=None):
if match_position is None:
cur_pos = capture_cur_position(self.view)

self.view.set_read_only(False)
self.view.replace(edit, sublime.Region(0, self.view.size()), inline_diff_contents)
self.view.run_command("gs_replace_view_text", {
"text": inline_diff_contents,
"restore_cursors": True
})

if match_position is None:
if cur_pos == (0, 0) and self.savvy_settings.get("inline_diff_auto_scroll", False):
Expand All @@ -227,7 +239,6 @@ def run(self, edit, match_position=None):
place_cursor_and_show(self.view, new_row, col)

self.highlight_regions(replaced_lines)
self.view.set_read_only(True)

sublime.set_timeout_async(lambda: self.verify_not_conflict(), 0)

Expand Down Expand Up @@ -370,9 +381,8 @@ class GsInlineDiffFocusEventListener(EventListener):
"""

def on_activated(self, view):

if view.settings().get("git_savvy.inline_diff_view") is True:
view.run_command("gs_inline_diff_refresh")
view.run_command("gs_inline_diff_refresh", {"sync": False})


class GsInlineDiffStageOrResetBase(TextCommand, GitCommand):
Expand Down

0 comments on commit b5f7776

Please sign in to comment.