mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
correct cursor position for formating actions
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@239 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+16
-10
@@ -96,26 +96,29 @@ TextValue& TextValueAction::value() const {
|
||||
}
|
||||
|
||||
|
||||
TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start, size_t end, const String& action_name) {
|
||||
if (start > end) swap(start, end);
|
||||
TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name) {
|
||||
if (start > end) {
|
||||
swap(start, end);
|
||||
swap(start_i, end_i);
|
||||
}
|
||||
String new_value;
|
||||
const String& str = value->value();
|
||||
// Are we inside the tag we are toggling?
|
||||
size_t tagpos = in_tag(str, _("<") + tag, start, end);
|
||||
size_t tagpos = in_tag(str, _("<") + tag, start_i, end_i);
|
||||
if (tagpos == String::npos) {
|
||||
// we are not inside this tag, add it
|
||||
new_value = str.substr(0, start);
|
||||
new_value = str.substr(0, start_i);
|
||||
new_value += _("<") + tag + _(">");
|
||||
new_value += str.substr(start, end - start);
|
||||
new_value += str.substr(start_i, end_i - start_i);
|
||||
new_value += _("</") + tag + _(">");
|
||||
new_value += str.substr(end);
|
||||
new_value += str.substr(end_i);
|
||||
} else {
|
||||
// we are inside this tag, _('remove') it
|
||||
new_value = str.substr(0, start);
|
||||
new_value = str.substr(0, start_i);
|
||||
new_value += _("</") + tag + _(">");
|
||||
new_value += str.substr(start, end - start);
|
||||
new_value += str.substr(start_i, end_i - start_i);
|
||||
new_value += _("<") + tag + _(">");
|
||||
new_value += str.substr(end);
|
||||
new_value += str.substr(end_i);
|
||||
}
|
||||
// Build action
|
||||
if (start != end) {
|
||||
@@ -132,7 +135,10 @@ TextValueAction* toggle_format_action(const TextValueP& value, const String& tag
|
||||
|
||||
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);
|
||||
if (reverse) {
|
||||
swap(start, end);
|
||||
swap(start_i, end_i);
|
||||
}
|
||||
String new_value = tagged_substr_replace(value->value(), start_i, end_i, replacement);
|
||||
if (value->value() == new_value) {
|
||||
// no change
|
||||
|
||||
@@ -72,7 +72,7 @@ class TextValueAction : public ValueAction {
|
||||
};
|
||||
|
||||
/// Action for toggleing some formating tag on or off in some range
|
||||
TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start, size_t end, const String& action_name);
|
||||
TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name);
|
||||
|
||||
/// Typing in a TextValue, replace the selection [start...end) with replacement
|
||||
/** start and end are cursor positions, start_i and end_i are indices*/
|
||||
|
||||
@@ -390,15 +390,15 @@ void TextValueEditor::doFormat(int type) {
|
||||
size_t ss = selection_start, se = selection_end;
|
||||
switch (type) {
|
||||
case ID_FORMAT_BOLD: {
|
||||
getSet().actions.add(toggle_format_action(valueP(), _("b"), selection_start_i, selection_end_i, _("Bold")));
|
||||
getSet().actions.add(toggle_format_action(valueP(), _("b"), selection_start_i, selection_end_i, selection_start, selection_end, _("Bold")));
|
||||
break;
|
||||
}
|
||||
case ID_FORMAT_ITALIC: {
|
||||
getSet().actions.add(toggle_format_action(valueP(), _("i"), selection_start_i, selection_end_i, _("Italic")));
|
||||
getSet().actions.add(toggle_format_action(valueP(), _("i"), selection_start_i, selection_end_i, selection_start, selection_end, _("Italic")));
|
||||
break;
|
||||
}
|
||||
case ID_FORMAT_SYMBOL: {
|
||||
getSet().actions.add(toggle_format_action(valueP(), _("sym"), selection_start_i, selection_end_i, _("Symbols")));
|
||||
getSet().actions.add(toggle_format_action(valueP(), _("sym"), selection_start_i, selection_end_i, selection_start, selection_end, _("Symbols")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user