[gcalctool] Correct whitespace removal with super/subscript buttons (bug #632666)
- From: Robin Sonefors <rsonefors src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Correct whitespace removal with super/subscript buttons (bug #632666)
- Date: Tue, 26 Oct 2010 11:17:44 +0000 (UTC)
commit bb430ce5f1e57174c40f6397f3c78c889d82596d
Author: Robin Sonefors <ozamosi flukkost nu>
Date: Tue Oct 26 13:09:33 2010 +0200
Correct whitespace removal with super/subscript buttons (bug #632666)
src/math-buttons.c | 27 +++++++++++++++++++++------
1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/src/math-buttons.c b/src/math-buttons.c
index 967c09f..3da1e8d 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -1741,6 +1741,21 @@ bit_toggle_cb(GtkWidget *event_box, GdkEventButton *event, MathButtons *buttons)
}
+static void
+remove_trailing_spaces(MathButtons *buttons)
+{
+ GtkTextMark *insert_mark;
+ GtkTextIter start, end;
+ insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER(buttons->priv->equation));
+ gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(buttons->priv->equation), &end, insert_mark);
+ start = end;
+ while (gtk_text_iter_backward_char(&start)) {
+ if (!g_unichar_isspace(gtk_text_iter_get_char(&start)))
+ break;
+ gtk_text_buffer_delete(GTK_TEXT_BUFFER(buttons->priv->equation), &start, &end);
+ }
+}
+
void set_superscript_cb(GtkWidget *widget, MathButtons *buttons);
G_MODULE_EXPORT
@@ -1748,10 +1763,10 @@ void
set_superscript_cb(GtkWidget *widget, MathButtons *buttons)
{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
- char* display;
math_equation_set_number_mode(buttons->priv->equation, SUPERSCRIPT);
- display = math_equation_get_display(buttons->priv->equation);
- math_equation_set(buttons->priv->equation, g_strchomp(display));
+ if (!gtk_text_buffer_get_has_selection(GTK_TEXT_BUFFER(buttons->priv->equation))) {
+ remove_trailing_spaces(buttons);
+ }
}
else if (math_equation_get_number_mode(buttons->priv->equation) == SUPERSCRIPT)
math_equation_set_number_mode(buttons->priv->equation, NORMAL);
@@ -1764,10 +1779,10 @@ void
set_subscript_cb(GtkWidget *widget, MathButtons *buttons)
{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
- char* display;
math_equation_set_number_mode(buttons->priv->equation, SUBSCRIPT);
- display = math_equation_get_display(buttons->priv->equation);
- math_equation_set(buttons->priv->equation, g_strchomp(display));
+ if (!gtk_text_buffer_get_has_selection(GTK_TEXT_BUFFER(buttons->priv->equation))) {
+ remove_trailing_spaces(buttons);
+ }
}
else if (math_equation_get_number_mode(buttons->priv->equation) == SUBSCRIPT)
math_equation_set_number_mode(buttons->priv->equation, NORMAL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]