Preserve clipboard history order

This commit is contained in:
2026-09-12 14:55:51 +02:00
parent 00370f7721
commit 0a81af95af
2 changed files with 71 additions and 59 deletions

View File

@@ -51,6 +51,7 @@ Each bounded iteration must:
- [ ] Verify global shortcut registration, cleanup, conflicts, and configured shortcuts (popup now presents immediately while target-focus capture completes asynchronously).
- [ ] Verify previous-focus capture and paste behavior against real X11 applications.
- [x] Refresh the paste destination while the visible popup is inactive so switching fields/apps does not reuse the original target (27 X11-feature tests and Docker GTK/X11/package build, 2026-09-12); live multi-field acceptance remains pending.
- [x] Preserve entry order after copy/paste and other non-pin actions by avoiding recency updates during clipboard actions; add Unix-second timestamps to UI status messages (27 X11-feature tests and Docker GTK/X11/package build, 2026-09-12); live GUI acceptance remains pending.
- [x] Preserve readable textual clipboard contents after paste injection fails;
retain the selected entry only when the original clipboard cannot be read or
restored, and show the existing actionable failure status (27 X11-feature
@@ -76,6 +77,7 @@ Each bounded iteration must:
still pending.
- [ ] Ensure copy, paste, pin, delete, clear, pause, and resume have consistent UI feedback.
- [x] Add icon-only copy, paste, and delete controls to every history row, with matching icon prefixes on toolbar actions (27 X11-feature tests, Docker GTK/X11/package build, 2026-09-12); live GUI acceptance remains pending.
- [x] Add state-specific icon-only pin/unpin controls on the left of every history row, routed through the existing pin-limit logic (27 X11-feature tests and Docker GTK/X11/package build, 2026-09-12); live GUI acceptance remains pending.
- [x] Surface actionable status text for keyboard and toolbar action failures, including successful clipboard writes with failed history updates (Docker GTK/X11 build, 2026-09-10).
- [x] Replace the conflict-prone `Ctrl+R` pause shortcut with `Ctrl+Alt+R`, and expose the configured global shortcut in the window title/status (Docker GTK/X11 build; live tray/capture verified, 2026-09-10).
- [x] Use the Mint-friendly `Ctrl+Alt+V` as the default global popup shortcut;

View File

@@ -47,7 +47,6 @@ struct UiState {
}
struct PendingClipboardAction {
content: String,
paste: bool,
}
@@ -55,6 +54,7 @@ struct PendingClipboardAction {
struct RowActions {
copy: Button,
paste: Button,
pin: Button,
delete: Button,
}
@@ -62,6 +62,7 @@ const COPY_ICON: &str = "📋";
const PASTE_ICON: &str = "↪";
const DELETE_ICON: &str = "🗑";
const PIN_ICON: &str = "📌";
const UNPIN_ICON: &str = "📍";
const CLEAR_ICON: &str = "🧹";
const PAUSE_ICON: &str = "⏸";
@@ -168,6 +169,7 @@ fn build_window(
let row_actions = RowActions {
copy: copy_button.clone(),
paste: paste_button.clone(),
pin: pin_button.clone(),
delete: delete_button.clone(),
};
let hotkey_status = if state.borrow().hotkey.is_some() {
@@ -175,9 +177,11 @@ fn build_window(
} else {
format!("global shortcut unavailable: {}", config.global_shortcut)
};
let status = Label::new(Some(&format!(
"Recording clipboard changes · {hotkey_status}"
)));
let status = Label::new(None);
set_status(
&status,
&format!("Recording clipboard changes · {hotkey_status}"),
);
actions.append(&copy_button);
actions.append(&paste_button);
actions.append(&pin_button);
@@ -273,11 +277,14 @@ fn build_window(
format!("{PAUSE_ICON} Resume Recording")
};
pause_button_for_keys.set_label(&pause_label);
status_for_keys.set_text(if state.recording {
"Recording clipboard changes"
} else {
"Recording paused"
});
set_status(
&status_for_keys,
if state.recording {
"Recording clipboard changes"
} else {
"Recording paused"
},
);
tracing::info!(
recording = state.recording,
"clipboard recording state changed"
@@ -300,7 +307,7 @@ fn build_window(
}
Err(error) => {
tracing::error!(%error, "failed to clear unpinned clipboard history");
status_for_keys.set_text("Could not clear clipboard history");
set_status(&status_for_keys, "Could not clear clipboard history");
}
}
return glib::Propagation::Stop;
@@ -316,7 +323,10 @@ fn build_window(
let paste = modifiers.contains(gtk4::gdk::ModifierType::CONTROL_MASK);
let paste_target = if paste {
let Some(target) = state.previous_focus else {
status_for_keys.set_text("Could not determine previous focus window");
set_status(
&status_for_keys,
"Could not determine previous focus window",
);
return glib::Propagation::Stop;
};
Some(target)
@@ -330,17 +340,14 @@ fn build_window(
{
Ok(()) => {
state.expected_change.expect(&entry.content);
state.pending_clipboard_action = Some(PendingClipboardAction {
content: entry.content,
paste,
});
state.pending_clipboard_action = Some(PendingClipboardAction { paste });
if !paste {
window_for_keys.set_visible(false);
}
}
Err(error) => {
tracing::error!(%error, "failed to queue keyboard clipboard action");
status_for_keys.set_text("Clipboard action unavailable");
set_status(&status_for_keys, "Clipboard action unavailable");
}
}
}
@@ -356,7 +363,7 @@ fn build_window(
}
Err(error) => {
tracing::error!(%error, "failed to pin clipboard entry");
status_for_keys.set_text("Could not update pin state");
set_status(&status_for_keys, "Could not update pin state");
}
}
refresh_list(
@@ -381,7 +388,7 @@ fn build_window(
}
Err(error) => {
tracing::error!(%error, "failed to delete clipboard entry");
status_for_keys.set_text("Could not delete clipboard entry");
set_status(&status_for_keys, "Could not delete clipboard entry");
}
}
return glib::Propagation::Stop;
@@ -403,14 +410,12 @@ fn build_window(
match state.clipboard_worker.request_write(&entry.content, None) {
Ok(()) => {
state.expected_change.expect(&entry.content);
state.pending_clipboard_action = Some(PendingClipboardAction {
content: entry.content,
paste: false,
});
state.pending_clipboard_action =
Some(PendingClipboardAction { paste: false });
}
Err(error) => {
tracing::error!(%error, "failed to queue clipboard copy");
status_for_copy.set_text("Clipboard copy unavailable");
set_status(&status_for_copy, "Clipboard copy unavailable");
}
}
}
@@ -428,7 +433,7 @@ fn build_window(
}
let Some(target) = state.previous_focus else {
tracing::error!("cannot paste selected clipboard entry because the previous focus window is unknown");
status_for_paste.set_text("Could not determine previous focus window");
set_status(&status_for_paste, "Could not determine previous focus window");
return;
};
if let Some(entry) = state.entries.iter().find(|entry| entry.id == id).cloned() {
@@ -436,13 +441,12 @@ fn build_window(
Ok(()) => {
state.expected_change.expect(&entry.content);
state.pending_clipboard_action = Some(PendingClipboardAction {
content: entry.content,
paste: true,
});
}
Err(error) => {
tracing::error!(%error, "failed to queue clipboard paste");
status_for_paste.set_text("Clipboard paste unavailable");
set_status(&status_for_paste, "Clipboard paste unavailable");
}
}
}
@@ -471,7 +475,7 @@ fn build_window(
}
Err(error) => {
tracing::error!(%error, "failed to pin clipboard entry");
status_for_pin.set_text("Could not update pin state");
set_status(&status_for_pin, "Could not update pin state");
}
}
}
@@ -497,7 +501,7 @@ fn build_window(
}
Err(error) => {
tracing::error!(%error, "failed to delete clipboard entry");
status_for_delete.set_text("Could not delete clipboard entry");
set_status(&status_for_delete, "Could not delete clipboard entry");
}
}
}
@@ -521,7 +525,7 @@ fn build_window(
}
Err(error) => {
tracing::error!(%error, "failed to clear unpinned clipboard history");
status_for_clear.set_text("Could not clear clipboard history");
set_status(&status_for_clear, "Could not clear clipboard history");
}
}
});
@@ -537,11 +541,14 @@ fn build_window(
format!("{PAUSE_ICON} Resume Recording")
};
button.set_label(&pause_label);
status_for_pause.set_text(if state.recording {
"Recording clipboard changes"
} else {
"Recording paused"
});
set_status(
&status_for_pause,
if state.recording {
"Recording clipboard changes"
} else {
"Recording paused"
},
);
tracing::info!(
recording = state.recording,
"clipboard recording state changed"
@@ -606,7 +613,10 @@ fn build_window(
window_for_events.present();
search_for_events.grab_focus();
} else {
status_for_events.set_text("Could not determine previous focus window");
set_status(
&status_for_events,
"Could not determine previous focus window",
);
}
}
ClipboardWorkerResult::Action {
@@ -616,40 +626,19 @@ fn build_window(
if let Some(action) = state.pending_clipboard_action.take() {
match result {
Ok(()) => {
let mut history_status = if action.paste {
let history_status = if action.paste {
"Pasted clipboard entry"
} else {
"Copied clipboard entry"
};
if let Err(error) =
state.database.upsert_content(&action.content, now())
{
tracing::error!(%error, "failed to update restored clipboard entry");
history_status =
"Clipboard action succeeded; history update failed";
} else if let Err(error) =
state.database.trim_unpinned(config_for_watch.history_limit)
{
tracing::error!(%error, "failed to enforce history limit after restore");
history_status =
"Clipboard action succeeded; history limit update failed";
} else if let Ok(entries) = state.database.load_entries() {
state.entries = entries;
refresh_list(
&list_for_watch,
&state.entries,
&state.search_query,
Some(&row_actions_for_watch),
);
}
status_for_events.set_text(history_status);
set_status(&status_for_events, history_status);
}
Err(error) => {
if !clipboard_written {
state.expected_change.clear();
}
tracing::error!(%error, "clipboard action failed; clipboard contents were preserved if the write succeeded");
status_for_events.set_text("Clipboard action failed");
set_status(&status_for_events, "Clipboard action failed");
if action.paste {
window_for_events.set_visible(true);
}
@@ -723,6 +712,10 @@ fn request_focus(state: &mut UiState) {
}
}
fn set_status(label: &Label, message: &str) {
label.set_text(&format!("[{}] {message}", now()));
}
fn refresh_list(
list: &ListBox,
entries: &[crate::core::Entry],
@@ -753,6 +746,23 @@ fn refresh_list(
label.set_margin_end(8);
let row = ListBoxRow::new();
let content = GtkBox::new(Orientation::Horizontal, 4);
if let Some(actions) = actions {
let pin_button = Button::with_label(if entry.pinned { UNPIN_ICON } else { PIN_ICON });
pin_button.set_tooltip_text(Some(if entry.pinned {
"Unpin entry"
} else {
"Pin entry"
}));
pin_button.set_focus_on_click(false);
let row_for_action = row.clone();
let list_for_action = list.clone();
let pin_action = actions.pin.clone();
pin_button.connect_clicked(move |_| {
list_for_action.select_row(Some(&row_for_action));
pin_action.emit_clicked();
});
content.append(&pin_button);
}
label.set_hexpand(true);
content.append(&label);
if let Some(actions) = actions {