mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-22 01:30: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;
|
char *out;
|
||||||
PackedByteArray data;
|
PackedByteArray data;
|
||||||
|
|
||||||
data.resize(func(screen, &out));
|
data.resize(std::max(func(screen, &out), 0));
|
||||||
memcpy(data.ptrw(), out, data.size());
|
if (data.size() > 0) {
|
||||||
std::free(out);
|
memcpy(data.ptrw(), out, data.size());
|
||||||
|
std::free(out);
|
||||||
|
}
|
||||||
|
|
||||||
return data.get_string_from_utf8();
|
return data.get_string_from_utf8();
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,9 @@ class TestCopy:
|
||||||
subject.write(text)
|
subject.write(text)
|
||||||
assert_string_contains(subject.copy_all(), text)
|
assert_string_contains(subject.copy_all(), text)
|
||||||
|
|
||||||
|
func test_copy_selection_when_nothing_selected():
|
||||||
|
assert_eq(subject.copy_selection(), "")
|
||||||
|
|
||||||
|
|
||||||
class TestClear:
|
class TestClear:
|
||||||
extends TerminalTest
|
extends TerminalTest
|
||||||
|
|
Loading…
Reference in a new issue