F1: cosmetics: regex error reason, one date format, Close Tab
- Find shows a bad regex as "invalid pattern: unclosed group": the search crate keeps only the parser's reason, the UI drops the invalid-params prefix (userMessage). - Dates read YYYY-MM-DD / YYYY-MM-DD HH:mm in local time everywhere (i18n formatDate/formatDateTime): Log, stash list, blame, recovery. - buffer.close is "Close Tab" in the palette as in the menu; an engine test keeps palette labels starting with their menu item's wording. - Docs: architecture, install (Jump List), localization parity, checklist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1b6bd1f870
commit
33a7185d75
18 changed files with 147 additions and 52 deletions
|
|
@ -27,7 +27,7 @@
|
|||
import { RangeSet, RangeSetBuilder, StateEffect, StateField, type EditorState, type Extension, type Text } from "@codemirror/state";
|
||||
import { EditorView, GutterMarker, ViewPlugin, gutter, showTooltip, type PluginValue, type Tooltip, type ViewUpdate } from "@codemirror/view";
|
||||
import { runWaiting, type JsonValue } from "../../ipc";
|
||||
import { t } from "../../i18n";
|
||||
import { formatDate, formatDateTime, t } from "../../i18n";
|
||||
import type { AssistBuffer } from "./assist";
|
||||
|
||||
/** Delay between the last edit and the query. */
|
||||
|
|
@ -154,18 +154,13 @@ export function ageLevel(iso: string, now: number): number {
|
|||
}
|
||||
|
||||
/**
|
||||
* A short local date, `YYYY-MM-DD`.
|
||||
* A short local date, `YYYY-MM-DD` ({@link formatDate}).
|
||||
*
|
||||
* @param iso - ISO 8601 date.
|
||||
* @returns the date, or the input when it cannot be read.
|
||||
*/
|
||||
export function shortDate(iso: string): string {
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return iso;
|
||||
}
|
||||
const pad = (n: number): string => String(n).padStart(2, "0");
|
||||
return `${String(date.getFullYear())}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
||||
return formatDate(iso);
|
||||
}
|
||||
|
||||
/** The text and look of one annotated line. */
|
||||
|
|
@ -343,9 +338,7 @@ function hoverCard(line: BlameLine): { dom: HTMLElement; message: HTMLElement }
|
|||
head.textContent = t("editor.blame.notCommitted");
|
||||
message.textContent = t("editor.blame.notCommittedHint");
|
||||
} else {
|
||||
const date = new Date(line.date);
|
||||
const when = Number.isNaN(date.getTime()) ? line.date : date.toLocaleString();
|
||||
head.textContent = t("editor.blame.byLine", { hash: line.hash.slice(0, 8), author: line.author, date: when });
|
||||
head.textContent = t("editor.blame.byLine", { hash: line.hash.slice(0, 8), author: line.author, date: formatDateTime(line.date) });
|
||||
message.textContent = messages.get(line.hash) ?? line.summary;
|
||||
const hint = document.createElement("div");
|
||||
hint.className = "lt-blame-tooltip__hint";
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
* failures, they are listed until the dialog is closed.
|
||||
*/
|
||||
import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { t } from "../../i18n";
|
||||
import { formatDateTime, t } from "../../i18n";
|
||||
import { useRecoveryStore } from "./recovery";
|
||||
|
||||
const recovery = useRecoveryStore();
|
||||
|
|
@ -55,7 +55,7 @@ watch(
|
|||
* @param savedAt - ms since the Unix epoch.
|
||||
*/
|
||||
function formatTime(savedAt: number): string {
|
||||
return new Date(savedAt).toLocaleString();
|
||||
return formatDateTime(savedAt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
import { RefreshCw, X } from "@lucide/vue";
|
||||
import { computed, nextTick, onBeforeUnmount, ref } from "vue";
|
||||
import { t } from "../../../i18n";
|
||||
import { formatDateTime, t } from "../../../i18n";
|
||||
import { useProjectStore } from "../../../stores/project";
|
||||
import { SHORT_HASH } from "../changes/changes";
|
||||
import { refBadges, useLogStore, type CommitFile, type CommitFileStatus } from "./log";
|
||||
|
|
@ -138,16 +138,12 @@ function rowAt(index: number): GraphRow | null {
|
|||
}
|
||||
|
||||
/**
|
||||
* A date for the list: the local date and time, short.
|
||||
* A date for the list: the local date and time, `YYYY-MM-DD HH:mm`.
|
||||
*
|
||||
* @param iso - ISO 8601 date.
|
||||
*/
|
||||
function shortDate(iso: string): string {
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return iso;
|
||||
}
|
||||
return date.toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
||||
return formatDateTime(iso);
|
||||
}
|
||||
|
||||
/** Applies the typed filters now. */
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import { Archive } from "@lucide/vue";
|
|||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { useModalsStore } from "../../../commands/modals";
|
||||
import { useCommandsStore } from "../../../commands/store";
|
||||
import { t } from "../../../i18n";
|
||||
import { formatDateTime, t } from "../../../i18n";
|
||||
import { useStashStore, type StashEntry } from "./stash";
|
||||
|
||||
const stash = useStashStore();
|
||||
|
|
@ -57,16 +57,12 @@ function refName(entry: StashEntry): string {
|
|||
}
|
||||
|
||||
/**
|
||||
* A date for the list: the local date and time, short.
|
||||
* A date for the list: the local date and time, `YYYY-MM-DD HH:mm`.
|
||||
*
|
||||
* @param iso - ISO 8601 date.
|
||||
*/
|
||||
function shortDate(iso: string): string {
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return iso;
|
||||
}
|
||||
return date.toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
||||
return formatDateTime(iso);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -55,3 +55,55 @@ export function t(key: string, params?: MessageParams): string {
|
|||
return value === undefined ? placeholder : String(value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Two digits, with a leading zero.
|
||||
*
|
||||
* @param n - a number from 0 to 99.
|
||||
*/
|
||||
function pad(n: number): string {
|
||||
return String(n).padStart(2, "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a date: an ISO 8601 text or milliseconds since the Unix epoch.
|
||||
*
|
||||
* @param value - the date.
|
||||
* @returns the date, or null when it cannot be read.
|
||||
*/
|
||||
function toDate(value: string | number): Date | null {
|
||||
const date = new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
}
|
||||
|
||||
/**
|
||||
* A date as Lutra shows it everywhere: `YYYY-MM-DD` in local time. One
|
||||
* fixed format instead of the system locale's, so dates read the same in
|
||||
* every part of the English interface (`01.11.2026` next to English text
|
||||
* looked broken). G14 may switch to the interface language's format.
|
||||
*
|
||||
* @param value - an ISO 8601 text or milliseconds since the Unix epoch.
|
||||
* @returns the date, or the input as text when it cannot be read.
|
||||
*/
|
||||
export function formatDate(value: string | number): string {
|
||||
const date = toDate(value);
|
||||
if (!date) {
|
||||
return String(value);
|
||||
}
|
||||
return `${String(date.getFullYear())}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A date and time as Lutra shows it everywhere: `YYYY-MM-DD HH:mm` in
|
||||
* local time, 24-hour clock (see {@link formatDate}).
|
||||
*
|
||||
* @param value - an ISO 8601 text or milliseconds since the Unix epoch.
|
||||
* @returns the date and time, or the input as text when it cannot be read.
|
||||
*/
|
||||
export function formatDateTime(value: string | number): string {
|
||||
const date = toDate(value);
|
||||
if (!date) {
|
||||
return String(value);
|
||||
}
|
||||
return `${formatDate(value)} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
* - **One search at a time:** a new search cancels the running one
|
||||
* (`search.cancel`); the engine does not do that by itself.
|
||||
* - **Errors:** a refused search (`invalid_params` for a bad regex or glob)
|
||||
* shows its message in the window, not as a toast.
|
||||
* shows its reason (`userMessage`, without the engine's command prefix) in
|
||||
* the window, not as a toast.
|
||||
* - **Opening:** `open` shows the panel, takes the query from the params
|
||||
* (an agent's `find.open {query}` searches at once) or from the editor
|
||||
* (selection or word at the cursor) and asks the window to focus its field.
|
||||
|
|
@ -23,7 +24,7 @@ import type { EditorState } from "@codemirror/state";
|
|||
import { defineStore } from "pinia";
|
||||
import { computed, ref, shallowRef } from "vue";
|
||||
import { t } from "../i18n";
|
||||
import { onEngineEvent, run, type EngineEventPayload, type JsonValue } from "../ipc";
|
||||
import { onEngineEvent, run, userMessage, type EngineEventPayload, type JsonValue } from "../ipc";
|
||||
import { useEditorStore } from "./editor";
|
||||
|
||||
/** One match as the window shows it. */
|
||||
|
|
@ -351,7 +352,7 @@ export const useFindStore = defineStore("find", () => {
|
|||
early = [];
|
||||
if (!result.ok) {
|
||||
running.value = false;
|
||||
error.value = result.error.message;
|
||||
error.value = userMessage(result.error);
|
||||
return;
|
||||
}
|
||||
if (id === null) {
|
||||
|
|
|
|||
|
|
@ -397,9 +397,9 @@ describe("Find tool window", () => {
|
|||
|
||||
it("shows a refused regex as an alert", async () => {
|
||||
const { wrapper } = await mountFind();
|
||||
findError = { code: "invalid_params", message: "bad regex" };
|
||||
findError = { code: "invalid_params", message: "invalid params for search.find: invalid pattern: unclosed group" };
|
||||
await searchFor(wrapper, "(");
|
||||
expect(wrapper.get("[data-test=find-error]").text()).toBe("bad regex");
|
||||
expect(wrapper.get("[data-test=find-error]").text()).toBe("invalid pattern: unclosed group");
|
||||
expect(wrapper.get("[data-test=find-query]").attributes("aria-invalid")).toBe("true");
|
||||
expect(wrapper.get("[data-test=find-status]").text()).toBe("");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
/**
|
||||
* Tests of the message catalog: the `t` helper (lookup, interpolation,
|
||||
* missing keys) and a scan of the frontend source that every literal key
|
||||
* missing keys), the one date format, and a scan of the frontend source that every literal key
|
||||
* passed to `t` exists in `en.json`.
|
||||
*/
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import en from "../../src/i18n/en.json";
|
||||
import { hasMessage, t } from "../../src/i18n";
|
||||
import { formatDate, formatDateTime, hasMessage, t } from "../../src/i18n";
|
||||
|
||||
/** Root of the frontend source tree. */
|
||||
const SRC = join(import.meta.dirname, "..", "..", "src");
|
||||
|
|
@ -205,3 +205,15 @@ describe("en.json", () => {
|
|||
expect(Object.keys(en).filter((key) => !used.has(key))).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dates", () => {
|
||||
it("shows every date as YYYY-MM-DD and times as HH:mm in local time, whatever the system locale", () => {
|
||||
const local = new Date(2026, 10, 1, 9, 5, 30);
|
||||
expect(formatDate(local.getTime())).toBe("2026-11-01");
|
||||
expect(formatDateTime(local.getTime())).toBe("2026-11-01 09:05");
|
||||
expect(formatDateTime("2026-12-24T18:30:00")).toBe("2026-12-24 18:30");
|
||||
expect(formatDate("2026-03-07T23:59:00")).toBe("2026-03-07");
|
||||
expect(formatDateTime("not a date")).toBe("not a date");
|
||||
expect(formatDate("")).toBe("");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import SettingsDialog from "../../src/components/settings/SettingsDialog.vue";
|
|||
const ENGINE_COMMANDS = [
|
||||
{ id: "app.about", label: "About Lutra", menuPath: "Help/About Lutra", defaultShortcut: null, params: "", enabled: true, ui: false },
|
||||
{ id: "app.quit", label: "Quit", menuPath: "File/Quit", defaultShortcut: "Mod+Q", params: "", enabled: true, ui: false },
|
||||
{ id: "buffer.close", label: "Close Buffer", menuPath: "File/Close Tab", defaultShortcut: "Mod+W", params: "", enabled: false, ui: false },
|
||||
{ id: "buffer.close", label: "Close Tab", menuPath: "File/Close Tab", defaultShortcut: "Mod+W", params: "", enabled: false, ui: false },
|
||||
{ id: "buffer.edit", label: "Edit Buffer", menuPath: null, defaultShortcut: null, params: "", enabled: true, ui: false },
|
||||
{ id: "file.save", label: "Save", menuPath: "File/Save", defaultShortcut: "Mod+S", params: "", enabled: true, ui: false },
|
||||
{ id: "file.saveAll", label: "Save All", menuPath: "File/Save All", defaultShortcut: "Mod+Alt+S", params: "", enabled: true, ui: false },
|
||||
|
|
|
|||
|
|
@ -112,9 +112,7 @@ describe("RecoveryDialog", () => {
|
|||
"src/b.php",
|
||||
"c.php",
|
||||
]);
|
||||
expect(rows[0]?.text()).toContain(
|
||||
`Saved ${new Date(ENTRIES[0]?.savedAt ?? 0).toLocaleString()}`,
|
||||
);
|
||||
expect(rows[0]?.text()).toMatch(/Saved \d{4}-\d{2}-\d{2} \d{2}:\d{2}/);
|
||||
expect(rows[0]?.find("[data-test=recovery-changed]").exists()).toBe(false);
|
||||
expect(rows[1]?.get("[data-test=recovery-changed]").text()).toBe(
|
||||
"The file changed on disk since then",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue