From d37adbbb94d4bd0dcaf31cd12258ecf66b6a1467 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 25 Mar 2007 00:22:44 +0000 Subject: [PATCH] cursor handling now correct in the precense of and (finally) git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@238 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/util/tagged_string.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/util/tagged_string.cpp b/src/util/tagged_string.cpp index 7f82beb5..f472f73c 100644 --- a/src/util/tagged_string.cpp +++ b/src/util/tagged_string.cpp @@ -193,9 +193,6 @@ size_t index_to_cursor(const String& str, size_t index, Movement dir) { return cursor; } else if (dir == MOVE_RIGHT) { return cursor + 1; - } else if (dir == MOVE_MID) { - // take the closest side - return cursor + ((int)(after - index) < (int)(index - before)); } else if (dir == MOVE_LEFT_OPT) { // is there any non-tag after index? bool empty = true; @@ -222,6 +219,22 @@ size_t index_to_cursor(const String& str, size_t index, Movement dir) { i = skip_tag(str, i); } return cursor + 1; // yes it is + } else if (dir == MOVE_MID) { + // count number of actual characters before/after + int before_c = 0; + int after_c = 0; + while (i < close) { + c = str.GetChar(i); + if (c == _('<')) { + i = skip_tag(str, i); + } else { + if (i < index) before_c++; + else after_c++; + ++i; + } + } + // take the closest side + return before_c <= after_c ? cursor : cursor + 1; } } i = after; @@ -250,6 +263,8 @@ void cursor_to_index_range(const String& str, size_t cursor, size_t& start, size if (c == _('<')) { // a tag if (is_substr(str, i, _("= cursor) break; // skip tag contents, tag counts as a single 'character' i = match_close_tag_end(str, i); } else {