From acbd8715f491f799ee1f51b649e470e719947c58 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 7 Apr 2023 12:42:46 -0400 Subject: [PATCH] Added in explicit touchscreen keyboard support. (#1389) --- data/core/commandview.lua | 5 +++++ data/core/docview.lua | 5 +++++ data/core/init.lua | 1 + data/core/view.lua | 4 ++++ src/api/system.c | 10 ++++++++++ src/main.c | 2 ++ 6 files changed, 27 insertions(+) diff --git a/data/core/commandview.lua b/data/core/commandview.lua index 1f388678..dd2c5e42 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -84,6 +84,11 @@ function CommandView:get_line_screen_position(line, col) end +function CommandView:supports_text_input() + return true +end + + function CommandView:get_scrollable_size() return 0 end diff --git a/data/core/docview.lua b/data/core/docview.lua index 908d7c6a..7b04dba4 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -252,6 +252,11 @@ function DocView:scroll_to_line(line, ignore_if_visible, instant) end +function DocView:supports_text_input() + return true +end + + function DocView:scroll_to_make_visible(line, col) local ox, oy = self:get_content_offset() local _, ly = self:get_line_screen_position(line, col) diff --git a/data/core/init.lua b/data/core/init.lua index f92c55bb..a15cfc5e 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1105,6 +1105,7 @@ function core.set_active_view(view) -- Reset the IME even if the focus didn't change ime.stop() if view ~= core.active_view then + system.text_input(view:supports_text_input()) if core.active_view and core.active_view.force_focus then core.next_active_view = view return diff --git a/data/core/view.lua b/data/core/view.lua index 77378b90..36580677 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -108,6 +108,10 @@ function View:get_h_scrollable_size() end +function View:supports_text_input() + return false +end + ---@param x number ---@param y number ---@return boolean diff --git a/src/api/system.c b/src/api/system.c index 76b69aba..5f7868d1 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -1084,6 +1084,15 @@ static int f_path_compare(lua_State *L) { } +static int f_text_input(lua_State* L) { + if (lua_toboolean(L, 1)) + SDL_StartTextInput(); + else + SDL_StopTextInput(); + return 0; +} + + static const luaL_Reg lib[] = { { "poll_event", f_poll_event }, { "wait_event", f_wait_event }, @@ -1117,6 +1126,7 @@ static const luaL_Reg lib[] = { { "load_native_plugin", f_load_native_plugin }, { "path_compare", f_path_compare }, { "get_fs_type", f_get_fs_type }, + { "text_input", f_text_input }, { NULL, NULL } }; diff --git a/src/main.c b/src/main.c index ec8abdca..f7e79db5 100644 --- a/src/main.c +++ b/src/main.c @@ -238,6 +238,8 @@ init_lua: set_macos_bundle_resources(L); #endif #endif + SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE); + SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE); const char *init_lite_code = \ "local core\n"