/* this scrolls the text so that cursor is on the screen */ void edit_scroll_screen_over_cursor (WEdit * edit) { int p; int outby; int b_extreme, t_extreme, l_extreme, r_extreme; if (edit->num_widget_lines <= 0 || edit->num_widget_columns <= 0) return; r_extreme = EDIT_RIGHT_EXTREME; l_extreme = EDIT_LEFT_EXTREME; b_extreme = EDIT_BOTTOM_EXTREME; t_extreme = EDIT_TOP_EXTREME; if (edit->found_len) { b_extreme = max (edit->num_widget_lines / 4, b_extreme); t_extreme = max (edit->num_widget_lines / 4, t_extreme); } if (b_extreme + t_extreme + 1 > edit->num_widget_lines) { int n; n = b_extreme + t_extreme; b_extreme = (b_extreme * (edit->num_widget_lines - 1)) / n; t_extreme = (t_extreme * (edit->num_widget_lines - 1)) / n; } if (l_extreme + r_extreme + 1 > edit->num_widget_columns) { int n; n = l_extreme + t_extreme; l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n; r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n; } p = edit_get_col (edit); edit_update_curs_row (edit); outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len); if (outby > 0) edit_scroll_right (edit, outby); outby = l_extreme - p - edit->start_col; if (outby > 0) edit_scroll_left (edit, outby); p = edit->curs_row; outby = p - edit->num_widget_lines + 1 + b_extreme; if (outby > 0) edit_scroll_downward (edit, outby); outby = t_extreme - p; if (outby > 0) edit_scroll_upward (edit, outby); edit_update_curs_row (edit); }
void format_paragraph (WEdit *edit, int force) { long p, q; int size; unsigned char *t; int indent = 0; if (option_word_wrap_line_length < 2) return; if (line_is_blank (edit, edit->curs_line)) return; p = begin_paragraph (edit, force); q = end_paragraph (edit, force); indent = test_indent (edit, p, q); t = get_paragraph (edit, p, q, indent, &size); if (!t) return; if (!force) { int i; if (strchr (NO_FORMAT_CHARS_START, *t)) { g_free (t); return; } for (i = 0; i < size - 1; i++) { if (t[i] == '\n') { if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) { g_free (t); return; } } } } format_this (t, q - p, indent); put_paragraph (edit, t, p, indent, size); g_free (t); /* Scroll left as much as possible to show the formatted paragraph */ edit_scroll_left (edit, -edit->start_col); }
/** this scrolls the text so that cursor is on the screen */ void edit_scroll_screen_over_cursor (WEdit * edit) { int p; int outby; int b_extreme, t_extreme, l_extreme, r_extreme; if (edit->widget.lines <= 0 || edit->widget.cols <= 0) return; edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; edit->widget.lines -= EDIT_TEXT_VERTICAL_OFFSET; r_extreme = EDIT_RIGHT_EXTREME; l_extreme = EDIT_LEFT_EXTREME; b_extreme = EDIT_BOTTOM_EXTREME; t_extreme = EDIT_TOP_EXTREME; if (edit->found_len) { b_extreme = max (edit->widget.lines / 4, b_extreme); t_extreme = max (edit->widget.lines / 4, t_extreme); } if (b_extreme + t_extreme + 1 > edit->widget.lines) { int n; n = b_extreme + t_extreme; if (n == 0) n = 1; b_extreme = (b_extreme * (edit->widget.lines - 1)) / n; t_extreme = (t_extreme * (edit->widget.lines - 1)) / n; } if (l_extreme + r_extreme + 1 > edit->widget.cols) { int n; n = l_extreme + t_extreme; if (n == 0) n = 1; l_extreme = (l_extreme * (edit->widget.cols - 1)) / n; r_extreme = (r_extreme * (edit->widget.cols - 1)) / n; } p = edit_get_col (edit) + edit->over_col; edit_update_curs_row (edit); outby = p + edit->start_col - edit->widget.cols + 1 + (r_extreme + edit->found_len); if (outby > 0) edit_scroll_right (edit, outby); outby = l_extreme - p - edit->start_col; if (outby > 0) edit_scroll_left (edit, outby); p = edit->curs_row; outby = p - edit->widget.lines + 1 + b_extreme; if (outby > 0) edit_scroll_downward (edit, outby); outby = t_extreme - p; if (outby > 0) edit_scroll_upward (edit, outby); edit_update_curs_row (edit); edit->widget.lines += EDIT_TEXT_VERTICAL_OFFSET; edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; }
void format_paragraph (WEdit * edit, gboolean force) { off_t p, q; off_t size; GString *t; long indent; unsigned char *t2; gboolean utf8 = FALSE; if (option_word_wrap_line_length < 2) return; if (edit_line_is_blank (edit, edit->buffer.curs_line)) return; p = begin_paragraph (edit, force); q = end_paragraph (edit, force); indent = test_indent (edit, p, q); t = get_paragraph (&edit->buffer, p, q, indent != 0); size = t->len - 1; if (!force) { off_t i; char *stop_format_chars; if (option_stop_format_chars != NULL && strchr (option_stop_format_chars, t->str[0]) != NULL) { g_string_free (t, TRUE); return; } if (option_stop_format_chars == NULL || *option_stop_format_chars == '\0') stop_format_chars = g_strdup ("\t"); else stop_format_chars = g_strconcat (option_stop_format_chars, "\t", (char *) NULL); for (i = 0; i < size - 1; i++) if (t->str[i] == '\n' && strchr (stop_format_chars, t->str[i + 1]) != NULL) { g_free (stop_format_chars); g_string_free (t, TRUE); return; } g_free (stop_format_chars); } t2 = (unsigned char *) g_string_free (t, FALSE); #ifdef HAVE_CHARSET utf8 = edit->utf8; #endif format_this (t2, q - p, indent, utf8); put_paragraph (edit, t2, p, indent, size); g_free ((char *) t2); /* Scroll left as much as possible to show the formatted paragraph */ edit_scroll_left (edit, -edit->start_col); }
void format_paragraph (WEdit * edit, gboolean force) { off_t p, q; long lines; off_t size; GString *t; long indent; unsigned char *t2; gboolean utf8 = FALSE; if (option_word_wrap_line_length < 2) return; if (edit_line_is_blank (edit, edit->buffer.curs_line)) return; p = begin_paragraph (edit, force, &lines); q = end_paragraph (edit, force); indent = test_indent (edit, p, q); t = get_paragraph (&edit->buffer, p, q, indent != 0); size = t->len - 1; if (!force) { off_t i; char *stop_format_chars; if (option_stop_format_chars != NULL && strchr (option_stop_format_chars, t->str[0]) != NULL) { g_string_free (t, TRUE); return; } if (option_stop_format_chars == NULL || *option_stop_format_chars == '\0') stop_format_chars = g_strdup ("\t"); else stop_format_chars = g_strconcat (option_stop_format_chars, "\t", (char *) NULL); for (i = 0; i < size - 1; i++) if (t->str[i] == '\n' && strchr (stop_format_chars, t->str[i + 1]) != NULL) { g_free (stop_format_chars); g_string_free (t, TRUE); return; } g_free (stop_format_chars); } t2 = (unsigned char *) g_string_free (t, FALSE); #ifdef HAVE_CHARSET utf8 = edit->utf8; #endif /* scroll up to show 1st line of paragraph */ edit_move_up (edit, lines, TRUE); /* scroll left as much as possible to show the formatted paragraph */ edit_scroll_left (edit, -edit->start_col); format_this (t2, q - p, indent, utf8); put_paragraph (edit, t2, p, indent, size); g_free ((char *) t2); /* move to the end of paragraph */ q = end_paragraph (edit, force); edit_cursor_move (edit, q - edit->buffer.curs1); /* try move to the start of next paragraph */ if (edit->buffer.curs_line < edit->buffer.lines) { edit_execute_cmd (edit, CK_Home, -1); do { edit_execute_cmd (edit, CK_Down, -1); } while (edit->buffer.curs_line < edit->buffer.lines && edit_line_is_blank (edit, edit->buffer.curs_line)); } }
/** this scrolls the text so that cursor is on the screen */ void edit_scroll_screen_over_cursor (WEdit * edit) { Widget *w = WIDGET (edit); long p; long outby; int b_extreme, t_extreme, l_extreme, r_extreme; if (w->lines <= 0 || w->cols <= 0) return; w->lines -= EDIT_TEXT_VERTICAL_OFFSET; w->cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; if (!edit->fullscreen) { w->x++; w->cols -= 2; w->y++; w->lines -= 2; } r_extreme = EDIT_RIGHT_EXTREME; l_extreme = EDIT_LEFT_EXTREME; b_extreme = EDIT_BOTTOM_EXTREME; t_extreme = EDIT_TOP_EXTREME; if (edit->found_len != 0) { b_extreme = max (w->lines / 4, b_extreme); t_extreme = max (w->lines / 4, t_extreme); } if (b_extreme + t_extreme + 1 > w->lines) { int n; n = b_extreme + t_extreme; if (n == 0) n = 1; b_extreme = (b_extreme * (w->lines - 1)) / n; t_extreme = (t_extreme * (w->lines - 1)) / n; } if (l_extreme + r_extreme + 1 > w->cols) { int n; n = l_extreme + t_extreme; if (n == 0) n = 1; l_extreme = (l_extreme * (w->cols - 1)) / n; r_extreme = (r_extreme * (w->cols - 1)) / n; } p = edit_get_col (edit) + edit->over_col; edit_update_curs_row (edit); outby = p + edit->start_col - w->cols + 1 + (r_extreme + edit->found_len); if (outby > 0) edit_scroll_right (edit, outby); outby = l_extreme - p - edit->start_col; if (outby > 0) edit_scroll_left (edit, outby); p = edit->curs_row; outby = p - w->lines + 1 + b_extreme; if (outby > 0) edit_scroll_downward (edit, outby); outby = t_extreme - p; if (outby > 0) edit_scroll_upward (edit, outby); edit_update_curs_row (edit); w->lines += EDIT_TEXT_VERTICAL_OFFSET; w->cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; if (!edit->fullscreen) { w->x--; w->cols += 2; w->y--; w->lines += 2; } }