From 0b24e1ab205c335c0ef728def020703888af7429 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 24 Aug 2008 18:27:11 +0000 Subject: [PATCH] fixed crash in cursor movement code when adding keyword parameter git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1167 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/value/text.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/value/text.cpp b/src/gui/value/text.cpp index a61ef012..91ce0ec9 100644 --- a/src/gui/value/text.cpp +++ b/src/gui/value/text.cpp @@ -868,6 +868,8 @@ void TextValueEditor::insert(const String& text, const String& action_name) { /// compare two cursor positions, determine how much the text matches before and after size_t match_cursor_position(size_t pos1, const String& text1, size_t pos2, const String& text2) { + pos1 = min(pos1, text1.size()); + pos2 = min(pos2, text2.size()); size_t score = 0; // total score // Match part before cursor size_t before1, before2; @@ -915,7 +917,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String& } // what we would expect if no scripts take place String expected_value = untag_for_cursor(action->newValue()); - size_t expected_cursor = min(selection_start, selection_end) + untag(replacement).size(); + size_t expected_cursor = min(selection_start, selection_end) + untag_for_cursor(replacement).size(); // perform the action // NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text addAction(action);