mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
fix(clipboard): unload payload
This commit is contained in:
@@ -716,6 +716,10 @@ void ClipboardPanel::onClose() {
|
||||
m_lastHeight = 0.0f;
|
||||
m_pendingScrollToSelected = false;
|
||||
m_thumbnailRefreshPending = false;
|
||||
|
||||
if (m_clipboard != nullptr) {
|
||||
m_clipboard->evictAllPayloads();
|
||||
}
|
||||
}
|
||||
|
||||
InputArea* ClipboardPanel::initialFocusArea() const {
|
||||
@@ -821,6 +825,9 @@ void ClipboardPanel::rebuildPreview(Renderer& renderer, float width, float heigh
|
||||
}
|
||||
|
||||
if (m_clipboard != nullptr) {
|
||||
if (m_previewPayloadIndex != static_cast<std::size_t>(-1) && m_previewPayloadIndex != historyIndex) {
|
||||
m_clipboard->evictEntryPayload(m_previewPayloadIndex);
|
||||
}
|
||||
(void)m_clipboard->ensureEntryLoaded(historyIndex);
|
||||
}
|
||||
const auto& loadedEntry = m_clipboard != nullptr ? m_clipboard->history()[historyIndex] : entry;
|
||||
|
||||
@@ -405,6 +405,25 @@ bool ClipboardService::ensureEntryLoaded(std::size_t index) {
|
||||
return loadEntryPayload(m_history[index]);
|
||||
}
|
||||
|
||||
void ClipboardService::evictEntryPayload(std::size_t index) {
|
||||
if (index >= m_history.size()) {
|
||||
return;
|
||||
}
|
||||
auto& entry = m_history[index];
|
||||
if (entry.data.empty() || entry.payloadPath.empty()) {
|
||||
return;
|
||||
}
|
||||
entry.data.clear();
|
||||
entry.data.shrink_to_fit();
|
||||
entry.payloadLoaded = false;
|
||||
}
|
||||
|
||||
void ClipboardService::evictAllPayloads() {
|
||||
for (std::size_t i = 0; i < m_history.size(); ++i) {
|
||||
evictEntryPayload(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool ClipboardService::copyText(std::string text) {
|
||||
std::vector<std::uint8_t> data(text.begin(), text.end());
|
||||
return copyData({"text/plain;charset=utf-8", "text/plain"}, std::move(data));
|
||||
|
||||
@@ -73,6 +73,8 @@ public:
|
||||
[[nodiscard]] std::size_t addPollFds(std::vector<pollfd>& fds) const;
|
||||
|
||||
bool ensureEntryLoaded(std::size_t index);
|
||||
void evictEntryPayload(std::size_t index);
|
||||
void evictAllPayloads();
|
||||
bool copyText(std::string text);
|
||||
bool copyEntry(const ClipboardEntry& entry);
|
||||
bool promoteEntry(std::size_t index);
|
||||
|
||||
Reference in New Issue
Block a user