From f09f610e7cb155e1b4a49c4270d83b79ec7d0d56 Mon Sep 17 00:00:00 2001 From: twanvl Date: Tue, 19 Dec 2006 15:45:32 +0000 Subject: [PATCH] correct selection drawing, fixed cursor position around git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@122 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/value/text.cpp | 2 +- src/util/tagged_string.cpp | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/gui/value/text.cpp b/src/gui/value/text.cpp index 4149cb0e..8fac6e68 100644 --- a/src/gui/value/text.cpp +++ b/src/gui/value/text.cpp @@ -509,7 +509,7 @@ void TextValueEditor::moveSelection(IndexType t, size_t new_end, bool also_move_ // editor.refreshEditor(); // } else { // draw new selection - v.drawSelection(rdc, style(), selection_start, selection_end); + v.drawSelection(rdc, style(), selection_start_i, selection_end_i); // } showCaret(); // TODO; DEBUG!! diff --git a/src/util/tagged_string.cpp b/src/util/tagged_string.cpp index 0f6ca6f2..b9902a5b 100644 --- a/src/util/tagged_string.cpp +++ b/src/util/tagged_string.cpp @@ -169,22 +169,29 @@ size_t index_to_cursor(const String& str, size_t index, Movement dir) { // after the loop, cursor corresponds to index end for (size_t i = 0 ; i < str.size() ; ) { Char c = str.GetChar(i); + bool has_width = true; if (c == _('<')) { // a tag if (is_substr(str, i, _(" index) break; + } else if (is_substr(str, i, _(" index) { + // HACK: Don't walk past + dir = dir == MOVE_RIGHT ? MOVE_LEFT : MOVE_RIGHT; + } } else { i = skip_tag(str, i); end = i; + has_width = false; } } else { - cursor++; i++; + } + if (has_width) { + cursor++; start = end; end = i; if (end > index) break; @@ -204,19 +211,24 @@ void cursor_to_index_range(const String& str, size_t cursor, size_t& start, size size_t i = 0; while (cur <= cursor && i < str.size()) { Char c = str.GetChar(i); + bool has_width = true; if (c == _('<')) { // a tag if (is_substr(str, i, _("