mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibVT: Replace u8 type to u32 for code point
Replace KeyEvent text attribute usage with code_point.
This commit is contained in:
parent
53227f400c
commit
7abca30f41
Notes:
sideshowbarker
2024-07-19 05:37:25 +09:00
Author: https://github.com/asliturk Commit: https://github.com/SerenityOS/serenity/commit/7abca30f414 Pull-request: https://github.com/SerenityOS/serenity/pull/2541
3 changed files with 13 additions and 18 deletions
|
@ -1004,7 +1004,7 @@ void Terminal::emit_string(const StringView& string)
|
|||
m_client.emit((const u8*)string.characters_without_null_termination(), string.length());
|
||||
}
|
||||
|
||||
void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags)
|
||||
void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
|
||||
{
|
||||
bool ctrl = flags & Mod_Ctrl;
|
||||
bool alt = flags & Mod_Alt;
|
||||
|
@ -1045,7 +1045,7 @@ void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags)
|
|||
break;
|
||||
}
|
||||
|
||||
if (!character) {
|
||||
if (!code_point) {
|
||||
// Probably a modifier being pressed.
|
||||
return;
|
||||
}
|
||||
|
@ -1058,10 +1058,10 @@ void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags)
|
|||
// Key event was not one of the above special cases,
|
||||
// attempt to treat it as a character...
|
||||
if (ctrl) {
|
||||
if (character >= 'a' && character <= 'z') {
|
||||
character = character - 'a' + 1;
|
||||
} else if (character == '\\') {
|
||||
character = 0x1c;
|
||||
if (code_point >= 'a' && code_point <= 'z') {
|
||||
code_point = code_point - 'a' + 1;
|
||||
} else if (code_point == '\\') {
|
||||
code_point = 0x1c;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1069,7 +1069,10 @@ void Terminal::handle_key_press(KeyCode key, u8 character, u8 flags)
|
|||
if (alt)
|
||||
emit_string("\033");
|
||||
|
||||
emit_string({ &character, 1 });
|
||||
StringBuilder sb;
|
||||
sb.append_codepoint(code_point);
|
||||
|
||||
emit_string(sb.to_string());
|
||||
}
|
||||
|
||||
void Terminal::unimplemented_escape()
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace VT {
|
|||
|
||||
class TerminalClient {
|
||||
public:
|
||||
virtual ~TerminalClient() { }
|
||||
virtual ~TerminalClient() {}
|
||||
|
||||
virtual void beep() = 0;
|
||||
virtual void set_window_title(const StringView&) = 0;
|
||||
|
@ -97,7 +97,7 @@ public:
|
|||
const NonnullOwnPtrVector<Line>& history() const { return m_history; }
|
||||
|
||||
void inject_string(const StringView&);
|
||||
void handle_key_press(KeyCode, u8 charatcter, u8 flags);
|
||||
void handle_key_press(KeyCode, u32, u8 flags);
|
||||
|
||||
Attribute attribute_at(const Position&) const;
|
||||
|
||||
|
|
|
@ -231,15 +231,7 @@ void TerminalWidget::keydown_event(GUI::KeyEvent& event)
|
|||
update();
|
||||
}
|
||||
|
||||
if (event.text().length() > 2) {
|
||||
// Unicode (likely emoji), just emit it.
|
||||
write(m_ptm_fd, event.text().characters(), event.text().length());
|
||||
} else {
|
||||
// Ask the terminal to generate the correct character sequence and send
|
||||
// it back to us via emit().
|
||||
u8 character = event.text().length() == 1 ? event.text()[0] : 0;
|
||||
m_terminal.handle_key_press(event.key(), character, event.modifiers());
|
||||
}
|
||||
m_terminal.handle_key_press(event.key(), event.code_point(), event.modifiers());
|
||||
|
||||
if (event.key() != Key_Control && event.key() != Key_Alt && event.key() != Key_Shift && event.key() != Key_Logo)
|
||||
m_scrollbar->set_value(m_scrollbar->max());
|
||||
|
|
Loading…
Reference in a new issue