mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Ticket #1666: fix paragraph formatting.
1st line was shifted after paragraph format. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
b7209c0c76
commit
ccb7ab341e
@ -123,7 +123,7 @@ bad_line_start (const edit_buffer_t * buf, off_t p)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static off_t
|
static off_t
|
||||||
begin_paragraph (WEdit * edit, gboolean force)
|
begin_paragraph (WEdit * edit, gboolean force, long *lines)
|
||||||
{
|
{
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
@ -135,8 +135,10 @@ begin_paragraph (WEdit * edit, gboolean force)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*lines = edit->buffer.curs_line - i;
|
||||||
|
|
||||||
return edit_buffer_move_backward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer),
|
return edit_buffer_move_backward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer),
|
||||||
edit->buffer.curs_line - i);
|
*lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -448,7 +450,6 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, long indent, off_t size)
|
|||||||
if (c != t[i])
|
if (c != t[i])
|
||||||
replace_at (edit, p, t[i]);
|
replace_at (edit, p, t[i]);
|
||||||
}
|
}
|
||||||
edit_cursor_move (edit, cursor - edit->buffer.curs1); /* restore cursor position */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -477,6 +478,7 @@ void
|
|||||||
format_paragraph (WEdit * edit, gboolean force)
|
format_paragraph (WEdit * edit, gboolean force)
|
||||||
{
|
{
|
||||||
off_t p, q;
|
off_t p, q;
|
||||||
|
long lines;
|
||||||
off_t size;
|
off_t size;
|
||||||
GString *t;
|
GString *t;
|
||||||
long indent;
|
long indent;
|
||||||
@ -488,7 +490,7 @@ format_paragraph (WEdit * edit, gboolean force)
|
|||||||
if (edit_line_is_blank (edit, edit->buffer.curs_line))
|
if (edit_line_is_blank (edit, edit->buffer.curs_line))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p = begin_paragraph (edit, force);
|
p = begin_paragraph (edit, force, &lines);
|
||||||
q = end_paragraph (edit, force);
|
q = end_paragraph (edit, force);
|
||||||
indent = test_indent (edit, p, q);
|
indent = test_indent (edit, p, q);
|
||||||
|
|
||||||
@ -527,12 +529,31 @@ format_paragraph (WEdit * edit, gboolean force)
|
|||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
utf8 = edit->utf8;
|
utf8 = edit->utf8;
|
||||||
#endif
|
#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);
|
format_this (t2, q - p, indent, utf8);
|
||||||
put_paragraph (edit, t2, p, indent, size);
|
put_paragraph (edit, t2, p, indent, size);
|
||||||
g_free ((char *) t2);
|
g_free ((char *) t2);
|
||||||
|
|
||||||
/* Scroll left as much as possible to show the formatted paragraph */
|
/* move to the end of paragraph */
|
||||||
edit_scroll_left (edit, -edit->start_col);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user