mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-24 18:20:25 +01:00
fix(term): copy_selection() when nothing selected
Fixes the copy_selection() method so that it returns and empty string when called and nothing is selected. Previously printed an error.
This commit is contained in:
parent
3ca272c615
commit
43303a51bf
2 changed files with 8 additions and 3 deletions
|
@ -648,9 +648,11 @@ String Terminal::_copy_screen(ScreenCopyFunction func) {
|
|||
char *out;
|
||||
PackedByteArray data;
|
||||
|
||||
data.resize(func(screen, &out));
|
||||
data.resize(std::max(func(screen, &out), 0));
|
||||
if (data.size() > 0) {
|
||||
memcpy(data.ptrw(), out, data.size());
|
||||
std::free(out);
|
||||
}
|
||||
|
||||
return data.get_string_from_utf8();
|
||||
}
|
||||
|
|
|
@ -222,6 +222,9 @@ class TestCopy:
|
|||
subject.write(text)
|
||||
assert_string_contains(subject.copy_all(), text)
|
||||
|
||||
func test_copy_selection_when_nothing_selected():
|
||||
assert_eq(subject.copy_selection(), "")
|
||||
|
||||
|
||||
class TestClear:
|
||||
extends TerminalTest
|
||||
|
|
Loading…
Reference in a new issue