mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
A user accidentally dragged a list into another swimlane on mobile (merging it with an existing list) and spent ~15 min recovering - no confirmation, no undo. Undo/Redo: the userPositionHistory collection modelled this but was NOT actually recording (trackChange guarded on an un-imported global) and had no redo or key bindings. Now: - list moves are recorded in updateListSort (import UserPositionHistory so the guard passes); card moves already had the call. - add a symmetric redo() model method + an undone/undoneAt redo stack; add userPositionHistory.undoLast/redoLast methods (a new action clears the redo stack via trackChange). - wire Ctrl+Z / Ctrl+Y (and Cmd variants) in client/lib/keyboard.js; disabled inside inputs/textareas so native text undo is unaffected. - pure selection logic models/lib/undoRedoSelection.js + tests. Confirmation: on touch / small screens, moving a list to a DIFFERENT swimlane (which re-homes every card) now asks for confirmation; a decline reverts the drag. Same-swimlane reordering is unaffected. Thanks to mueschel (report) and xet7.
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// #6478: pure selection rules for the position-history undo/redo stack. Kept
|
|
// Meteor-free so they can be unit tested (tests/undoRedoSelection.test.cjs); the
|
|
// server (server/models/userPositionHistory.js) applies the same rule via Mongo
|
|
// sort/limit.
|
|
//
|
|
// Stack model: real (non-checkpoint) position changes form the undo stack in
|
|
// createdAt order. Undoing one marks it `undone` with an `undoneAt` timestamp and
|
|
// moves it onto the redo stack. Redoing clears `undone`. Recording a NEW change
|
|
// clears the redo stack (drops undone entries), so redo only ever re-applies
|
|
// changes that were not superseded.
|
|
|
|
function timeOf(d) {
|
|
if (d instanceof Date) return d.getTime();
|
|
if (d == null) return 0;
|
|
const t = new Date(d).getTime();
|
|
return Number.isNaN(t) ? 0 : t;
|
|
}
|
|
|
|
// The next change to UNDO: the most recent real change not already undone.
|
|
function pickUndo(entries) {
|
|
let best = null;
|
|
for (const e of entries || []) {
|
|
if (!e || e.isCheckpoint || e.undone === true) continue;
|
|
if (best === null || timeOf(e.createdAt) >= timeOf(best.createdAt)) best = e;
|
|
}
|
|
return best;
|
|
}
|
|
|
|
// The next change to REDO: the most-recently-undone change (largest undoneAt).
|
|
function pickRedo(entries) {
|
|
let best = null;
|
|
for (const e of entries || []) {
|
|
if (!e || e.isCheckpoint || e.undone !== true) continue;
|
|
if (best === null || timeOf(e.undoneAt) >= timeOf(best.undoneAt)) best = e;
|
|
}
|
|
return best;
|
|
}
|
|
|
|
module.exports = { pickUndo, pickRedo };
|