Delete selected clipboard history entries
This commit is contained in:
@@ -84,6 +84,23 @@ Item {
|
|||||||
root.addClipboardEntry(ClipboardHistory.parseEntryJson(line))
|
root.addClipboardEntry(ClipboardHistory.parseEntryJson(line))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeDisplayIndex(index) {
|
||||||
|
if (index < 0 || index >= displayModel.count) return
|
||||||
|
|
||||||
|
var row = displayModel.get(index)
|
||||||
|
root.history = ClipboardHistory.removeEntryAt(root.history, row.index)
|
||||||
|
root.saveHistory()
|
||||||
|
|
||||||
|
if (displayModel.count <= 1) {
|
||||||
|
root.selectedIndex = 0
|
||||||
|
root.cursorActive = false
|
||||||
|
} else if (root.selectedIndex >= displayModel.count - 1) {
|
||||||
|
root.selectedIndex = displayModel.count - 2
|
||||||
|
}
|
||||||
|
|
||||||
|
root.rebuildDisplay()
|
||||||
|
}
|
||||||
|
|
||||||
function rebuildDisplay() {
|
function rebuildDisplay() {
|
||||||
var rows = ClipboardHistory.displayRows(root.history, root.filterText, 50)
|
var rows = ClipboardHistory.displayRows(root.history, root.filterText, 50)
|
||||||
|
|
||||||
@@ -231,6 +248,9 @@ Item {
|
|||||||
} else if (event.key === Qt.Key_Backspace) {
|
} else if (event.key === Qt.Key_Backspace) {
|
||||||
if (root.filterText.length > 0) root.setFilter(root.filterText.slice(0, -1))
|
if (root.filterText.length > 0) root.setFilter(root.filterText.slice(0, -1))
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Delete) {
|
||||||
|
root.removeDisplayIndex(root.selectedIndex)
|
||||||
|
event.accepted = true
|
||||||
} else if (event.key === Qt.Key_Up) {
|
} else if (event.key === Qt.Key_Up) {
|
||||||
root.select(-1)
|
root.select(-1)
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
|
|||||||
@@ -66,6 +66,16 @@ function addEntry(history, entry, limit) {
|
|||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeEntryAt(history, index) {
|
||||||
|
var values = Array.isArray(history) ? history : []
|
||||||
|
var target = Number(index)
|
||||||
|
if (isNaN(target) || target < 0 || target >= values.length) return values.slice()
|
||||||
|
|
||||||
|
var next = values.slice()
|
||||||
|
next.splice(target, 1)
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
function parseEntryJson(line) {
|
function parseEntryJson(line) {
|
||||||
var raw = String(line || "").trim()
|
var raw = String(line || "").trim()
|
||||||
if (!raw) return null
|
if (!raw) return null
|
||||||
@@ -121,6 +131,7 @@ if (typeof module !== "undefined") {
|
|||||||
entryKey: entryKey,
|
entryKey: entryKey,
|
||||||
parseHistory: parseHistory,
|
parseHistory: parseHistory,
|
||||||
addEntry: addEntry,
|
addEntry: addEntry,
|
||||||
|
removeEntryAt: removeEntryAt,
|
||||||
parseEntryJson: parseEntryJson,
|
parseEntryJson: parseEntryJson,
|
||||||
searchableText: searchableText,
|
searchableText: searchableText,
|
||||||
previewText: previewText,
|
previewText: previewText,
|
||||||
|
|||||||
@@ -47,6 +47,17 @@ assertDeepEqual(
|
|||||||
'clipboard addEntry moves duplicate text to front'
|
'clipboard addEntry moves duplicate text to front'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assertDeepEqual(
|
||||||
|
clipboard.removeEntryAt(history, 1),
|
||||||
|
[
|
||||||
|
{ type: 'text', text: 'old' },
|
||||||
|
{ type: 'image', path: '/tmp/a.png', mime: 'image/png' }
|
||||||
|
],
|
||||||
|
'clipboard removeEntryAt removes the requested entry'
|
||||||
|
)
|
||||||
|
|
||||||
|
assertDeepEqual(clipboard.removeEntryAt(history, 10), history, 'clipboard removeEntryAt ignores invalid indexes')
|
||||||
|
|
||||||
assertDeepEqual(
|
assertDeepEqual(
|
||||||
clipboard.displayRows(history, 'image', 50).map(row => ({ type: row.entryType, preview: row.previewText, mime: row.mime })),
|
clipboard.displayRows(history, 'image', 50).map(row => ({ type: row.entryType, preview: row.previewText, mime: row.mime })),
|
||||||
[{ type: 'image', preview: 'Image', mime: 'image/png' }],
|
[{ type: 'image', preview: 'Image', mime: 'image/png' }],
|
||||||
|
|||||||
Reference in New Issue
Block a user