Skip to content

Commit

Permalink
feat: app name case insensitive in app_options (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang authored Dec 16, 2023
1 parent 2d3c54c commit 415679b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 7 additions & 5 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,10 @@ void RimeWithWeaselHandler::_ReadClientInfo(UINT session_id, LPWSTR buffer)
{
RimeSetProperty(session_id, "client_app", app_name.c_str());

if (m_app_options.find(app_name) != m_app_options.end())
auto it = m_app_options.find(app_name);
if (it != m_app_options.end())
{
AppOptions& options(m_app_options[app_name]);
AppOptions& options(m_app_options[it->first]);
std::for_each(options.begin(), options.end(), [session_id](std::pair<const std::string, bool> &pair)
{
DLOG(INFO) << "set app option: " << pair.first << " = " << pair.second;
Expand Down Expand Up @@ -508,11 +509,12 @@ void RimeWithWeaselHandler::_LoadAppInlinePreeditSet(UINT session_id, bool ignor
bool inline_preedit = m_ui->style().inline_preedit;
if (!app_name.empty())
{
if (m_app_options.find(app_name) != m_app_options.end())
auto it = m_app_options.find(app_name);
if (it != m_app_options.end())
{
AppOptions& options(m_app_options[app_name]);
AppOptions& options(m_app_options[it->first]);
auto pfind = std::make_shared<bool>(false);
std::for_each(options.begin(), options.end(), [session_id, app_name, pfind, inline_preedit, this](std::pair<const std::string, bool> &pair)
std::for_each(options.begin(), options.end(), [session_id, pfind, inline_preedit, this](std::pair<const std::string, bool> &pair)
{
if(pair.first == "inline_preedit")
{
Expand Down
13 changes: 12 additions & 1 deletion include/RimeWithWeasel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@

#include <rime_api.h>

struct CaseInsensitiveCompare {
bool operator()(const std::string& str1, const std::string& str2) const {
std::string str1Lower, str2Lower;
std::transform(str1.begin(), str1.end(), std::back_inserter(str1Lower),
[](char c) { return std::tolower(c); });
std::transform(str2.begin(), str2.end(), std::back_inserter(str2Lower),
[](char c) { return std::tolower(c); });
return str1Lower < str2Lower;
}
};

typedef std::map<std::string, bool> AppOptions;
typedef std::map<std::string, AppOptions> AppOptionsByAppName;
typedef std::map<std::string, AppOptions, CaseInsensitiveCompare> AppOptionsByAppName;
class RimeWithWeaselHandler :
public weasel::RequestHandler
{
Expand Down

0 comments on commit 415679b

Please sign in to comment.