1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

LibGUI: Replace text attribute on KeyEvent with code_point attribute

This commit is contained in:
Hüseyin ASLITÜRK 2020-06-11 21:31:53 +03:00 committed by Andreas Kling
parent 0aad21fff2
commit 53227f400c
3 changed files with 25 additions and 18 deletions

View file

@ -26,6 +26,7 @@
#pragma once
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <Kernel/KeyCode.h>
#include <LibCore/Event.h>
@ -267,10 +268,11 @@ enum MouseButton : u8 {
class KeyEvent final : public Event {
public:
KeyEvent(Type type, KeyCode key, u8 modifiers, u32 scancode)
KeyEvent(Type type, KeyCode key, u8 modifiers, u32 code_point, u32 scancode)
: Event(type)
, m_key(key)
, m_modifiers(modifiers)
, m_code_point(code_point)
, m_scancode(scancode)
{
}
@ -281,7 +283,13 @@ public:
bool shift() const { return m_modifiers & Mod_Shift; }
bool logo() const { return m_modifiers & Mod_Logo; }
u8 modifiers() const { return m_modifiers; }
String text() const { return m_text; }
u32 code_point() const { return m_code_point; }
String text() const
{
StringBuilder sb;
sb.append_codepoint(m_code_point);
return sb.to_string();
}
u32 scancode() const { return m_scancode; }
String to_string() const;
@ -290,8 +298,9 @@ private:
friend class WindowServerConnection;
KeyCode m_key { KeyCode::Key_Invalid };
u8 m_modifiers { 0 };
u32 m_code_point { 0 };
u32 m_scancode { 0 };
String m_text;
String m_text2;
};
class MouseEvent final : public Event {

View file

@ -889,8 +889,11 @@ void TextEditor::keydown_event(KeyEvent& event)
return;
}
if (!is_readonly() && !event.ctrl() && !event.alt() && !event.text().is_empty()) {
insert_at_cursor_or_replace_selection(event.text());
if (!is_readonly() && !event.ctrl() && !event.alt() && event.code_point() != 0) {
StringBuilder sb;
sb.append_codepoint(event.code_point());
insert_at_cursor_or_replace_selection(sb.to_string());
return;
}

View file

@ -25,6 +25,7 @@
*/
#include <AK/SharedBuffer.h>
#include <AK/StringBuilder.h>
#include <LibCore/EventLoop.h>
#include <LibCore/MimeData.h>
#include <LibGUI/Action.h>
@ -129,12 +130,7 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyDown& messa
if (!window)
return;
auto key_event = make<KeyEvent>(Event::KeyDown, (KeyCode) message.key(), message.modifiers(), message.scancode());
if (message.character() != '\0') {
char ch = message.character();
key_event->m_text = String(&ch, 1);
}
auto key_event = make<KeyEvent>(Event::KeyDown, (KeyCode)message.key(), message.modifiers(), message.code_point(), message.scancode());
Action* action = nullptr;
#ifdef KEYBOARD_SHORTCUTS_DEBUG
@ -176,7 +172,11 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyDown& messa
return;
key_event->m_key = Key_Invalid;
key_event->m_modifiers = 0;
key_event->m_text = emoji_input_dialog->selected_emoji_text();
AK::Utf8View m_utf8_view(emoji_input_dialog->selected_emoji_text().characters());
u32 code_point = *m_utf8_view.begin();
key_event->m_code_point = code_point;
}
Core::EventLoop::current().post_event(*window, move(key_event));
@ -188,12 +188,7 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyUp& message
if (!window)
return;
auto key_event = make<KeyEvent>(Event::KeyUp, (KeyCode) message.key(), message.modifiers(), message.scancode());
if (message.character() != '\0') {
char ch = message.character();
key_event->m_text = String(&ch, 1);
}
auto key_event = make<KeyEvent>(Event::KeyUp, (KeyCode)message.key(), message.modifiers(), message.code_point(), message.scancode());
Core::EventLoop::current().post_event(*window, move(key_event));
}