mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibGUI: Replace text attribute on KeyEvent with code_point attribute
This commit is contained in:
parent
0aad21fff2
commit
53227f400c
3 changed files with 25 additions and 18 deletions
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <Kernel/KeyCode.h>
|
#include <Kernel/KeyCode.h>
|
||||||
#include <LibCore/Event.h>
|
#include <LibCore/Event.h>
|
||||||
|
@ -267,10 +268,11 @@ enum MouseButton : u8 {
|
||||||
|
|
||||||
class KeyEvent final : public Event {
|
class KeyEvent final : public Event {
|
||||||
public:
|
public:
|
||||||
KeyEvent(Type type, KeyCode key, u8 modifiers, u32 scancode)
|
KeyEvent(Type type, KeyCode key, u8 modifiers, u32 code_point, u32 scancode)
|
||||||
: Event(type)
|
: Event(type)
|
||||||
, m_key(key)
|
, m_key(key)
|
||||||
, m_modifiers(modifiers)
|
, m_modifiers(modifiers)
|
||||||
|
, m_code_point(code_point)
|
||||||
, m_scancode(scancode)
|
, m_scancode(scancode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -281,7 +283,13 @@ public:
|
||||||
bool shift() const { return m_modifiers & Mod_Shift; }
|
bool shift() const { return m_modifiers & Mod_Shift; }
|
||||||
bool logo() const { return m_modifiers & Mod_Logo; }
|
bool logo() const { return m_modifiers & Mod_Logo; }
|
||||||
u8 modifiers() const { return m_modifiers; }
|
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; }
|
u32 scancode() const { return m_scancode; }
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
|
@ -290,8 +298,9 @@ private:
|
||||||
friend class WindowServerConnection;
|
friend class WindowServerConnection;
|
||||||
KeyCode m_key { KeyCode::Key_Invalid };
|
KeyCode m_key { KeyCode::Key_Invalid };
|
||||||
u8 m_modifiers { 0 };
|
u8 m_modifiers { 0 };
|
||||||
|
u32 m_code_point { 0 };
|
||||||
u32 m_scancode { 0 };
|
u32 m_scancode { 0 };
|
||||||
String m_text;
|
String m_text2;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MouseEvent final : public Event {
|
class MouseEvent final : public Event {
|
||||||
|
|
|
@ -889,8 +889,11 @@ void TextEditor::keydown_event(KeyEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_readonly() && !event.ctrl() && !event.alt() && !event.text().is_empty()) {
|
if (!is_readonly() && !event.ctrl() && !event.alt() && event.code_point() != 0) {
|
||||||
insert_at_cursor_or_replace_selection(event.text());
|
StringBuilder sb;
|
||||||
|
sb.append_codepoint(event.code_point());
|
||||||
|
|
||||||
|
insert_at_cursor_or_replace_selection(sb.to_string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/SharedBuffer.h>
|
#include <AK/SharedBuffer.h>
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/MimeData.h>
|
#include <LibCore/MimeData.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
|
@ -129,12 +130,7 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyDown& messa
|
||||||
if (!window)
|
if (!window)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto key_event = make<KeyEvent>(Event::KeyDown, (KeyCode) message.key(), message.modifiers(), message.scancode());
|
auto key_event = make<KeyEvent>(Event::KeyDown, (KeyCode)message.key(), message.modifiers(), message.code_point(), message.scancode());
|
||||||
if (message.character() != '\0') {
|
|
||||||
char ch = message.character();
|
|
||||||
key_event->m_text = String(&ch, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Action* action = nullptr;
|
Action* action = nullptr;
|
||||||
|
|
||||||
#ifdef KEYBOARD_SHORTCUTS_DEBUG
|
#ifdef KEYBOARD_SHORTCUTS_DEBUG
|
||||||
|
@ -176,7 +172,11 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyDown& messa
|
||||||
return;
|
return;
|
||||||
key_event->m_key = Key_Invalid;
|
key_event->m_key = Key_Invalid;
|
||||||
key_event->m_modifiers = 0;
|
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));
|
Core::EventLoop::current().post_event(*window, move(key_event));
|
||||||
|
@ -188,12 +188,7 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyUp& message
|
||||||
if (!window)
|
if (!window)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto key_event = make<KeyEvent>(Event::KeyUp, (KeyCode) message.key(), message.modifiers(), message.scancode());
|
auto key_event = make<KeyEvent>(Event::KeyUp, (KeyCode)message.key(), message.modifiers(), message.code_point(), message.scancode());
|
||||||
if (message.character() != '\0') {
|
|
||||||
char ch = message.character();
|
|
||||||
key_event->m_text = String(&ch, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::EventLoop::current().post_event(*window, move(key_event));
|
Core::EventLoop::current().post_event(*window, move(key_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue