@@ -286,7 +286,6 @@ void WidgetTextInput::SetValue(String value)
286
286
else
287
287
{
288
288
TransformValue (value);
289
- RMLUI_ASSERTMSG (value.size () == initial_size, " TransformValue must not change the text length." );
290
289
291
290
text_element->SetText (value);
292
291
@@ -301,6 +300,16 @@ void WidgetTextInput::SetValue(String value)
301
300
302
301
void WidgetTextInput::TransformValue (String& /* value*/ ) {}
303
302
303
+ int WidgetTextInput::DisplayIndexToAttributeIndex (int display_index, const String& /* attribute_value*/ )
304
+ {
305
+ return display_index;
306
+ }
307
+
308
+ int WidgetTextInput::AttributeIndexToDisplayIndex (int attribute_index, const String& /* attribute_value*/ )
309
+ {
310
+ return attribute_index;
311
+ }
312
+
304
313
void WidgetTextInput::SetMaxLength (int _max_length)
305
314
{
306
315
if (max_length != _max_length)
@@ -739,9 +748,11 @@ bool WidgetTextInput::AddCharacters(String string)
739
748
return false ;
740
749
741
750
String value = GetAttributeValue ();
742
- value.insert (std::min<size_t >((size_t )absolute_cursor_index, value.size ()), string);
751
+ const int attribute_insert_index = DisplayIndexToAttributeIndex (absolute_cursor_index, value);
752
+ value.insert (std::min<size_t >((size_t )attribute_insert_index, value.size ()), string);
743
753
744
- absolute_cursor_index += (int )string.size ();
754
+ const int new_cursor_attribute_index = AttributeIndexToDisplayIndex (attribute_insert_index + (int )string.size (), value);
755
+ absolute_cursor_index = new_cursor_attribute_index;
745
756
parent->SetAttribute (" value" , value);
746
757
747
758
if (UpdateSelection (false ))
@@ -1504,8 +1515,13 @@ void WidgetTextInput::DeleteSelection()
1504
1515
if (selection_length > 0 )
1505
1516
{
1506
1517
String new_value = GetAttributeValue ();
1507
- const size_t selection_begin = std::min ((size_t )selection_begin_index, (size_t )new_value.size ());
1508
- new_value.erase (selection_begin, (size_t )selection_length);
1518
+ const int selection_begin_index_attribute = DisplayIndexToAttributeIndex (selection_begin_index, new_value);
1519
+ const int selection_end_index_attribute = DisplayIndexToAttributeIndex (selection_begin_index + selection_length, new_value);
1520
+ RMLUI_ASSERT (selection_end_index_attribute >= selection_begin_index_attribute);
1521
+
1522
+ const size_t selection_begin = std::min ((size_t )selection_begin_index_attribute, (size_t )new_value.size ());
1523
+ const size_t attribute_selection_length = size_t (selection_end_index_attribute - selection_begin_index_attribute);
1524
+ new_value.erase (selection_begin, (size_t )attribute_selection_length);
1509
1525
1510
1526
// Move the cursor to the beginning of the old selection.
1511
1527
absolute_cursor_index = selection_begin_index;
0 commit comments