Skip to content

Commit af8c067

Browse files
committed
try to get whole of current line
1 parent bbd7b78 commit af8c067

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

src/program.c

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -897,33 +897,65 @@ program_text_changed( GtkTextBuffer *buffer, Program *program )
897897
}
898898
}
899899

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+
900934
static void
901935
program_set_text( Program *program, const char *text, gboolean editable )
902936
{
903937
GtkTextView *text_view = GTK_TEXT_VIEW( program->text );
938+
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( text_view );
904939
guint text_hash = g_str_hash( text );
905940

906941
if( text_hash != program->text_hash ) {
907942
/* Stop ::changed from firing, we don't want it to update the
908943
* def browser filter.
909944
*/
910-
g_signal_handlers_block_by_func(
911-
gtk_text_view_get_buffer( text_view ),
945+
g_signal_handlers_block_by_func( text_buffer,
912946
G_CALLBACK( program_text_changed ), program );
947+
g_signal_handlers_block_by_func( text_buffer,
948+
G_CALLBACK( program_text_cursor_position ), program );
913949

914950
text_view_set_text( text_view, text, editable );
915951
program->text_hash = text_hash;
916952

917-
g_signal_handlers_unblock_by_func(
918-
gtk_text_view_get_buffer( text_view ),
953+
g_signal_handlers_unblock_by_func( text_buffer,
919954
G_CALLBACK( program_text_changed ), program );
955+
g_signal_handlers_unblock_by_func( text_buffer,
956+
G_CALLBACK( program_text_cursor_position ), program );
920957
}
921958

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-
927959
program->dirty = FALSE;
928960
}
929961

@@ -2368,6 +2400,10 @@ program_build( Program *program, GtkWidget *vbox )
23682400
gtk_text_view_get_buffer( GTK_TEXT_VIEW( program->text ) ),
23692401
"changed",
23702402
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 );
23712407
gtk_container_add( GTK_CONTAINER( swin ), program->text );
23722408
gtk_widget_show( program->text );
23732409

0 commit comments

Comments
 (0)