Skip to content

Commit 5b53715

Browse files
committed
Refactor: Extract _update_mapping()
1 parent 674fdf3 commit 5b53715

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

gitbrowse/browser.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ def get_status(self):
7373
'message': self.file_history.current_commit.message,
7474
}
7575

76+
def _update_mapping(self, start, finish):
77+
mapping = self.file_history.line_mapping(start, finish)
78+
new_highlight_line = mapping.get(self.highlight_line)
79+
if new_highlight_line is not None:
80+
self.highlight_line = new_highlight_line
81+
else:
82+
# The highlight_line setter validates the value, so it makes
83+
# sense to set it to the same value here to make sure that it's
84+
# not out of range for the newly loaded revision of the file.
85+
self.highlight_line = self.highlight_line
86+
7687
def _move_commit(self, method_name):
7788
start = self.file_history.current_commit.sha
7889

@@ -83,15 +94,7 @@ def _move_commit(self, method_name):
8394

8495
finish = self.file_history.current_commit.sha
8596

86-
mapping = self.file_history.line_mapping(start, finish)
87-
new_highlight_line = mapping.get(self.highlight_line)
88-
if new_highlight_line is not None:
89-
self.highlight_line = new_highlight_line
90-
else:
91-
# The highlight_line setter validates the value, so it makes
92-
# sense to set it to the same value here to make sure that it's
93-
# not out of range for the newly loaded revision of the file.
94-
self.highlight_line = self.highlight_line
97+
self._update_mapping(start, finish)
9598

9699
@ModalScrollingInterface.key_bindings(']')
97100
def next_commit(self, times=1):

0 commit comments

Comments
 (0)