Skip to content

Commit

Permalink
Merge pull request #1829 from timbrel/chunkwise
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Dec 8, 2023
2 parents 0f32c20 + ab4aec3 commit 32d8a08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
28 changes: 16 additions & 12 deletions core/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import intra_line_colorizer
from . import stage_hunk
from .navigate import GsNavigate
from ..fns import head, filter_, flatten, pairwise, unique
from ..fns import head, filter_, flatten, unique
from ..parse_diff import SplittedDiff
from ..git_command import GitCommand
from ..runtime import ensure_on_ui, enqueue_on_worker
Expand Down Expand Up @@ -1017,19 +1017,23 @@ class gs_diff_navigate(GsNavigate):

offset = 0
log_position = True
shrink_to_cursor = False

def get_available_regions(self):
return [
sublime.Region(a.a, b.a - 1)
for a, b in pairwise(
chain(
self.view.find_by_selector(
"meta.diff.range.unified, meta.commit-info.header"
),
[sublime.Region(self.view.size())]
)
)
]
def _gen():
# type: () -> Iterator[sublime.Region]
diff = SplittedDiff.from_view(self.view)
for hunk in diff.hunks:
yield sublime.Region(hunk.region().a)
chunks = list(chunkby(hunk.content().lines(), lambda line: not line.is_context()))
if len(chunks) > 1:
for chunk in chunks:
yield sublime.Region(chunk[0].region().a, chunk[-1].region().b)

return sorted(
list(_gen())
+ self.view.find_by_selector("meta.commit-info.header")
)


class gs_diff_undo(TextCommand, GitCommand):
Expand Down
9 changes: 6 additions & 3 deletions core/commands/navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GsNavigate(TextCommand, GitCommand):
show_at_center = False
wrap = True
wrap_with_force = False
shrink_to_cursor = True
log_position = False
# For the first entry, try to show the beginning of the buffer.
# (Usually we have some info/help text there.)
Expand Down Expand Up @@ -53,9 +54,11 @@ def run(self, edit, forward=True):

self._just_jumped = 2
sel.clear()
# Position the cursor at the beginning of the section...
new_cursor_position = wanted_section.begin() + self.offset
sel.add(sublime.Region(new_cursor_position))
if self.shrink_to_cursor or self.offset:
new_cursor_position = sublime.Region(wanted_section.begin() + self.offset)
else:
new_cursor_position = sublime.Region(wanted_section.b, wanted_section.a)
sel.add(new_cursor_position)

if self.show_at_center:
self.view.show_at_center(new_cursor_position)
Expand Down

0 comments on commit 32d8a08

Please sign in to comment.