<s> import os <EOL> from collections import namedtuple <EOL> import sublime <EOL> from sublime_plugin import WindowCommand , TextCommand , EventListener <EOL> from ... common import util <EOL> from ... common . theme_generator import ThemeGenerator <EOL> from . . git_command import GitCommand <EOL> from . . constants import MERGE_CONFLICT_PORCELAIN_STATUSES <EOL> from ... common . util import debug <EOL> HunkReference = namedtuple ( "<STR_LIT>" , ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> INLINE_DIFF_TITLE = "<STR_LIT>" <EOL> INLINE_DIFF_CACHED_TITLE = "<STR_LIT>" <EOL> DIFF_HEADER = """<STR_LIT>""" <EOL> diff_view_hunks = { } <EOL> class GsInlineDiffCommand ( WindowCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , ** kwargs ) : <EOL> sublime . set_timeout_async ( lambda : self . run_async ( ** kwargs ) , <NUM_LIT:0> ) <EOL> def run_async ( self , settings = None , cached = False ) : <EOL> if settings is None : <EOL> file_view = self . window . active_view ( ) <EOL> syntax_file = file_view . settings ( ) . get ( "<STR_LIT>" ) <EOL> settings = { <EOL> "<STR_LIT>" : self . file_path , <EOL> "<STR_LIT>" : self . repo_path <EOL> } <EOL> else : <EOL> syntax_file = settings [ "<STR_LIT>" ] <EOL> del settings [ "<STR_LIT>" ] <EOL> diff_view = util . view . get_scratch_view ( self , "<STR_LIT>" , read_only = True ) <EOL> title = INLINE_DIFF_CACHED_TITLE if cached else INLINE_DIFF_TITLE <EOL> diff_view . set_name ( title + os . path . basename ( settings [ "<STR_LIT>" ] ) ) <EOL> diff_view . set_syntax_file ( syntax_file ) <EOL> file_ext = util . file . get_file_extension ( os . path . basename ( settings [ "<STR_LIT>" ] ) ) <EOL> self . augment_color_scheme ( diff_view , file_ext ) <EOL> diff_view . settings ( ) . set ( "<STR_LIT>" , cached ) <EOL> for k , v in settings . items ( ) : <EOL> diff_view . settings ( ) . set ( k , v ) <EOL> self . window . focus_view ( diff_view ) <EOL> diff_view . run_command ( "<STR_LIT>" ) <EOL> def augment_color_scheme ( self , target_view , file_ext ) : <EOL> """<STR_LIT>""" <EOL> colors = sublime . load_settings ( "<STR_LIT>" ) . get ( "<STR_LIT>" ) <EOL> original_color_scheme = target_view . settings ( ) . get ( "<STR_LIT>" ) <EOL> themeGenerator = ThemeGenerator ( original_color_scheme ) <EOL> themeGenerator . add_scoped_style ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> background = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <EOL> foreground = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> ) <EOL> themeGenerator . add_scoped_style ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> background = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <EOL> foreground = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> ) <EOL> themeGenerator . add_scoped_style ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> background = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <EOL> foreground = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> ) <EOL> themeGenerator . add_scoped_style ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> background = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <EOL> foreground = colors [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> ) <EOL> themeGenerator . apply_new_theme ( "<STR_LIT>" + file_ext , target_view ) <EOL> class GsInlineDiffRefreshCommand ( TextCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit ) : <EOL> file_path = self . file_path <EOL> in_cached_mode = self . view . settings ( ) . get ( "<STR_LIT>" ) <EOL> savvy_settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> ignore_eol_arg = ( <EOL> "<STR_LIT>" <EOL> if savvy_settings . get ( "<STR_LIT>" , True ) <EOL> else None <EOL> ) <EOL> if in_cached_mode : <EOL> indexed_object = self . get_indexed_file_object ( file_path ) <EOL> head_file_object = self . get_head_file_object ( file_path ) <EOL> head_file_contents = self . get_object_contents ( head_file_object ) <EOL> stdout = self . git ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ignore_eol_arg , head_file_object , indexed_object ) <EOL> diff = util . parse_diff ( stdout ) <EOL> inline_diff_contents , replaced_lines = self . get_inline_diff_contents ( head_file_contents , diff ) <EOL> else : <EOL> indexed_object = self . get_indexed_file_object ( file_path ) <EOL> indexed_object_contents = self . get_object_contents ( indexed_object ) <EOL> working_tree_file_contents = self . get_file_contents ( file_path ) <EOL> working_tree_file_object = self . get_object_from_string ( working_tree_file_contents ) <EOL> stdout = self . git ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ignore_eol_arg , indexed_object , working_tree_file_object ) <EOL> diff = util . parse_diff ( stdout ) <EOL> inline_diff_contents , replaced_lines = self . get_inline_diff_contents ( indexed_object_contents , diff ) <EOL> cursors = self . view . sel ( ) <EOL> if cursors : <EOL> row , col = self . view . rowcol ( cursors [ <NUM_LIT:0> ] . begin ( ) ) <EOL> self . view . set_read_only ( False ) <EOL> self . view . replace ( edit , sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) , inline_diff_contents ) <EOL> if cursors : <EOL> if ( row , col ) == ( <NUM_LIT:0> , <NUM_LIT:0> ) and savvy_settings . get ( "<STR_LIT>" , False ) : <EOL> self . view . run_command ( "<STR_LIT>" ) <EOL> else : <EOL> self . view . sel ( ) . clear ( ) <EOL> pt = self . view . text_point ( row , <NUM_LIT:0> ) <EOL> self . view . sel ( ) . add ( sublime . Region ( pt , pt ) ) <EOL> self . view . show_at_center ( pt ) <EOL> _ , vp_y = self . view . viewport_position ( ) <EOL> self . view . set_viewport_position ( ( <NUM_LIT:0> , vp_y ) , False ) <EOL> self . highlight_regions ( replaced_lines ) <EOL> self . view . set_read_only ( True ) <EOL> sublime . set_timeout_async ( lambda : self . verify_not_conflict ( ) , <NUM_LIT:0> ) <EOL> def get_indexed_file_object ( self , file_path ) : <EOL> """<STR_LIT>""" <EOL> stdout = self . git ( "<STR_LIT>" , "<STR_LIT>" , file_path ) <EOL> git_file_entry = stdout . split ( "<STR_LIT:U+0020>" ) <EOL> return git_file_entry [ <NUM_LIT:1> ] <EOL> def get_head_file_object ( self , file_path ) : <EOL> """<STR_LIT>""" <EOL> stdout = self . git ( "<STR_LIT>" , "<STR_LIT>" , file_path ) <EOL> git_file_entry = stdout . split ( ) <EOL> return git_file_entry [ <NUM_LIT:2> ] <EOL> def get_object_contents ( self , object_hash ) : <EOL> """<STR_LIT>""" <EOL> return self . git ( "<STR_LIT>" , "<STR_LIT>" , object_hash ) <EOL> def get_file_contents ( self , file_path ) : <EOL> """<STR_LIT>""" <EOL> file_path = os . path . join ( self . repo_path , file_path ) <EOL> with open ( file_path , "<STR_LIT>" , encoding = "<STR_LIT:utf-8>" ) as f : <EOL> return f . read ( ) <EOL> def get_object_from_string ( self , string ) : <EOL> """<STR_LIT>""" <EOL> stdout = self . git ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , stdin = string ) <EOL> return stdout . split ( "<STR_LIT:\n>" ) [ <NUM_LIT:0> ] <EOL> def get_inline_diff_contents ( self , original_contents , diff ) : <EOL> """<STR_LIT>""" <EOL> hunks = [ ] <EOL> diff_view_hunks [ self . view . id ( ) ] = hunks <EOL> lines = original_contents . split ( "<STR_LIT:\n>" ) <EOL> replaced_lines = [ ] <EOL> adjustment = <NUM_LIT:0> <EOL> for hunk in diff : <EOL> head_start = hunk . head_start - <NUM_LIT:1> <EOL> head_start += <NUM_LIT:1> if hunk . head_length == <NUM_LIT:0> else <NUM_LIT:0> <EOL> head_end = head_start + hunk . head_length <EOL> diff_lines = hunk . raw_lines [ <NUM_LIT:1> : ] <EOL> section_start = head_start + adjustment <EOL> section_end = section_start + len ( diff_lines ) <EOL> line_types = [ line [ <NUM_LIT:0> ] for line in diff_lines ] <EOL> raw_lines = [ line [ <NUM_LIT:1> : ] for line in diff_lines ] <EOL> hunks . append ( HunkReference ( <EOL> section_start , section_end , hunk , line_types , raw_lines <EOL> ) ) <EOL> lines = lines [ : section_start ] + raw_lines + lines [ head_end + adjustment : ] <EOL> replaced_lines . append ( ( section_start , section_end , line_types , raw_lines ) ) <EOL> adjustment += len ( diff_lines ) - hunk . head_length <EOL> return "<STR_LIT:\n>" . join ( lines ) , replaced_lines <EOL> def highlight_regions ( self , replaced_lines ) : <EOL> """<STR_LIT>""" <EOL> add_regions = [ ] <EOL> add_bold_regions = [ ] <EOL> remove_regions = [ ] <EOL> remove_bold_regions = [ ] <EOL> for section_start , section_end , line_types , raw_lines in replaced_lines : <EOL> region_start = None <EOL> region_end = None <EOL> region_type = None <EOL> for type_index , line_number in enumerate ( range ( section_start , section_end ) ) : <EOL> line = self . view . full_line ( self . view . text_point ( line_number , <NUM_LIT:0> ) ) <EOL> line_type = line_types [ type_index ] <EOL> if not region_type : <EOL> region_type = line_type <EOL> region_start = line . begin ( ) <EOL> elif region_type != line_type : <EOL> region_end = line . begin ( ) <EOL> l = add_regions if region_type == "<STR_LIT:+>" else remove_regions <EOL> l . append ( sublime . Region ( region_start , region_end ) ) <EOL> region_type = line_type <EOL> region_start = line . begin ( ) <EOL> region_end = line . end ( ) <EOL> l = add_regions if region_type == "<STR_LIT:+>" else remove_regions <EOL> l . append ( sublime . Region ( region_start , region_end ) ) <EOL> if "<STR_LIT:+>" in line_types and "<STR_LIT:->" in line_types : <EOL> section_start_idx = self . view . text_point ( section_start , <NUM_LIT:0> ) <EOL> remove_start = section_start_idx <EOL> first_added_line = line_types . index ( "<STR_LIT:+>" ) <EOL> add_start = section_start_idx + len ( "<STR_LIT:\n>" . join ( raw_lines [ : first_added_line ] ) ) + <NUM_LIT:1> <EOL> removed_part = "<STR_LIT:\n>" . join ( raw_lines [ : first_added_line ] ) <EOL> added_part = "<STR_LIT:\n>" . join ( raw_lines [ first_added_line : ] ) <EOL> changes = util . diff_string . get_changes ( removed_part , added_part ) <EOL> for change in changes : <EOL> if change . type in ( util . diff_string . DELETE , util . diff_string . REPLACE ) : <EOL> region_start = remove_start + change . old_start <EOL> region_end = remove_start + change . old_end <EOL> remove_bold_regions . append ( sublime . Region ( region_start , region_end ) ) <EOL> if change . type in ( util . diff_string . INSERT , util . diff_string . REPLACE ) : <EOL> region_start = add_start + change . new_start <EOL> region_end = add_start + change . new_end <EOL> add_bold_regions . append ( sublime . Region ( region_start , region_end ) ) <EOL> self . view . add_regions ( "<STR_LIT>" , add_regions , scope = "<STR_LIT>" ) <EOL> self . view . add_regions ( "<STR_LIT>" , remove_regions , scope = "<STR_LIT>" ) <EOL> self . view . add_regions ( "<STR_LIT>" , add_bold_regions , scope = "<STR_LIT>" ) <EOL> self . view . add_regions ( "<STR_LIT>" , remove_bold_regions , scope = "<STR_LIT>" ) <EOL> def verify_not_conflict ( self ) : <EOL> fpath = self . get_rel_path ( ) <EOL> status_file_list = self . get_status ( ) <EOL> for f in status_file_list : <EOL> if f . path == fpath : <EOL> if ( f . index_status , f . working_status ) in MERGE_CONFLICT_PORCELAIN_STATUSES : <EOL> sublime . error_message ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . view . window ( ) . focus_view ( self . view ) <EOL> self . view . window ( ) . run_command ( "<STR_LIT>" ) <EOL> break <EOL> class GsInlineDiffFocusEventListener ( EventListener ) : <EOL> """<STR_LIT>""" <EOL> def on_activated ( self , view ) : <EOL> if view . settings ( ) . get ( "<STR_LIT>" ) == True : <EOL> view . run_command ( "<STR_LIT>" ) <EOL> class GsInlineDiffStageOrResetBase ( TextCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit , ** kwargs ) : <EOL> sublime . set_timeout_async ( lambda : self . run_async ( ** kwargs ) , <NUM_LIT:0> ) <EOL> def run_async ( self , reset = False ) : <EOL> in_cached_mode = self . view . settings ( ) . get ( "<STR_LIT>" ) <EOL> savvy_settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> ignore_ws = ( <EOL> "<STR_LIT>" <EOL> if savvy_settings . get ( "<STR_LIT>" , True ) <EOL> else None <EOL> ) <EOL> selections = self . view . sel ( ) <EOL> region = selections [ <NUM_LIT:0> ] <EOL> if len ( selections ) > <NUM_LIT:1> or not region . empty ( ) : <EOL> return <EOL> line_number = self . view . rowcol ( region . begin ( ) ) [ <NUM_LIT:0> ] + <NUM_LIT:1> <EOL> diff_lines = self . get_diff_from_line ( line_number , reset ) <EOL> rel_path = self . get_rel_path ( ) <EOL> if os . name == "<STR_LIT>" : <EOL> rel_path = rel_path . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) <EOL> header = DIFF_HEADER . format ( path = rel_path ) <EOL> full_diff = header + diff_lines + "<STR_LIT:\n>" <EOL> args = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" if ( reset or in_cached_mode ) else None , <EOL> "<STR_LIT>" if ( not reset or in_cached_mode ) else None , <EOL> ignore_ws , <EOL> "<STR_LIT:->" <EOL> ] <EOL> self . git ( * args , stdin = full_diff ) <EOL> self . save_to_history ( args , full_diff ) <EOL> self . view . run_command ( "<STR_LIT>" ) <EOL> def save_to_history ( self , args , full_diff ) : <EOL> """<STR_LIT>""" <EOL> history = self . view . settings ( ) . get ( "<STR_LIT>" ) or [ ] <EOL> history . append ( ( args , full_diff ) ) <EOL> self . view . settings ( ) . set ( "<STR_LIT>" , history ) <EOL> class GsInlineDiffStageOrResetLineCommand ( GsInlineDiffStageOrResetBase ) : <EOL> """<STR_LIT>""" <EOL> def get_diff_from_line ( self , line_no , reset ) : <EOL> hunks = diff_view_hunks [ self . view . id ( ) ] <EOL> add_length_earlier_in_diff = <NUM_LIT:0> <EOL> cur_hunk_begin_on_minus = <NUM_LIT:0> <EOL> cur_hunk_begin_on_plus = <NUM_LIT:0> <EOL> for hunk_ref in hunks : <EOL> if hunk_ref . section_start <= line_no and hunk_ref . section_end >= line_no : <EOL> break <EOL> else : <EOL> for type in hunk_ref . line_types : <EOL> if type == "<STR_LIT:+>" : <EOL> add_length_earlier_in_diff += <NUM_LIT:1> <EOL> elif type == "<STR_LIT:->" : <EOL> add_length_earlier_in_diff -= <NUM_LIT:1> <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> else : <EOL> return <EOL> section_start = hunk_ref . section_start + <NUM_LIT:1> <EOL> index_in_hunk = line_no - section_start <EOL> line = hunk_ref . lines [ index_in_hunk ] <EOL> line_type = hunk_ref . line_types [ index_in_hunk ] <EOL> for type in hunk_ref . line_types [ : index_in_hunk ] : <EOL> if type == "<STR_LIT:->" : <EOL> cur_hunk_begin_on_minus += <NUM_LIT:1> <EOL> else : <EOL> cur_hunk_begin_on_plus += <NUM_LIT:1> <EOL> head_start = hunk_ref . hunk . head_start if line_type == "<STR_LIT:+>" else hunk_ref . hunk . head_start + index_in_hunk <EOL> if reset : <EOL> xhead_start = head_start - index_in_hunk + ( <NUM_LIT:0> if line_type == "<STR_LIT:+>" else add_length_earlier_in_diff ) <EOL> xnew_start = head_start - cur_hunk_begin_on_minus + index_in_hunk + add_length_earlier_in_diff - <NUM_LIT:1> <EOL> return ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> head_start = ( xhead_start if xhead_start >= <NUM_LIT:0> else cur_hunk_begin_on_plus ) , <EOL> head_length = "<STR_LIT:0>" if line_type == "<STR_LIT:+>" else "<STR_LIT:1>" , <EOL> new_start = xhead_start + ( <NUM_LIT:1> if line_type == "<STR_LIT:+>" else <NUM_LIT:0> ) , <EOL> new_length = "<STR_LIT:1>" if line_type == "<STR_LIT:+>" else "<STR_LIT:0>" , <EOL> line_type = line_type , <EOL> line = line <EOL> ) <EOL> else : <EOL> head_start += <NUM_LIT:1> <EOL> return ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> head_start = head_start + ( - <NUM_LIT:1> if line_type == "<STR_LIT:->" else <NUM_LIT:0> ) , <EOL> head_length = "<STR_LIT:0>" if line_type == "<STR_LIT:+>" else "<STR_LIT:1>" , <EOL> new_start = head_start + ( - <NUM_LIT:1> if line_type == "<STR_LIT:->" else <NUM_LIT:0> ) , <EOL> new_length = "<STR_LIT:1>" if line_type == "<STR_LIT:+>" else "<STR_LIT:0>" , <EOL> line_type = line_type , <EOL> line = line <EOL> ) <EOL> class GsInlineDiffStageOrResetHunkCommand ( GsInlineDiffStageOrResetBase ) : <EOL> """<STR_LIT>""" <EOL> def get_diff_from_line ( self , line_no , reset ) : <EOL> hunks = diff_view_hunks [ self . view . id ( ) ] <EOL> add_length_earlier_in_diff = <NUM_LIT:0> <EOL> for hunk_ref in hunks : <EOL> if hunk_ref . section_start <= line_no and hunk_ref . section_end >= line_no : <EOL> break <EOL> else : <EOL> for type in hunk_ref . line_types : <EOL> if type == "<STR_LIT:+>" : <EOL> add_length_earlier_in_diff += <NUM_LIT:1> <EOL> elif type == "<STR_LIT:->" : <EOL> add_length_earlier_in_diff -= <NUM_LIT:1> <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> else : <EOL> return <EOL> stand_alone_header = "<STR_LIT>" . format ( <EOL> head_start = hunk_ref . hunk . head_start + ( add_length_earlier_in_diff if reset else <NUM_LIT:0> ) , <EOL> head_length = hunk_ref . hunk . head_length , <EOL> new_start = hunk_ref . hunk . head_start + ( <NUM_LIT:0> if hunk_ref . hunk . head_length else <NUM_LIT:1> ) , <EOL> new_length = hunk_ref . hunk . saved_length <EOL> ) <EOL> return "<STR_LIT:\n>" . join ( [ stand_alone_header ] + hunk_ref . hunk . raw_lines [ <NUM_LIT:1> : ] ) <EOL> class GsInlineDiffOpenFile ( TextCommand ) : <EOL> """<STR_LIT>""" <EOL> @ util . view . single_cursor_coords <EOL> def run ( self , coords , edit ) : <EOL> if not coords : <EOL> return <EOL> cursor_line , cursor_column = coords <EOL> row , col = self . get_editable_position ( cursor_line + <NUM_LIT:1> , cursor_column + <NUM_LIT:1> ) <EOL> self . open_file ( row , col ) <EOL> def open_file ( self , row , col ) : <EOL> file_name = self . view . settings ( ) . get ( "<STR_LIT>" ) <EOL> self . view . window ( ) . open_file ( <EOL> "<STR_LIT>" . format ( <EOL> file = file_name , <EOL> row = row , <EOL> col = col <EOL> ) , <EOL> sublime . ENCODED_POSITION <EOL> ) <EOL> def get_editable_position ( self , line_no , col_no ) : <EOL> hunk_ref = self . get_closest_hunk_ref_before ( line_no ) <EOL> if not hunk_ref : <EOL> return line_no , col_no <EOL> if hunk_ref . section_end >= line_no : <EOL> hunk_change_index = line_no - hunk_ref . section_start - <NUM_LIT:1> <EOL> change = hunk_ref . hunk . changes [ hunk_change_index ] <EOL> return change . saved_pos , col_no if change . type == "<STR_LIT:+>" else <NUM_LIT:0> <EOL> else : <EOL> lines_after_hunk_end = line_no - hunk_ref . section_end - <NUM_LIT:1> <EOL> if all ( change . type == "<STR_LIT:->" for change in hunk_ref . hunk . changes ) : <EOL> lines_after_hunk_end += <NUM_LIT:1> <EOL> hunk_end_in_saved = hunk_ref . hunk . saved_start + hunk_ref . hunk . saved_length <EOL> return hunk_end_in_saved + lines_after_hunk_end , col_no <EOL> def get_closest_hunk_ref_before ( self , line_no ) : <EOL> hunks = diff_view_hunks [ self . view . id ( ) ] <EOL> for hunk_ref in reversed ( hunks ) : <EOL> if hunk_ref . section_start < line_no : <EOL> return hunk_ref <EOL> class GsInlineDiffGotoBase ( TextCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit ) : <EOL> selections = self . view . sel ( ) <EOL> region = self . view . line ( <NUM_LIT:0> ) if len ( selections ) == <NUM_LIT:0> else selections [ <NUM_LIT:0> ] <EOL> current_line_number = self . view . rowcol ( region . begin ( ) ) [ <NUM_LIT:0> ] + <NUM_LIT:1> <EOL> new_cursor_pt = self . get_target_cursor_pos ( current_line_number ) <EOL> if new_cursor_pt is not None : <EOL> self . view . sel ( ) . clear ( ) <EOL> self . view . sel ( ) . add ( new_cursor_pt ) <EOL> self . view . show_at_center ( self . view . line ( new_cursor_pt ) ) <EOL> class GsInlineDiffGotoNextHunk ( GsInlineDiffGotoBase ) : <EOL> """<STR_LIT>""" <EOL> def get_target_cursor_pos ( self , current_line_number ) : <EOL> hunks = diff_view_hunks [ self . view . id ( ) ] <EOL> if not hunks : <EOL> return <EOL> for hunk_ref in hunks : <EOL> if hunk_ref . section_start > current_line_number : <EOL> break <EOL> return self . view . text_point ( hunk_ref . section_start , <NUM_LIT:0> ) <EOL> class GsInlineDiffGotoPreviousHunk ( GsInlineDiffGotoBase ) : <EOL> """<STR_LIT>""" <EOL> def get_target_cursor_pos ( self , current_line_number ) : <EOL> hunks = diff_view_hunks [ self . view . id ( ) ] <EOL> previous_hunk_ref = None <EOL> for hunk_ref in hunks : <EOL> if hunk_ref . section_end < current_line_number : <EOL> previous_hunk_ref = hunk_ref <EOL> if previous_hunk_ref : <EOL> return self . view . text_point ( previous_hunk_ref . section_start , <NUM_LIT:0> ) <EOL> class GsInlineDiffUndo ( TextCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit ) : <EOL> sublime . set_timeout_async ( self . run_async , <NUM_LIT:0> ) <EOL> def run_async ( self ) : <EOL> history = self . view . settings ( ) . get ( "<STR_LIT>" ) or [ ] <EOL> if not history : <EOL> return <EOL> last_args , last_stdin = history . pop ( ) <EOL> last_args [ <NUM_LIT:2> ] = "<STR_LIT>" if not last_args [ <NUM_LIT:2> ] else None <EOL> self . git ( * last_args , stdin = last_stdin ) <EOL> self . view . settings ( ) . set ( "<STR_LIT>" , history ) <EOL> self . view . run_command ( "<STR_LIT>" ) </s>
