[geany/geany] a5b99d: Add virtual column and selected chars to the statusbar

Dimitar Zhekov git-noreply at xxxxx
Tue Mar 3 19:07:11 UTC 2015


Branch:      refs/heads/master
Author:      Dimitar Zhekov <dimitar.zhekov at gmail.com>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Tue, 03 Mar 2015 19:07:11 UTC
Commit:      a5b99dc96dfed95bb08940e33b8ce5153f5069d5
             https://github.com/geany/geany/commit/a5b99dc96dfed95bb08940e33b8ce5153f5069d5

Log Message:
-----------
Add virtual column and selected chars to the statusbar

Closes https://sourceforge.net/p/geany/patches/10/


Modified Paths:
--------------
    doc/geany.txt
    src/sciwrappers.c
    src/sciwrappers.h
    src/ui_utils.c

Modified: doc/geany.txt
8 lines changed, 6 insertions(+), 2 deletions(-)
===================================================================
@@ -2693,10 +2693,14 @@ Placeholder   Description
 ============  ===========================================================
   ``%l``      The current line number starting at 1
   ``%L``      The total number of lines
-  ``%c``      The current column number starting at 0
-  ``%C``      The current column number starting at 1
+  ``%c``      The current column number starting at 0, including virtual
+              space.
+  ``%C``      The current column number starting at 1, including virtual
+              space.
   ``%s``      The number of selected characters or if only whole lines
               selected, the number of selected lines.
+  ``%n``      The number of selected characters, even if only whole lines
+              are selected.
   ``%w``      Shows ``RO`` when the document is in read-only mode,
               otherwise shows whether the editor is in overtype (OVR)
               or insert (INS) mode.


Modified: src/sciwrappers.c
11 lines changed, 11 insertions(+), 0 deletions(-)
===================================================================
@@ -398,6 +398,17 @@ gint sci_get_current_position(ScintillaObject *sci)
 }
 
 
+gint sci_get_cursor_virtual_space(ScintillaObject *sci)
+{
+	gint selection_mode = sci_get_selection_mode(sci);
+
+	return selection_mode == SC_SEL_RECTANGLE || selection_mode == SC_SEL_THIN ?
+		SSM(sci, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0) :
+		SSM(sci, SCI_GETSELECTIONNCARETVIRTUALSPACE,
+			SSM(sci, SCI_GETMAINSELECTION, 0, 0), 0);
+}
+
+
 /** Sets the cursor position.
  * @param sci Scintilla widget.
  * @param position Position.


Modified: src/sciwrappers.h
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -42,6 +42,7 @@ gint 				sci_get_col_from_position	(ScintillaObject *sci, gint position);
 gint 				sci_get_line_from_position	(ScintillaObject *sci, gint position);
 gint 				sci_get_position_from_line	(ScintillaObject *sci, gint line);
 gint 				sci_get_current_position	(ScintillaObject *sci);
+gint 				sci_get_cursor_virtual_space(ScintillaObject *sci);
 void 				sci_set_current_position	(ScintillaObject *sci, gint position, gboolean scroll_to_caret);
 
 gint				sci_get_selection_start		(ScintillaObject *sci);


Modified: src/ui_utils.c
19 lines changed, 12 insertions(+), 7 deletions(-)
===================================================================
@@ -185,7 +185,7 @@ void ui_set_statusbar(gboolean log, const gchar *format, ...)
 
 /* note: some comments below are for translators */
 static gchar *create_statusbar_statistics(GeanyDocument *doc,
-	guint line, guint col, guint pos)
+	guint line, guint vcol, guint pos)
 {
 	const gchar *cur_tag;
 	const gchar *fmt;
@@ -216,10 +216,10 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
 					sci_get_line_count(doc->editor->sci));
 				break;
 			case 'c':
-				g_string_append_printf(stats_str, "%d", col);
+				g_string_append_printf(stats_str, "%d", vcol);
 				break;
 			case 'C':
-				g_string_append_printf(stats_str, "%d", col + 1);
+				g_string_append_printf(stats_str, "%d", vcol + 1);
 				break;
 			case 'p':
 				g_string_append_printf(stats_str, "%u", pos);
@@ -238,6 +238,10 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
 						sci_get_lines_selected(doc->editor->sci) - 1);
 				break;
 			}
+			case 'n' :
+				g_string_append_printf(stats_str, "%d",
+					sci_get_selected_text_length(doc->editor->sci) - 1);
+				break;
 			case 'w':
 				/* RO = read-only */
 				g_string_append(stats_str, (doc->readonly) ? _("RO ") :
@@ -328,7 +332,7 @@ void ui_update_statusbar(GeanyDocument *doc, gint pos)
 
 	if (doc != NULL)
 	{
-		guint line, col;
+		guint line, vcol;
 		gchar *stats_str;
 
 		if (pos == -1)
@@ -339,11 +343,12 @@ void ui_update_statusbar(GeanyDocument *doc, gint pos)
 		 * when current pos is beyond document end (can occur when removing
 		 * blocks of selected lines especially esp. brace sections near end of file). */
 		if (pos <= sci_get_length(doc->editor->sci))
-			col = sci_get_col_from_position(doc->editor->sci, pos);
+			vcol = sci_get_col_from_position(doc->editor->sci, pos);
 		else
-			col = 0;
+			vcol = 0;
+		vcol += sci_get_cursor_virtual_space(doc->editor->sci);
 
-		stats_str = create_statusbar_statistics(doc, line, col, pos);
+		stats_str = create_statusbar_statistics(doc, line, vcol, pos);
 
 		/* can be overridden by status messages */
 		set_statusbar(stats_str, TRUE);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list