Browse Source

Lua plugin: Fix selection API using 0-based indices (#435)

Jan Lupčík 2 years ago
parent
commit
3dc8ec57eb

+ 4 - 4
Source/Lua/Elements/ElementFormControlInput.cpp

@@ -43,8 +43,8 @@ int ElementFormControlInputSelect(lua_State* /*L*/, ElementFormControlInput* obj
 
 int ElementFormControlInputSetSelection(lua_State* L, ElementFormControlInput* obj)
 {
-    int start = (int)luaL_checkinteger(L, 1);
-    int end = (int)luaL_checkinteger(L, 2);
+    int start = (int)GetIndex(L, 1);
+    int end = (int)GetIndex(L, 2);
     obj->SetSelectionRange(start, end);
     return 0;
 }
@@ -54,8 +54,8 @@ int ElementFormControlInputGetSelection(lua_State* L, ElementFormControlInput* o
     int selection_start = 0, selection_end = 0;
     String selected_text;
     obj->GetSelection(&selection_start, &selection_end, &selected_text);
-    lua_pushinteger(L, selection_start);
-    lua_pushinteger(L, selection_end);
+    PushIndex(L, selection_start);
+    PushIndex(L, selection_end);
     lua_pushstring(L, selected_text.c_str());
     return 3;
 }

+ 4 - 4
Source/Lua/Elements/ElementFormControlTextArea.cpp

@@ -43,8 +43,8 @@ int ElementFormControlTextAreaSelect(lua_State* /*L*/, ElementFormControlTextAre
 
 int ElementFormControlTextAreaSetSelection(lua_State* L, ElementFormControlTextArea* obj)
 {
-    int start = (int)luaL_checkinteger(L, 1);
-    int end = (int)luaL_checkinteger(L, 2);
+    int start = (int)GetIndex(L, 1);
+    int end = (int)GetIndex(L, 2);
     obj->SetSelectionRange(start, end);
     return 0;
 }
@@ -54,8 +54,8 @@ int ElementFormControlTextAreaGetSelection(lua_State* L, ElementFormControlTextA
     int selection_start = 0, selection_end = 0;
     String selected_text;
     obj->GetSelection(&selection_start, &selection_end, &selected_text);
-    lua_pushinteger(L, selection_start);
-    lua_pushinteger(L, selection_end);
+    PushIndex(L, selection_start);
+    PushIndex(L, selection_end);
     lua_pushstring(L, selected_text.c_str());
     return 3;
 }