Skip to content

Commit

Permalink
only start editing if input is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Jul 15, 2023
1 parent f941ad1 commit 03e617a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/chatinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ void ChatInput::StopEditing() {
m_input.Get().get_style_context()->remove_class("editing");
}

bool ChatInput::IsEmpty() {
return GetBuffer()->get_char_count() == 0;
}

bool ChatInput::AddFileAsImageAttachment(const Glib::RefPtr<Gio::File> &file) {
try {
const auto read_stream = file->read();
Expand Down
2 changes: 2 additions & 0 deletions src/components/chatinput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class ChatInput : public Gtk::Box {
void StartEditing(const Message &message);
void StopEditing();

bool IsEmpty();

private:
bool AddFileAsImageAttachment(const Glib::RefPtr<Gio::File> &file);
bool CanAttachFiles();
Expand Down
2 changes: 1 addition & 1 deletion src/components/chatwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ bool ChatWindow::OnInputSubmit(ChatSubmitParams data) {

bool ChatWindow::ProcessKeyEvent(GdkEventKey *e) {
if (e->type != GDK_KEY_PRESS) return false;
if (e->keyval == GDK_KEY_Up) {
if (e->keyval == GDK_KEY_Up && !(e->state & GDK_SHIFT_MASK) && m_input->IsEmpty()) {
const auto edit_id = m_chat->GetLastSentMessage();
if (edit_id.has_value()) {
StartEditing(*edit_id);
Expand Down

0 comments on commit 03e617a

Please sign in to comment.