summaryrefslogtreecommitdiff
path: root/Libraries/LibVT
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-10 17:39:11 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-10 17:39:11 +0200
commitf41bbdd46e02c7bba4e6e150ceb6f90ff8d0cc74 (patch)
treeedd0307b7a07eb43a5daaf3364966ddb0801122d /Libraries/LibVT
parent901d2e323668d97fe3aa2d1e679352c7f53f4af6 (diff)
downloadserenity-f41bbdd46e02c7bba4e6e150ceb6f90ff8d0cc74.zip
LibVT: Allow dragging hyperlinks :^)
You can now drag a hyperlink as a text/uri-list. This allows you to drag a file from "ls" output and drop it on a FileManager to copy the file there. Truly futuristic stuff!
Diffstat (limited to 'Libraries/LibVT')
-rw-r--r--Libraries/LibVT/TerminalWidget.cpp24
-rw-r--r--Libraries/LibVT/TerminalWidget.h3
2 files changed, 26 insertions, 1 deletions
diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp
index feb9ace106..618788ae7a 100644
--- a/Libraries/LibVT/TerminalWidget.cpp
+++ b/Libraries/LibVT/TerminalWidget.cpp
@@ -36,6 +36,7 @@
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/Clipboard.h>
+#include <LibGUI/DragOperation.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h>
#include <LibGUI/ScrollBar.h>
@@ -639,6 +640,7 @@ void TerminalWidget::mouseup_event(GUI::MouseEvent& event)
Desktop::Launcher::open(attribute.href);
}
if (!m_active_href_id.is_null()) {
+ m_active_href = {};
m_active_href_id = {};
update();
}
@@ -648,12 +650,16 @@ void TerminalWidget::mouseup_event(GUI::MouseEvent& event)
void TerminalWidget::mousedown_event(GUI::MouseEvent& event)
{
if (event.button() == GUI::MouseButton::Left) {
+ m_left_mousedown_position = event.position();
+
auto attribute = m_terminal.attribute_at(buffer_position_at(event.position()));
if (!(event.modifiers() & Mod_Shift) && !attribute.href.is_empty()) {
+ m_active_href = attribute.href;
m_active_href_id = attribute.href_id;
update();
return;
}
+ m_active_href = {};
m_active_href_id = {};
if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
@@ -700,8 +706,24 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event)
if (!(event.buttons() & GUI::MouseButton::Left))
return;
- if (!m_active_href_id.is_null())
+ if (!m_active_href_id.is_null()) {
+ auto diff = event.position() - m_left_mousedown_position;
+ auto distance_travelled_squared = diff.x() * diff.x() + diff.y() * diff.y();
+ constexpr int drag_distance_threshold = 5;
+
+ if (distance_travelled_squared <= drag_distance_threshold)
+ return;
+
+ auto drag_operation = GUI::DragOperation::construct();
+ drag_operation->set_text(m_active_href);
+ drag_operation->set_data("text/uri-list", m_active_href);
+ drag_operation->exec();
+
+ m_active_href = {};
+ m_active_href_id = {};
+ update();
return;
+ }
auto old_selection_end = m_selection_end;
m_selection_end = position;
diff --git a/Libraries/LibVT/TerminalWidget.h b/Libraries/LibVT/TerminalWidget.h
index 64d63d82c8..efd46068f1 100644
--- a/Libraries/LibVT/TerminalWidget.h
+++ b/Libraries/LibVT/TerminalWidget.h
@@ -134,6 +134,7 @@ private:
String m_hovered_href;
String m_hovered_href_id;
+ String m_active_href;
String m_active_href_id;
// Snapshot of m_hovered_href when opening a context menu for a hyperlink.
@@ -179,4 +180,6 @@ private:
RefPtr<GUI::Menu> m_context_menu_for_hyperlink;
Core::ElapsedTimer m_triple_click_timer;
+
+ Gfx::Point m_left_mousedown_position;
};