* Fixed flush_text_buffer() function. It always assumed a newline at the end and...
authorMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Fri, 22 May 2009 10:38:41 +0000 (10:38 +0000)
committerMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Fri, 22 May 2009 10:38:41 +0000 (10:38 +0000)
git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@67 ddfedd41-794f-dd11-ae45-00112f111e67

src/input.c

index 418e5ea1f6b2e82b6a662e40887054c146a3d345..89356fae2ff913d8f9a6c07e085ca9556dad067a 100644 (file)
@@ -450,15 +450,22 @@ flush_text_buffer(winid_t win)
        VALID_WINDOW(win, return 0);
        g_return_val_if_fail(win->type == wintype_TextBuffer, 0);
 
-       GtkTextIter start_iter, end_iter;
+       GtkTextIter start_iter, end_iter, last_character;
 
        GtkTextBuffer *window_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
        GtkTextMark *input_position = gtk_text_buffer_get_mark(window_buffer, "input_position");
        gtk_text_buffer_get_iter_at_mark(window_buffer, &start_iter, input_position);
        gtk_text_buffer_get_end_iter(window_buffer, &end_iter);
-       gtk_text_iter_backward_cursor_position(&end_iter); /* don't include \n */
-       
+       gtk_text_buffer_get_end_iter(window_buffer, &last_character);
+       gtk_text_iter_backward_cursor_position(&last_character);
+
+       gchar* last_char = gtk_text_buffer_get_text(window_buffer, &last_character, &end_iter, FALSE);
+
+       if( strchr(last_char, '\n') != NULL )
+               gtk_text_iter_backward_cursor_position(&end_iter);
+
        gchar* inserted_text = gtk_text_buffer_get_text(window_buffer, &start_iter, &end_iter, FALSE);
+
        int chars_written = write_to_window_buffer(win, inserted_text);
        g_free(inserted_text);