mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 04:26:50 +03:00
Move line start calc into reflow handler.
This commit is contained in:
parent
b23c580f33
commit
b603cafbaa
@ -842,16 +842,17 @@ static bool textarea_reflow_singleline(struct textarea *ta, size_t b_off,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflow a text area from the given line onwards
|
* Reflow a multiline textarea from the given line onwards
|
||||||
*
|
*
|
||||||
* \param ta Textarea to reflow
|
* \param ta Textarea to reflow
|
||||||
* \param start Line number to begin reflow on
|
* \param b_start 0-based byte offset in ta->text to start of modification
|
||||||
* \return true on success false otherwise
|
* \return true on success false otherwise
|
||||||
*/
|
*/
|
||||||
static bool textarea_reflow_multiline(struct textarea *ta, unsigned int start)
|
static bool textarea_reflow_multiline(struct textarea *ta, size_t b_start)
|
||||||
{
|
{
|
||||||
char *text;
|
char *text;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
unsigned int start;
|
||||||
size_t b_off;
|
size_t b_off;
|
||||||
int x;
|
int x;
|
||||||
char *space, *para_end;
|
char *space, *para_end;
|
||||||
@ -874,14 +875,16 @@ static bool textarea_reflow_multiline(struct textarea *ta, unsigned int start)
|
|||||||
ta->lines_alloc_size = LINE_CHUNK_SIZE;
|
ta->lines_alloc_size = LINE_CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get line of start of changes */
|
||||||
|
for (start = 0; (signed) start < ta->line_count - 1; start++)
|
||||||
|
if (ta->lines[start + 1].b_start > b_start)
|
||||||
|
break;
|
||||||
|
|
||||||
/* Find max number of lines before vertical scrollbar is required */
|
/* Find max number of lines before vertical scrollbar is required */
|
||||||
scroll_lines = (ta->vis_height - 2 * ta->border_width -
|
scroll_lines = (ta->vis_height - 2 * ta->border_width -
|
||||||
ta->pad_top - ta->pad_bottom) /
|
ta->pad_top - ta->pad_bottom) /
|
||||||
ta->line_height;
|
ta->line_height;
|
||||||
|
|
||||||
if ((signed)start > ta->line_count)
|
|
||||||
start = 0;
|
|
||||||
|
|
||||||
/* Have to start on line before where the changes are in case an
|
/* Have to start on line before where the changes are in case an
|
||||||
* added space makes the text before the space on a soft-wrapped line
|
* added space makes the text before the space on a soft-wrapped line
|
||||||
* fit on the line above */
|
* fit on the line above */
|
||||||
@ -1177,7 +1180,7 @@ static bool textarea_set_caret_xy(struct textarea *ta, int x, int y,
|
|||||||
static bool textarea_insert_text(struct textarea *ta, const char *text,
|
static bool textarea_insert_text(struct textarea *ta, const char *text,
|
||||||
size_t b_off, size_t b_len, int *byte_delta, struct rect *r)
|
size_t b_off, size_t b_len, int *byte_delta, struct rect *r)
|
||||||
{
|
{
|
||||||
int char_delta, line;
|
int char_delta;
|
||||||
const size_t show_b_off = b_off;
|
const size_t show_b_off = b_off;
|
||||||
|
|
||||||
if (ta->flags & TEXTAREA_READONLY)
|
if (ta->flags & TEXTAREA_READONLY)
|
||||||
@ -1233,10 +1236,7 @@ static bool textarea_insert_text(struct textarea *ta, const char *text,
|
|||||||
|
|
||||||
/* See to reflow */
|
/* See to reflow */
|
||||||
if (ta->flags & TEXTAREA_MULTILINE) {
|
if (ta->flags & TEXTAREA_MULTILINE) {
|
||||||
for (line = 0; line < ta->line_count - 1; line++)
|
if (!textarea_reflow_multiline(ta, show_b_off))
|
||||||
if (ta->lines[line + 1].b_start > b_off)
|
|
||||||
break;
|
|
||||||
if (!textarea_reflow_multiline(ta, line))
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (!textarea_reflow_singleline(ta, show_b_off, r))
|
if (!textarea_reflow_singleline(ta, show_b_off, r))
|
||||||
@ -1294,7 +1294,7 @@ static bool textarea_replace_text(struct textarea *ta, size_t b_start,
|
|||||||
size_t b_end, const char *rep, size_t rep_len,
|
size_t b_end, const char *rep, size_t rep_len,
|
||||||
bool add_to_clipboard, int *byte_delta, struct rect *r)
|
bool add_to_clipboard, int *byte_delta, struct rect *r)
|
||||||
{
|
{
|
||||||
int char_delta, line;
|
int char_delta;
|
||||||
const size_t show_b_off = b_start;
|
const size_t show_b_off = b_start;
|
||||||
*byte_delta = 0;
|
*byte_delta = 0;
|
||||||
|
|
||||||
@ -1388,10 +1388,7 @@ static bool textarea_replace_text(struct textarea *ta, size_t b_start,
|
|||||||
|
|
||||||
/* See to reflow */
|
/* See to reflow */
|
||||||
if (ta->flags & TEXTAREA_MULTILINE) {
|
if (ta->flags & TEXTAREA_MULTILINE) {
|
||||||
for (line = 0; line < ta->line_count - 1; line++)
|
if (!textarea_reflow_multiline(ta, b_start))
|
||||||
if (ta->lines[line + 1].b_start > b_start)
|
|
||||||
break;
|
|
||||||
if (!textarea_reflow_multiline(ta, line))
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (!textarea_reflow_singleline(ta, show_b_off, r))
|
if (!textarea_reflow_singleline(ta, show_b_off, r))
|
||||||
|
Loading…
Reference in New Issue
Block a user