Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Jiří Techet techet@gmail.com Date: Mon, 22 May 2017 13:06:14 UTC Commit: 0c77ad778c84209ecf0237bd5f76162a619ef235 https://github.com/geany/geany-plugins/commit/0c77ad778c84209ecf0237bd5f7616...
Log Message: ----------- git-changebar: Don't rely on the caret position too much
Don't rely on the caret position when altering the document to undo a hunk, and use the hunk position itself instead.
This allows to use the same mechanism anywhere in the document regardless of the caret position, making the code more easily reusable.
Modified Paths: -------------- git-changebar/src/gcb-plugin.c
Modified: git-changebar/src/gcb-plugin.c 26 lines changed, 10 insertions(+), 16 deletions(-) =================================================================== @@ -123,7 +123,6 @@ struct UndoHunkData { guint doc_id; gint line; gboolean found; - gboolean first_line_removed; gint old_start; gint old_lines; gint new_start; @@ -1151,17 +1150,15 @@ undo_hunk_diff_hunk_cb (const git_diff_delta *delta, void *udata) { UndoHunkData *data = udata; - gboolean first_line_removed = is_first_line_removed (data->line, hunk->new_start, hunk->new_lines); - - if (first_line_removed || + + if (is_first_line_removed (data->line, hunk->new_start, hunk->new_lines) || (data->line >= hunk->new_start && data->line < hunk->new_start + MAX (1, hunk->new_lines))) { data->old_start = hunk->old_start; data->old_lines = hunk->old_lines; data->new_start = hunk->new_start; data->new_lines = hunk->new_lines; data->found = TRUE; - data->first_line_removed = first_line_removed; return 1; }
@@ -1180,33 +1177,30 @@ undo_hunk_cb (const gchar *path, diff_buf_to_doc (contents, doc, undo_hunk_diff_hunk_cb, data);
if (data->found) { - ScintillaObject *sci = doc->editor->sci; + ScintillaObject *sci = doc->editor->sci; + gint line = data->new_start - (data->new_lines ? 1 : 0);
sci_start_undo_action (sci);
if (data->new_lines > 0) { - gint pos = sci_get_position_from_line (sci, data->new_start - 1); + gint pos = sci_get_position_from_line (sci, line); sci_set_target_start (sci, pos); - pos = sci_get_position_from_line (sci, data->new_start + data->new_lines - 1); + pos = sci_get_position_from_line (sci, line + data->new_lines); sci_set_target_end (sci, pos); sci_replace_target (sci, "", FALSE); }
if (data->old_lines > 0) { - gint line = sci_get_current_line (sci); - gint pos; - - if (data->new_lines == 0 && !data->first_line_removed) { - line++; /* marker for deleted hunk is on previous line except the 1st line */ - } - pos = sci_get_position_from_line (sci, line); + gint pos = sci_get_position_from_line (sci, line);
insert_buf_range (doc, contents, pos, data->old_start - 1, data->old_lines); }
- sci_scroll_caret (sci); + scintilla_send_message (sci, SCI_SCROLLRANGE, + sci_get_position_from_line (sci, line + data->old_lines), + sci_get_position_from_line (sci, line));
sci_end_undo_action (sci); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org