mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-10 04:40:25 +01:00
Add copy selection support
This commit is contained in:
parent
57c1c3524d
commit
0e6334db96
5 changed files with 18 additions and 1 deletions
|
@ -289,6 +289,7 @@ void Terminal::_register_methods() {
|
|||
register_method("start_selection", &Terminal::start_selection);
|
||||
register_method("select_to_pointer", &Terminal::select_to_pointer);
|
||||
register_method("reset_selection", &Terminal::reset_selection);
|
||||
register_method("copy_selection", &Terminal::copy_selection);
|
||||
|
||||
register_method("_update_theme", &Terminal::update_theme);
|
||||
register_method("_update_size", &Terminal::update_theme);
|
||||
|
@ -598,3 +599,11 @@ void Terminal::reset_selection() {
|
|||
tsm_screen_selection_reset(screen);
|
||||
update();
|
||||
}
|
||||
|
||||
String Terminal::copy_selection() {
|
||||
char *out = nullptr;
|
||||
int len = tsm_screen_selection_copy(screen, &out);
|
||||
String result = String(out);
|
||||
std::free(out);
|
||||
return result;
|
||||
}
|
|
@ -61,6 +61,7 @@ public:
|
|||
void start_selection(Vector2 position);
|
||||
void select_to_pointer(Vector2 position);
|
||||
void reset_selection();
|
||||
String copy_selection();
|
||||
|
||||
enum UpdateMode {
|
||||
DISABLED,
|
||||
|
|
|
@ -31,6 +31,9 @@ export (UpdateMode) var update_mode = UpdateMode.AUTO setget set_update_mode
|
|||
var cols = 2
|
||||
var rows = 2
|
||||
|
||||
# If true, text in the terminal will be copied to the clipboard when selected.
|
||||
export (bool) var copy_on_selection
|
||||
|
||||
var _viewport: Viewport = preload("./viewport.tscn").instance()
|
||||
var _native_terminal: Control = _viewport.get_node("Terminal")
|
||||
var _screen := TextureRect.new()
|
||||
|
@ -167,6 +170,9 @@ func _handle_selection(event: InputEventMouse):
|
|||
|
||||
func _on_selection_held() -> void:
|
||||
if not Input.is_mouse_button_pressed(BUTTON_LEFT) or _selecting_mode == SelectionMode.NONE:
|
||||
if copy_on_selection:
|
||||
var selection = _native_terminal.copy_selection()
|
||||
OS.set_clipboard(selection)
|
||||
_selection_timer.stop()
|
||||
return
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
extends GDXterm.Terminal
|
||||
extends "res://addons/godot_xterm/nodes/terminal/terminal.gd"
|
||||
|
||||
onready var pty = $PTY
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ script = ExtResource( 3 )
|
|||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
copy_on_selection = true
|
||||
|
||||
[node name="PTY" type="Node" parent="."]
|
||||
script = ExtResource( 2 )
|
||||
|
|
Loading…
Reference in a new issue