@@ -897,33 +897,65 @@ program_text_changed( GtkTextBuffer *buffer, Program *program )
897
897
}
898
898
}
899
899
900
+ static void
901
+ program_text_cursor_position ( GtkTextBuffer * buffer , GParamSpec * pspec ,
902
+ Program * program )
903
+ {
904
+ gboolean editable = !program -> kit || !program -> kit -> pseudo ;
905
+
906
+ if ( program -> rpane_open &&
907
+ editable ) {
908
+ /* Fetch characters left of the cursor while we have stuff
909
+ * that could be an identifier.
910
+ */
911
+ GtkTextIter start ;
912
+ GtkTextIter cursor ;
913
+ GtkTextIter end ;
914
+ char * line ;
915
+ char * p ;
916
+
917
+ /* Get iters for start / cursor / end of line.
918
+ */
919
+ gtk_text_buffer_get_iter_at_mark ( buffer ,
920
+ & cursor , gtk_text_buffer_get_insert ( buffer ) );
921
+ gtk_text_buffer_get_iter_at_line_index ( buffer ,
922
+ & start , gtk_text_iter_get_line ( & end ), 0 );
923
+ gtk_text_buffer_get_iter_at_line_index ( buffer ,
924
+ & end , gtk_text_iter_get_line ( & end ), -1 );
925
+
926
+ line = gtk_text_buffer_get_text ( buffer , & start , & end , FALSE );
927
+
928
+ printf ( "line = <%s>\n" , line );
929
+
930
+ g_free ( line );
931
+ }
932
+ }
933
+
900
934
static void
901
935
program_set_text ( Program * program , const char * text , gboolean editable )
902
936
{
903
937
GtkTextView * text_view = GTK_TEXT_VIEW ( program -> text );
938
+ GtkTextBuffer * text_buffer = gtk_text_view_get_buffer ( text_view );
904
939
guint text_hash = g_str_hash ( text );
905
940
906
941
if ( text_hash != program -> text_hash ) {
907
942
/* Stop ::changed from firing, we don't want it to update the
908
943
* def browser filter.
909
944
*/
910
- g_signal_handlers_block_by_func (
911
- gtk_text_view_get_buffer ( text_view ),
945
+ g_signal_handlers_block_by_func ( text_buffer ,
912
946
G_CALLBACK ( program_text_changed ), program );
947
+ g_signal_handlers_block_by_func ( text_buffer ,
948
+ G_CALLBACK ( program_text_cursor_position ), program );
913
949
914
950
text_view_set_text ( text_view , text , editable );
915
951
program -> text_hash = text_hash ;
916
952
917
- g_signal_handlers_unblock_by_func (
918
- gtk_text_view_get_buffer ( text_view ),
953
+ g_signal_handlers_unblock_by_func ( text_buffer ,
919
954
G_CALLBACK ( program_text_changed ), program );
955
+ g_signal_handlers_unblock_by_func ( text_buffer ,
956
+ G_CALLBACK ( program_text_cursor_position ), program );
920
957
}
921
958
922
- g_signal_connect (
923
- gtk_text_view_get_buffer ( GTK_TEXT_VIEW ( program -> text ) ),
924
- "changed" ,
925
- G_CALLBACK ( program_text_changed ), program );
926
-
927
959
program -> dirty = FALSE;
928
960
}
929
961
@@ -2368,6 +2400,10 @@ program_build( Program *program, GtkWidget *vbox )
2368
2400
gtk_text_view_get_buffer ( GTK_TEXT_VIEW ( program -> text ) ),
2369
2401
"changed" ,
2370
2402
G_CALLBACK ( program_text_changed ), program );
2403
+ g_signal_connect (
2404
+ gtk_text_view_get_buffer ( GTK_TEXT_VIEW ( program -> text ) ),
2405
+ "notify::cursor-position" ,
2406
+ G_CALLBACK ( program_text_cursor_position ), program );
2371
2407
gtk_container_add ( GTK_CONTAINER ( swin ), program -> text );
2372
2408
gtk_widget_show ( program -> text );
2373
2409
0 commit comments