Skip to content

Commit 6fe1c6f

Browse files
committed
update def browser on cursor move
the def browser in the program window updates as you move the cursor about in the edit area
1 parent af8c067 commit 6fe1c6f

File tree

3 files changed

+19
-67
lines changed

3 files changed

+19
-67
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ started 7.31 3/9/12
44
- better definition of to_group (thanks MvGulik)
55
- better defintion of scan, renamed as scanl
66
- don't clear def browser filter on text buffer ::changed in program window
7+
- update filter on cursor move
78

89
started 7.30.1 7/8/12
910
- update rectangle select (thanks Joe)

TODO

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11

22
- new foldr1 def ... look for problems!
33

4-
- definition browser could update on cursor move?
5-
6-
eg. mouse click on contains_Group, or move cursor into contains_Group with
7-
kb, rhs changes to display contains_Group
4+
- breadcrumb trail for prog window, so you can get back to where you were?
85

96
- im_invertlut() as a menu item
107

src/program.c

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -846,57 +846,6 @@ is_ident( int ch )
846846
return( FALSE );
847847
}
848848

849-
static void
850-
program_text_changed( GtkTextBuffer *buffer, Program *program )
851-
{
852-
gboolean editable = !program->kit || !program->kit->pseudo;
853-
854-
if( !program->dirty ) {
855-
program->dirty = TRUE;
856-
program_refresh( program );
857-
}
858-
859-
if( program->rpane_open &&
860-
editable ) {
861-
/* Fetch characters left of the cursor while we have stuff
862-
* that could be an identifier.
863-
*/
864-
GtkTextIter start;
865-
GtkTextIter end;
866-
char *line;
867-
char *p;
868-
869-
/* Set iter at cursor.
870-
*/
871-
gtk_text_buffer_get_iter_at_mark( buffer,
872-
&end, gtk_text_buffer_get_insert( buffer ) );
873-
874-
/* Point an iter at the start of this line.
875-
*/
876-
gtk_text_buffer_get_iter_at_line_index( buffer,
877-
&start, gtk_text_iter_get_line( &end ), 0 );
878-
879-
line = gtk_text_buffer_get_text( buffer, &start, &end, FALSE );
880-
881-
/* Search back from the end of the string for the start of the
882-
* identifier.
883-
*/
884-
for( p = line + strlen( line ) - 1;
885-
p >= line && is_ident( *p );
886-
p-- )
887-
;
888-
889-
/* Don't update the filter for empty strings. This happens
890-
* when the user clicks between tools, not when they type
891-
* stuff.
892-
*/
893-
if( strcmp( p + 1, "" ) != 0 )
894-
defbrowser_set_filter( program->defbrowser, p + 1 );
895-
896-
g_free( line );
897-
}
898-
}
899-
900849
static void
901850
program_text_cursor_position( GtkTextBuffer *buffer, GParamSpec *pspec,
902851
Program *program )
@@ -912,20 +861,33 @@ program_text_cursor_position( GtkTextBuffer *buffer, GParamSpec *pspec,
912861
GtkTextIter cursor;
913862
GtkTextIter end;
914863
char *line;
915-
char *p;
864+
char *p, *q, *r;
916865

917866
/* Get iters for start / cursor / end of line.
918867
*/
919868
gtk_text_buffer_get_iter_at_mark( buffer,
920869
&cursor, gtk_text_buffer_get_insert( buffer ) );
921870
gtk_text_buffer_get_iter_at_line_index( buffer,
922-
&start, gtk_text_iter_get_line( &end ), 0 );
871+
&start, gtk_text_iter_get_line( &cursor ), 0 );
923872
gtk_text_buffer_get_iter_at_line_index( buffer,
924-
&end, gtk_text_iter_get_line( &end ), -1 );
873+
&end, gtk_text_iter_get_line( &cursor ), 0 );
874+
gtk_text_iter_forward_to_line_end( &end );
925875

926876
line = gtk_text_buffer_get_text( buffer, &start, &end, FALSE );
877+
p = line + gtk_text_iter_get_line_index( &cursor );
878+
879+
/* Search back from the cursor for the first non-identifier
880+
* char.
881+
*/
882+
for( q = p - 1; q >= line && is_ident( *q ); q-- )
883+
;
884+
q += 1;
885+
for( r = p; r < line + strlen( line ) && is_ident( *r ); r++ )
886+
;
887+
*r= '\0';
927888

928-
printf( "line = <%s>\n", line );
889+
if( strlen( q ) > 1 )
890+
defbrowser_set_filter( program->defbrowser, q );
929891

930892
g_free( line );
931893
}
@@ -942,16 +904,12 @@ program_set_text( Program *program, const char *text, gboolean editable )
942904
/* Stop ::changed from firing, we don't want it to update the
943905
* def browser filter.
944906
*/
945-
g_signal_handlers_block_by_func( text_buffer,
946-
G_CALLBACK( program_text_changed ), program );
947907
g_signal_handlers_block_by_func( text_buffer,
948908
G_CALLBACK( program_text_cursor_position ), program );
949909

950910
text_view_set_text( text_view, text, editable );
951911
program->text_hash = text_hash;
952912

953-
g_signal_handlers_unblock_by_func( text_buffer,
954-
G_CALLBACK( program_text_changed ), program );
955913
g_signal_handlers_unblock_by_func( text_buffer,
956914
G_CALLBACK( program_text_cursor_position ), program );
957915
}
@@ -2396,10 +2354,6 @@ program_build( Program *program, GtkWidget *vbox )
23962354
gtk_widget_show( swin );
23972355

23982356
program->text = program_text_new();
2399-
g_signal_connect(
2400-
gtk_text_view_get_buffer( GTK_TEXT_VIEW( program->text ) ),
2401-
"changed",
2402-
G_CALLBACK( program_text_changed ), program );
24032357
g_signal_connect(
24042358
gtk_text_view_get_buffer( GTK_TEXT_VIEW( program->text ) ),
24052359
"notify::cursor-position",

0 commit comments

Comments
 (0)