tled: decide cursor insertion position by inserting an 'a' - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 9724b248644e35bd73ecf9fa0a2adae08f372f14
(DIR) parent a7405155b28f15f29b2171d175e317be66f785e1
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Mon, 18 May 2015 12:05:24 +0430
led: decide cursor insertion position by inserting an 'a'
Diffstat:
M led.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
---
(DIR) diff --git a/led.c b/led.c
t@@ -106,24 +106,25 @@ static void led_printparts(char *ai, char *pref, char *main, char *post)
{
struct sbuf *ln;
int off, pos;
+ int idir = 0;
ln = sbuf_make();
sbuf_str(ln, ai);
sbuf_str(ln, pref);
sbuf_str(ln, main);
off = uc_slen(sbuf_buf(ln));
/* cursor position for inserting the next character */
- if (post[0] && post[0] != '\n') {
- sbuf_str(ln, post);
- pos = ren_cursor(sbuf_buf(ln), ren_pos(sbuf_buf(ln), off));
- } else {
+ if (*pref || *main || *ai) {
int len = sbuf_len(ln);
sbuf_str(ln, keymap(led_kmap, 'a'));
- pos = ren_cursor(sbuf_buf(ln), ren_pos(sbuf_buf(ln), off));
- sbuf_cut(ln, len);
sbuf_str(ln, post);
+ idir = ren_pos(sbuf_buf(ln), off) -
+ ren_pos(sbuf_buf(ln), off - 1) < 0 ? -1 : +1;
+ sbuf_cut(ln, len);
}
+ sbuf_str(ln, post);
led_print(sbuf_buf(ln), -1);
- term_pos(-1, led_pos(sbuf_buf(ln), pos));
+ pos = ren_cursor(sbuf_buf(ln), ren_pos(sbuf_buf(ln), off - 1));
+ term_pos(-1, led_pos(sbuf_buf(ln), pos + idir));
sbuf_free(ln);
}