[geany/geany] 5bb0ca: Fix cursor position after comment toggling with no selection

Colomban Wendling git-noreply at geany.org
Thu Oct 11 22:15:29 UTC 2012


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Thu, 11 Oct 2012 22:15:29
Commit:      5bb0ca5a83fff906256d9924e8831f7c2bc24024
             https://github.com/geany/geany/commit/5bb0ca5a83fff906256d9924e8831f7c2bc24024

Log Message:
-----------
Fix cursor position after comment toggling with no selection

The implementation drops the non-selection code paths and simply makes
sure both caret and anchor are placed at the same position if there
was no selection.  This avoids having two completely different code
paths for things that are very similar -- and alternative code paths
were buggy.

Closes #3576431.


Modified Paths:
--------------
    src/editor.c

Modified: src/editor.c
54 files changed, 24 insertions(+), 30 deletions(-)
===================================================================
@@ -3133,46 +3133,40 @@ void editor_do_comment_toggle(GeanyEditor *editor)
 
 	co_len += tm_len;
 
-	/* restore selection if there is one */
-	if (sel_start < sel_end)
+	/* restore selection or caret position */
+	if (single_line)
 	{
-		if (single_line)
-		{
-			gint a = (first_line_was_comment) ? - co_len : co_len;
+		gint a = (first_line_was_comment) ? - co_len : co_len;
 
-			/* don't modify sel_start when the selection starts within indentation */
-			read_indent(editor, sel_start);
-			if ((sel_start - first_line_start) <= (gint) strlen(indent))
-				a = 0;
+		/* don't modify sel_start when the selection starts within indentation */
+		read_indent(editor, sel_start);
+		if ((sel_start - first_line_start) <= (gint) strlen(indent))
+			a = 0;
 
+		if (sel_start < sel_end)
+		{
 			sci_set_selection_start(editor->sci, sel_start + a);
 			sci_set_selection_end(editor->sci, sel_end +
 								(count_commented * co_len) - (count_uncommented * co_len));
 		}
 		else
-		{
-			gint eol_len = editor_get_eol_char_len(editor);
-			if (count_uncommented > 0)
-			{
-				sci_set_selection_start(editor->sci, sel_start - co_len + eol_len);
-				sci_set_selection_end(editor->sci, sel_end - co_len + eol_len);
-			}
-			else if (count_commented > 0)
-			{
-				sci_set_selection_start(editor->sci, sel_start + co_len - eol_len);
-				sci_set_selection_end(editor->sci, sel_end + co_len - eol_len);
-			}
-		}
+			sci_set_current_position(editor->sci, sel_start + a, TRUE);
 	}
-	else if (count_uncommented > 0)
-	{
-		gint eol_len = single_line ? 0: editor_get_eol_char_len(editor);
-		sci_set_current_position(editor->sci, sel_start - co_len + eol_len, TRUE);
-	}
-	else if (count_commented > 0)
+	else
 	{
-		gint eol_len = single_line ? 0: editor_get_eol_char_len(editor);
-		sci_set_current_position(editor->sci, sel_start + co_len - eol_len, TRUE);
+		gint eol_len = editor_get_eol_char_len(editor);
+		if (count_uncommented > 0)
+		{
+			sci_set_selection_start(editor->sci, sel_start - co_len + eol_len);
+			sci_set_selection_end(editor->sci, sel_end - co_len + eol_len);
+		}
+		else if (count_commented > 0)
+		{
+			sci_set_selection_start(editor->sci, sel_start + co_len - eol_len);
+			sci_set_selection_end(editor->sci, sel_end + co_len - eol_len);
+		}
+		if (sel_start >= sel_end)
+			sci_scroll_caret(editor->sci);
 	}
 }
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).


More information about the Commits mailing list