improved cursor motion for up/down/home/end; text editor now remembers cursor positions (instead of indices) when applying scripts.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@237 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-03-24 23:42:33 +00:00
parent 135941fb43
commit 114c03b6e1
5 changed files with 66 additions and 31 deletions
+4 -4
View File
@@ -130,10 +130,10 @@ TextValueAction* toggle_format_action(const TextValueP& value, const String& tag
}
}
TextValueAction* typing_action(const TextValueP& value, size_t start, size_t end, const String& replacement, const String& action_name) {
TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name) {
bool reverse = start > end;
if (reverse) swap(start, end);
String new_value = tagged_substr_replace(value->value(), start, end, replacement);
String new_value = tagged_substr_replace(value->value(), start_i, end_i, replacement);
if (value->value() == new_value) {
// no change
return nullptr;
@@ -141,9 +141,9 @@ TextValueAction* typing_action(const TextValueP& value, size_t start, size_t end
// if (name == _("Backspace")) {
// // HACK: put start after end
if (reverse) {
return new TextValueAction(value, end, start, start+replacement.size(), new_value, action_name);
return new TextValueAction(value, end, start, start+untag(replacement).size(), new_value, action_name);
} else {
return new TextValueAction(value, start, end, start+replacement.size(), new_value, action_name);
return new TextValueAction(value, start, end, start+untag(replacement).size(), new_value, action_name);
}
}
}
+2 -1
View File
@@ -75,7 +75,8 @@ class TextValueAction : public ValueAction {
TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start, size_t end, const String& action_name);
/// Typing in a TextValue, replace the selection [start...end) with replacement
TextValueAction* typing_action(const TextValueP& value, size_t start, size_t end, const String& replacement, const String& action_name);
/** start and end are cursor positions, start_i and end_i are indices*/
TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name);
// ----------------------------------------------------------------------------- : Event