From aea64adbb9ff755be303515bebb428d92e7bcc92 Mon Sep 17 00:00:00 2001 From: Darkvater Date: Mon, 5 Mar 2007 00:34:48 +0000 Subject: (svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset --- src/misc_gui.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/misc_gui.cpp') diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 306289eab..406cd72be 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -804,17 +804,21 @@ static void DelChar(Textbuf *tb, bool backspace) WChar c; uint width; size_t len; + char *s = tb->buf + tb->caretpos; - if (backspace) tb->caretpos -= Utf8PrevCharLen(tb->buf + tb->caretpos); + if (backspace) s = Utf8PrevChar(s); - len = Utf8Decode(&c, tb->buf + tb->caretpos); + len = Utf8Decode(&c, s); width = GetCharacterWidth(FS_NORMAL, c); tb->width -= width; - if (backspace) tb->caretxoffs -= width; + if (backspace) { + tb->caretpos -= len; + tb->caretxoffs -= width; + } /* Move the remaining characters over the marker */ - memmove(tb->buf + tb->caretpos, tb->buf + tb->caretpos + len, tb->length - tb->caretpos - len + 1); + memmove(s, s + len, tb->length - (s - tb->buf) - len + 1); tb->length -= len; } @@ -887,9 +891,9 @@ bool MoveTextBufferPos(Textbuf *tb, int navmode) case WKC_LEFT: if (tb->caretpos != 0) { WChar c; - - tb->caretpos -= Utf8PrevCharLen(tb->buf + tb->caretpos); - Utf8Decode(&c, tb->buf + tb->caretpos); + const char *s = Utf8PrevChar(tb->buf + tb->caretpos); + Utf8Decode(&c, s); + tb->caretpos = s - tb->buf; // -= (tb->buf + tb->caretpos - s) tb->caretxoffs -= GetCharacterWidth(FS_NORMAL, c); return true; -- cgit v1.2.3-54-g00ecf