Cursor now moves correctly with script updates; tries to stay outside <sym> tags;

Closing </kw> tags no longer end up in keyword parameters

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@515 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-07-06 23:28:45 +00:00
parent 6acd0a5794
commit e3939813dc
5 changed files with 89 additions and 24 deletions
+26
View File
@@ -301,6 +301,10 @@ size_t cursor_to_index(const String& str, size_t cursor, Movement dir) {
return i;
}
}
if (starts_with(tag1, _("/sym"))) {
// we like to be inside <b> and <i> tags, but outside <sym> tags
start = i;
}
} else {
i++;
}
@@ -310,6 +314,28 @@ size_t cursor_to_index(const String& str, size_t cursor, Movement dir) {
return dir <= 0 /*MOVE_LEFT*/ ? start : end - 1;
}
String untag_for_cursor(const String& str) {
String ret; ret.reserve(str.size());
for (size_t i = 0 ; i < str.size() ; ) {
Char c = str.GetChar(i);
if (c == _('<')) {
if (is_substr(str, i, _("<atom"))) {
i = match_close_tag_end(str, i);
ret += _('\2'); // use a random character here
} else if (is_substr(str, i, _("<sep"))) {
i = match_close_tag_end(str, i);
ret += _('\3'); // use a random character here
} else {
i = skip_tag(str, i);
}
} else {
ret += c;
++i;
}
}
return ret;
}
// ----------------------------------------------------------------------------- : Untagged position
size_t untagged_to_index(const String& str, size_t pos, bool inside) {
+4
View File
@@ -111,6 +111,10 @@ void cursor_to_index_range(const String& str, size_t cursor, size_t& begin, size
/// Find the character index corresponding to the given cursor position
size_t cursor_to_index(const String& str, size_t cursor, Movement dir = MOVE_MID);
/// Untag a string for use with cursors, <atom>...</atom> becomes a single character.
/** This string should only be used for cursor position calculations. */
String untag_for_cursor(const String& str);
// ----------------------------------------------------------------------------- : Untagged position
/// Find the tagged position corresponding to the given untagged position.