diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 6e33d22941..847d4f5dc2 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -974,6 +974,12 @@ void Editor::handle_read_event() } if (is_in_paste && param1 == 201) { m_state = InputState::Free; + if (on_paste) { + on_paste(Utf32View { m_paste_buffer.data(), m_paste_buffer.size() }, *this); + m_paste_buffer.clear_with_capacity(); + } + if (!m_paste_buffer.is_empty()) + insert(Utf32View { m_paste_buffer.data(), m_paste_buffer.size() }); continue; } } @@ -998,7 +1004,10 @@ void Editor::handle_read_event() m_state = InputState::GotEscape; continue; } - insert(code_point); + if (on_paste) + m_paste_buffer.append(code_point); + else + insert(code_point); continue; case InputState::Free: m_previous_free_state = InputState::Free; diff --git a/Userland/Libraries/LibLine/Editor.h b/Userland/Libraries/LibLine/Editor.h index 446585fe3d..5215505a4e 100644 --- a/Userland/Libraries/LibLine/Editor.h +++ b/Userland/Libraries/LibLine/Editor.h @@ -163,6 +163,7 @@ public: static StringMetrics actual_rendered_string_metrics(Utf32View const&); Function(Editor const&)> on_tab_complete; + Function on_paste; Function on_interrupt_handled; Function on_display_refresh; @@ -316,6 +317,7 @@ private: m_chars_touched_in_the_middle = 0; m_drawn_end_of_line_offset = 0; m_drawn_spans = {}; + m_paste_buffer.clear_with_capacity(); } void refresh_display(); @@ -491,6 +493,8 @@ private: RefPtr m_notifier; + Vector m_paste_buffer; + bool m_initialized { false }; bool m_refresh_needed { false }; Vector m_signal_handlers;