дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
feat(vcs): show Today / Yesterday in the annotate gutter with pretty dates (#6110)
The annotate gutter now shows Today / Yesterday when the global date format's "Use pretty formatting" is on, as IDEA's annotate does (FileAnnotation.formatDate -> DateFormatUtil.formatPrettyDate); older dates, and all dates with pretty formatting off, keep the short date. New formatPrettyDay next to formatTimestamp. Co-authored-by: muutot <[email protected]>
Цей коміт міститься в:
1 джерело
b283d352b7
коміт
138209c627
6 files changed
+52
-4
No files matched your search
@@ -90,7 +90,7 @@ Settings › Appearance & Behavior › System Settings, unless noted.
|
||||
| `dateFormat.overrideSystem` | `false` | **Override system date and time format** (Date Formats page). |
|
||||
| `dateFormat.pattern` | `"dd.MM.yyyy"` | Date pattern with `dd`, `MM`, `MMM`, `yy`, `yyyy`. |
|
||||
| `dateFormat.use24Hour` | `true` | 24-hour time. |
|
||||
| `dateFormat.pretty` | `true` | "Today", "Yesterday", "5 min ago". |
|
||||
| `dateFormat.pretty` | `true` | "Today", "Yesterday", "5 min ago" (in lists with time, in the annotate gutter as the day alone). |
|
||||
|
||||
### `[appearance]`
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ exclude = ["**/.git", "**/node_modules", "**/target", "**/dist"]
|
||||
| `dateFormat.overrideSystem` | `false` | **覆盖系统日期和时间格式**(日期格式页)。 |
|
||||
| `dateFormat.pattern` | `"dd.MM.yyyy"` | 日期格式,可用 `dd`、`MM`、`MMM`、`yy`、`yyyy`。 |
|
||||
| `dateFormat.use24Hour` | `true` | 使用 24 小时制。 |
|
||||
| `dateFormat.pretty` | `true` | 显示“今天”“昨天”“5 分钟前”这类相对时间。 |
|
||||
| `dateFormat.pretty` | `true` | 显示“今天”“昨天”“5 分钟前”这类相对时间(列表中带时间,注解装订区域仅显示日期)。 |
|
||||
|
||||
### `[appearance]`
|
||||
|
||||
|
||||
@@ -276,6 +276,27 @@ describe("annotate Options", () => {
|
||||
const hidden = (v: EditorView) =>
|
||||
["date", "author", "revision"].filter((c) => v.dom.classList.contains(`cm-vcs-blame-hide-${c}`));
|
||||
|
||||
it("prints Today/Yesterday in the date cell when pretty formatting is on", async () => {
|
||||
const today = Date.now();
|
||||
const yesterday = today - 86_400_000;
|
||||
const recentLines: BlameLine[] = [
|
||||
{ commit: sha, author: "Aleks Zlateski", timeMs: today, summary: "today" },
|
||||
{ commit: otherSha, author: "Dan Crankshaw", timeMs: yesterday, summary: "yesterday" },
|
||||
];
|
||||
mocks.blame.mockResolvedValue({ status: "ok", data: recentLines });
|
||||
useProject.setState({ settings: { general: { dateFormat: { pretty: true } } } });
|
||||
const created = new EditorView({
|
||||
parent: document.body,
|
||||
state: EditorState.create({ doc: "first\nsecond\nthird", extensions: [blameSlot()] }),
|
||||
});
|
||||
view = created;
|
||||
await toggleAnnotations(created, "/repo/src/main.py");
|
||||
const cell = (commit: string) =>
|
||||
created.dom.querySelector<HTMLElement>(`.cm-vcs-blame [data-commit="${commit}"] .cm-vcs-blame-date`)?.textContent;
|
||||
expect(cell(sha)).toBe("Today");
|
||||
expect(cell(otherSha)).toBe("Yesterday");
|
||||
});
|
||||
|
||||
it("shows date and author by default and adds the revision from Options", async () => {
|
||||
view = await annotated();
|
||||
expect(
|
||||
|
||||
@@ -11,7 +11,7 @@ import { onWorkflowSettingsChange, workflowSettings } from "@/platform/workflowS
|
||||
import { showContextMenu, type MenuItem } from "@/ui";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { closeBlamePopup, scheduleCloseBlamePopup, scheduleOpenBlamePopup } from "./BlamePopup";
|
||||
import { formatDate } from "./model";
|
||||
import { formatPrettyDay } from "@/platform/dateFormat";
|
||||
import { saveVcsSetting } from "./settingsUi";
|
||||
import { useVcs } from "./store";
|
||||
|
||||
@@ -318,7 +318,7 @@ function build(lines: BlameLine[], doc: Text): BlameState {
|
||||
let label = labels.get(line.commit);
|
||||
if (!label && !isUncommitted(line)) {
|
||||
label = {
|
||||
date: formatDate(line.timeMs),
|
||||
date: line.timeMs ? formatPrettyDay(line.timeMs) : "",
|
||||
author: shortAuthorName(line.author, names),
|
||||
revision: line.commit.slice(0, 8),
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
formatDateTime,
|
||||
formatDay,
|
||||
formatPattern,
|
||||
formatPrettyDay,
|
||||
formatTimestamp,
|
||||
} from "./dateFormat";
|
||||
|
||||
@@ -33,6 +34,19 @@ describe("dateFormat", () => {
|
||||
expect(formatTimestamp(d.getTime(), now, custom)).toBe("05.11.2026 09:07");
|
||||
});
|
||||
|
||||
it("shows Today/Yesterday without a clock time for blame, older dates keep the short date", () => {
|
||||
const now = new Date(2026, 10, 13, 12, 0).getTime();
|
||||
const pretty = { ...system, pretty: true };
|
||||
const older = new Date(2026, 10, 5, 9, 7);
|
||||
const short = { year: "2-digit", month: "2-digit", day: "2-digit" } as const;
|
||||
expect(formatPrettyDay(new Date(2026, 10, 13, 9, 7).getTime(), now, pretty)).toBe("Today");
|
||||
expect(formatPrettyDay(new Date(2026, 10, 12, 23, 30).getTime(), now, pretty)).toBe("Yesterday");
|
||||
expect(formatPrettyDay(older.getTime(), now, pretty)).toBe(older.toLocaleDateString(undefined, short));
|
||||
expect(formatPrettyDay(new Date(2026, 10, 13, 9, 7).getTime(), now, { ...system, pretty: false })).toBe(
|
||||
new Date(2026, 10, 13, 9, 7).toLocaleDateString(undefined, short),
|
||||
);
|
||||
});
|
||||
|
||||
it("formats another date with the same cached formatter", () => {
|
||||
const e = new Date(2025, 0, 31);
|
||||
formatDay(d, system);
|
||||
|
||||
@@ -99,3 +99,16 @@ export function formatTimestamp(ms: number, now = Date.now(), o: DateFormatOptio
|
||||
}
|
||||
return formatDateTime(d, o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Day without clock time (blame gutter): "Today" / "Yesterday" when pretty
|
||||
* formatting is on, as IDEA's annotate shows; older dates keep the short date.
|
||||
*/
|
||||
export function formatPrettyDay(ms: number, now = Date.now(), o: DateFormatOptions = dateFormatOptions()): string {
|
||||
const d = new Date(ms);
|
||||
if (o.pretty) {
|
||||
if (d.toDateString() === new Date(now).toDateString()) return tx("Today");
|
||||
if (d.toDateString() === new Date(now - 86_400_000).toDateString()) return tx("Yesterday");
|
||||
}
|
||||
return formatDay(d, o, true);
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача