Group six more clusters out of web/src/lib
Takes the flat module count from 66 to 42, continuing what admin/ and
calendar/ started.
lib/mailbox/ archiveDate, emptyFolder, folderMove, labelTree,
mailboxName, mailboxRoute
lib/sieve/ sieve, sieveApply, sieveFolders
lib/input/ keyboard, swipe, touch, listSelection, dropUpload
lib/notify/ notify, webpush, webpushEnable
lib/sw/ swCache, swFacts, staleBuild
lib/text/ html, markdown, text, emlName
FOUR THINGS THE FILENAMES GET WRONG, each checked by reading the file
rather than trusting what it is called:
- appFolder is not a mailbox. It is the `ihasmail` folder in JMAP
*Files*, where the client keeps signature images and synced settings.
It stays flat.
- format holds no formatting of text. It re-exports the date and clock
formatters, so it belongs with dates/datetime, not with text/.
- preview is the file viewer deciding what it can show without
downloading, and source is where to point someone asking for this
instance's AGPL source. Neither is about text.
- notify is not Web Push. It is the tab title, the favicon badge and
the new-mail sound -- in-app notification, which is why it sits with
webpush rather than under sw/ with the service worker's own concerns.
threadScroll stays flat too: it decides where a conversation opens, which
is view state rather than a gesture, and input/ is honest only if
everything in it interprets something the reader did.
No behavior change. Almost every reference was on the @/ alias; eight
relative imports in files that did not move, or that moved away from a
sibling, needed rewriting by hand.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import type { Id } from "@/jmap/types";
|
||||
|
||||
/**
|
||||
* What a click on a message row means.
|
||||
*
|
||||
* Lifted out of the list so the rules sit together and can be tested. They had
|
||||
* drifted apart while they were two branches of one handler: shift-click
|
||||
* selected the whole range including the row it started from, and ctrl-click
|
||||
* selected only the row clicked, leaving the message you had open highlighted
|
||||
* but unticked. Both looked picked; one was. That is issue #186, and the reason
|
||||
* this is a function rather than a comment asking the next person to be careful.
|
||||
*/
|
||||
|
||||
export type RowClick =
|
||||
| { kind: "open" }
|
||||
| { kind: "select"; ids: Id[]; on: boolean; moveAnchor: boolean };
|
||||
|
||||
export function rowClick(opts: {
|
||||
/** The row clicked. */
|
||||
rowId: Id;
|
||||
/** Every row on screen, in the order they are shown. */
|
||||
ids: Id[];
|
||||
/** The row a range would extend from: the last one clicked without shift. */
|
||||
anchor: Id | null;
|
||||
selected: Record<Id, boolean>;
|
||||
modifiers: { shift: boolean; ctrl: boolean };
|
||||
isMobile: boolean;
|
||||
}): RowClick {
|
||||
const { rowId, ids, anchor, selected, modifiers, isMobile } = opts;
|
||||
const selectedCount = Object.keys(selected).length;
|
||||
|
||||
// A range, from the anchor to here, inclusive at both ends.
|
||||
if (modifiers.shift && anchor) {
|
||||
const from = ids.indexOf(anchor);
|
||||
const to = ids.indexOf(rowId);
|
||||
if (from >= 0 && to >= 0) {
|
||||
const [start, end] = from < to ? [from, to] : [to, from];
|
||||
// The anchor stays where it is, so extending the range again grows it
|
||||
// from the same place rather than from wherever it last reached.
|
||||
return { kind: "select", ids: ids.slice(start, end + 1), on: true, moveAnchor: false };
|
||||
}
|
||||
}
|
||||
|
||||
if (modifiers.ctrl) {
|
||||
/*
|
||||
* The row that was already current joins the selection.
|
||||
*
|
||||
* Opening a message does not select it -- it is highlighted because it is
|
||||
* the one being read, which is a different state -- so picking a second one
|
||||
* with ctrl used to select only the second, and every action that followed
|
||||
* quietly applied to half of what the screen showed.
|
||||
*
|
||||
* Only while nothing is selected yet. Once there is a selection, ctrl-click
|
||||
* toggles exactly one row, which is the whole point of it.
|
||||
*/
|
||||
if (!selectedCount && anchor && anchor !== rowId && ids.includes(anchor)) {
|
||||
return { kind: "select", ids: [anchor, rowId], on: true, moveAnchor: true };
|
||||
}
|
||||
return { kind: "select", ids: [rowId], on: !selected[rowId], moveAnchor: true };
|
||||
}
|
||||
|
||||
// On a touchscreen, once anything is selected a plain tap goes on selecting:
|
||||
// there is no modifier to hold, and opening a message mid-selection is almost
|
||||
// never what the tap meant.
|
||||
if (selectedCount > 0 && isMobile) {
|
||||
return { kind: "select", ids: [rowId], on: !selected[rowId], moveAnchor: true };
|
||||
}
|
||||
|
||||
return { kind: "open" };
|
||||
}
|
||||
Reference in New Issue
Block a user