mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 12:31:45 +08:00
No re-position when inserting string in the middle
This commit is contained in:
parent
d466ec6213
commit
aa1ef33ed8
@ -187,7 +187,7 @@ static void tty_puts(const char *p)
|
|||||||
tty_put(*p++);
|
tty_put(*p++);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tty_show(unsigned char c)
|
static size_t tty_show(unsigned char c)
|
||||||
{
|
{
|
||||||
if (c == DEL) {
|
if (c == DEL) {
|
||||||
tty_put('^');
|
tty_put('^');
|
||||||
@ -208,9 +208,9 @@ static int tty_show(unsigned char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tty_string(char *p)
|
static size_t tty_string(char *p)
|
||||||
{
|
{
|
||||||
int n = 0;
|
size_t n = 0;
|
||||||
while (*p)
|
while (*p)
|
||||||
n += tty_show(*p++);
|
n += tty_show(*p++);
|
||||||
return n;
|
return n;
|
||||||
@ -501,6 +501,7 @@ static void clear_line(void)
|
|||||||
static el_status_t insert_string(const char *p)
|
static el_status_t insert_string(const char *p)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
size_t bk;
|
||||||
int i;
|
int i;
|
||||||
char *line;
|
char *line;
|
||||||
char *q;
|
char *q;
|
||||||
@ -526,10 +527,12 @@ static el_status_t insert_string(const char *p)
|
|||||||
memcpy(&rl_line_buffer[rl_point], p, len);
|
memcpy(&rl_line_buffer[rl_point], p, len);
|
||||||
rl_end += len;
|
rl_end += len;
|
||||||
rl_line_buffer[rl_end] = '\0';
|
rl_line_buffer[rl_end] = '\0';
|
||||||
tty_string(&rl_line_buffer[rl_point]);
|
bk = tty_string(&rl_line_buffer[rl_point]);
|
||||||
rl_point += len;
|
rl_point += len;
|
||||||
|
if (bk > len)
|
||||||
|
tty_backn(bk-len);
|
||||||
|
|
||||||
return rl_point == rl_end ? CSstay : CSmove;
|
return CSstay;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rl_insert_text(const char *text)
|
int rl_insert_text(const char *text)
|
||||||
@ -757,6 +760,7 @@ static el_status_t delete_string(int count)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
|
size_t bk;
|
||||||
|
|
||||||
if (count <= 0 || rl_end == rl_point)
|
if (count <= 0 || rl_end == rl_point)
|
||||||
return el_ring_bell();
|
return el_ring_bell();
|
||||||
@ -790,8 +794,8 @@ static el_status_t delete_string(int count)
|
|||||||
p[0] = p[count];
|
p[0] = p[count];
|
||||||
ceol();
|
ceol();
|
||||||
rl_end -= count;
|
rl_end -= count;
|
||||||
i = tty_string(&rl_line_buffer[rl_point]);
|
bk = tty_string(&rl_line_buffer[rl_point]);
|
||||||
tty_backn(i);
|
tty_backn(bk);
|
||||||
|
|
||||||
return CSstay;
|
return CSstay;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user