From faae3bfc6462009405b5e97a8e21e7803386cc9f Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 22 May 2002 04:19:22 +0000 Subject: [PATCH] Fix hiliting of matched strings to better match the returned matched * src/vte.c: Fix hiliting of matched strings to better match the returned matched string in match_check(). --- ChangeLog | 4 ++++ README | 2 -- src/vte.c | 71 +++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55d74b8d..5ccc0dde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ +2002-05-22 nalin + * src/vte.c: Fix hiliting of matched strings. + 2002-05-21 nalin * src/vte.c: Filter key release events through input methods. (Patch from otaylor.) When building with gcc, use -std=c99. + 2002-05-21 nalin * autogen.sh, src/termcap.c, src/utf8echo.c, src/vte.c: Patch from Hidetoshi Tajima to fix building on Solaris systems, remove use of diff --git a/README b/README index 5351abb2..b8e7d324 100644 --- a/README +++ b/README @@ -29,8 +29,6 @@ - Currently doesn't handle children exiting quite right (if the child spawned a background process which keeps its stdio open, we don't close because we don't get an EOF). -- Small dingus bug -- if the string is at the end of the buffer, too much - is hilited. - Sequence matching is greedy, so that C=AB matches C and not A and then B. - Bold doesn't work right if the default foreground color isn't gray. Need to move to 20-color palette to fix this right. diff --git a/src/vte.c b/src/vte.c index 1a0269f3..17315852 100644 --- a/src/vte.c +++ b/src/vte.c @@ -130,7 +130,9 @@ struct _VteTerminalPrivate { const char *shell; /* shell we started */ int pty_master; /* pty master descriptor */ GIOChannel *pty_input; /* master input watch */ + int pty_input_tag; GIOChannel *pty_output; /* master output watch */ + int pty_output_tag; pid_t pty_pid; /* pid of child using pty slave */ const char *encoding; /* the pty's encoding */ const char *gxencoding[4]; /* alternate encodings */ @@ -783,9 +785,9 @@ vte_terminal_match_check_int(VteTerminal *terminal, long column, vte_terminal_match_contents_refresh(terminal); } /* Map the pointer position to a portion of the string. */ - for (offset = 0; - offset < terminal->pvt->match_attributes->len; - offset++) { + for (offset = terminal->pvt->match_attributes->len - 1; + offset >= 0; + offset--) { attr = &g_array_index(terminal->pvt->match_attributes, struct vte_char_attributes, offset); @@ -795,8 +797,17 @@ vte_terminal_match_check_int(VteTerminal *terminal, long column, } } } +#ifdef VTE_DEBUG + if (vte_debug_on(VTE_DEBUG_EVENTS)) { + if (offset < 0) { + fprintf(stderr, "Cursor is not on a character.\n"); + } else { + fprintf(stderr, "Cursor is on character %d.\n", offset); + } + } +#endif /* If the pointer isn't on a matchable character, bug out. */ - if (offset >= terminal->pvt->match_attributes->len) { + if (offset < 0) { return NULL; } /* If the pointer is on a newline, bug out. */ @@ -838,13 +849,13 @@ vte_terminal_match_check_int(VteTerminal *terminal, long column, matches[j].rm_so + coffset); eattr = &g_array_index(terminal->pvt->match_attributes, struct vte_char_attributes, - matches[j].rm_eo + coffset); + matches[j].rm_eo + coffset - 1); fprintf(stderr, "Match %d `%s' from %d(%ld,%ld) to %d(%ld,%ld) (%d).\n", j, match, matches[j].rm_so + coffset, sattr->column, sattr->row, - matches[j].rm_eo + coffset, + matches[j].rm_eo + coffset - 1, eattr->column, eattr->row, offset); @@ -855,7 +866,7 @@ vte_terminal_match_check_int(VteTerminal *terminal, long column, /* If the pointer is in this substring, * then we're done. */ if ((offset >= matches[j].rm_so + coffset) && - (offset <= matches[j].rm_eo + coffset)) { + (offset < matches[j].rm_eo + coffset)) { if (tag != NULL) { *tag = regex->tag; } @@ -863,7 +874,7 @@ vte_terminal_match_check_int(VteTerminal *terminal, long column, *start = matches[j].rm_so + coffset; } if (end != NULL) { - *end = matches[j].rm_eo + coffset; + *end = matches[j].rm_eo + coffset - 1; } return g_strndup(terminal->pvt->match_contents + matches[j].rm_so + coffset, matches[j].rm_eo - matches[j].rm_so); @@ -4879,12 +4890,13 @@ vte_terminal_fork_command(VteTerminal *terminal, const char *command, terminal->pvt->pty_input = g_io_channel_unix_new(terminal->pvt->pty_master); terminal->pvt->pty_output = NULL; - g_io_add_watch_full(terminal->pvt->pty_input, - G_PRIORITY_LOW, - G_IO_IN | G_IO_HUP, - vte_terminal_io_read, - terminal, - NULL); + terminal->pvt->pty_input_tag = + g_io_add_watch_full(terminal->pvt->pty_input, + G_PRIORITY_LOW, + G_IO_IN | G_IO_HUP, + vte_terminal_io_read, + terminal, + NULL); g_io_channel_unref(terminal->pvt->pty_input); } @@ -4905,6 +4917,8 @@ vte_terminal_eof(GIOChannel *channel, gpointer data) * has already been dereferenced. */ if (channel == terminal->pvt->pty_input) { terminal->pvt->pty_input = NULL; + g_source_remove(terminal->pvt->pty_input_tag); + terminal->pvt->pty_input_tag = -1; } /* Emit a signal that we read an EOF. */ @@ -5561,6 +5575,8 @@ vte_terminal_io_write(GIOChannel *channel, if (terminal->pvt->n_outgoing == 0) { if (channel == terminal->pvt->pty_output) { terminal->pvt->pty_output = NULL; + g_source_remove(terminal->pvt->pty_output_tag); + terminal->pvt->pty_output_tag = -1; } leave_open = FALSE; } else { @@ -5617,12 +5633,13 @@ vte_terminal_send(VteTerminal *terminal, const char *encoding, if (terminal->pvt->pty_output == NULL) { terminal->pvt->pty_output = g_io_channel_unix_new(terminal->pvt->pty_master); - g_io_add_watch_full(terminal->pvt->pty_output, - G_PRIORITY_HIGH, - G_IO_OUT, - vte_terminal_io_write, - terminal, - NULL); + terminal->pvt->pty_output_tag = + g_io_add_watch_full(terminal->pvt->pty_output, + G_PRIORITY_HIGH, + G_IO_OUT, + vte_terminal_io_write, + terminal, + NULL); g_io_channel_unref(terminal->pvt->pty_output); } } @@ -6489,8 +6506,8 @@ vte_terminal_match_hilite(VteTerminal *terminal, double x, double y) } /* Check for matches. */ match = vte_terminal_match_check_int(terminal, - x / terminal->char_width, - y / terminal->char_height, + floor(x) / terminal->char_width, + floor(y) / terminal->char_height, NULL, &start, &end); @@ -6690,7 +6707,7 @@ vte_terminal_copy_cb(GtkClipboard *clipboard, GtkSelectionData *data, } } -/* Extract a view of the widget as if we were goint to copy it. */ +/* Extract a view of the widget as if we were going to copy it. */ char * vte_terminal_get_text(VteTerminal *terminal, gboolean(*is_selected)(VteTerminal *, long, long), @@ -8254,10 +8271,14 @@ vte_terminal_finalize(GObject *object) if (terminal->pvt->pty_input != NULL) { g_io_channel_unref(terminal->pvt->pty_input); terminal->pvt->pty_input = NULL; + g_source_remove(terminal->pvt->pty_input_tag); + terminal->pvt->pty_input_tag = -1; } if (terminal->pvt->pty_output != NULL) { g_io_channel_unref(terminal->pvt->pty_output); terminal->pvt->pty_output = NULL; + g_source_remove(terminal->pvt->pty_output_tag); + terminal->pvt->pty_output_tag = -1; } /* Discard any pending data. */ @@ -9237,13 +9258,13 @@ vte_terminal_draw_char(VteTerminal *terminal, ((row == terminal->pvt->match_start.row) && (row == terminal->pvt->match_end.row) && (col >= terminal->pvt->match_start.column) && - (col < terminal->pvt->match_end.column)) || + (col <= terminal->pvt->match_end.column)) || ((row == terminal->pvt->match_start.row) && (row != terminal->pvt->match_end.row) && (col >= terminal->pvt->match_start.column)) || ((row == terminal->pvt->match_end.row) && (row != terminal->pvt->match_start.row) && - (col < terminal->pvt->match_end.column))) { + (col <= terminal->pvt->match_end.column))) { XSetForeground(display, gc, terminal->pvt->palette[fore].pixel); XDrawLine(display, drawable, gc, -- 2.20.1