Skip to content

Commit

Permalink
toggle show emojis to update text entry field
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Jan 27, 2024
1 parent d0c9e2d commit afdb3ec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "4.34"
#define NCHAT_VERSION "4.35"
2 changes: 1 addition & 1 deletion src/nchat.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NCHAT "1" "January 2024" "nchat v4.34" "User Commands"
.TH NCHAT "1" "January 2024" "nchat v4.35" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down
28 changes: 27 additions & 1 deletion src/uimodel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// uimodel.cpp
//
// Copyright (c) 2019-2023 Kristofer Berggren
// Copyright (c) 2019-2024 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
Expand Down Expand Up @@ -143,6 +143,7 @@ void UiModel::KeyHandler(wint_t p_Key)
else if (p_Key == keyToggleEmoji)
{
m_View->SetEmojiEnabled(!m_View->GetEmojiEnabled());
EntryConvertEmojiEnabled();
UpdateList();
UpdateStatus();
UpdateHistory();
Expand Down Expand Up @@ -3203,3 +3204,28 @@ void UiModel::Quit()

m_Running = false;
}

void UiModel::EntryConvertEmojiEnabled()
{
const bool emojiEnabled = GetEmojiEnabled();
std::string profileId = m_CurrentChat.first;
std::string chatId = m_CurrentChat.second;
int& entryPos = m_EntryPos[profileId][chatId];
std::wstring& entryStr = m_EntryStr[profileId][chatId];

if (!entryStr.empty())
{
if (!emojiEnabled)
{
std::wstring wstr = entryStr;
wstr.erase(std::remove(wstr.begin(), wstr.end(), EMOJI_PAD), wstr.end());
entryStr = StrUtil::ToWString(StrUtil::Textize(StrUtil::ToString(wstr)));
}
else
{
entryStr = StrUtil::ToWString(StrUtil::Emojize(StrUtil::ToString(entryStr), true));
}

entryPos = entryStr.size();
}
}
3 changes: 2 additions & 1 deletion src/uimodel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// uimodel.h
//
// Copyright (c) 2019-2023 Kristofer Berggren
// Copyright (c) 2019-2024 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
Expand Down Expand Up @@ -156,6 +156,7 @@ class UiModel
void SendProtocolRequest(const std::string& p_ProfileId, std::shared_ptr<RequestMessage> p_Request);
bool HasProtocolFeature(const std::string& p_ProfileId, ProtocolFeature p_ProtocolFeature);
void Quit();
void EntryConvertEmojiEnabled();

private:
bool m_Running = true;
Expand Down

0 comments on commit afdb3ec

Please sign in to comment.