mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-18 16:08:55 +00:00
fix(vcs): translate commit message hints and offer Add blank line (#3749)
The commit message inspections were shown as untranslated English text with no way to act on them, so the subject/body hint read like an error that blocked line breaks. They now go through the text catalog, and the missing blank line hint has an Add blank line fix that inserts it and keeps the caret. Fixes #3732
This commit is contained in:
@@ -354,3 +354,15 @@
|
||||
[role="treeitem"][aria-selected="true"] .stageButton {
|
||||
visibility: visible;
|
||||
}
|
||||
.inspectionFix {
|
||||
margin-left: var(--space-2);
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--link);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.inspectionFix:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
type MouseEvent,
|
||||
type PointerEvent,
|
||||
} from "react";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { tx, txTemplate } from "@/platform/i18n";
|
||||
import clsx from "clsx";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { basename, dirname } from "@/platform/project";
|
||||
@@ -961,6 +961,14 @@ export function ChangesTree({ mode }: { mode: "commit" | "local" | "dialog" }) {
|
||||
);
|
||||
}
|
||||
|
||||
const MISSING_BLANK_LINE = "Missing blank line between subject and body";
|
||||
|
||||
/** The quick fix for {@link MISSING_BLANK_LINE}: an empty line after the subject. */
|
||||
export function addBlankLineAfterSubject(message: string): string {
|
||||
const end = message.indexOf("\n");
|
||||
return end < 0 ? message : `${message.slice(0, end)}\n${message.slice(end)}`;
|
||||
}
|
||||
|
||||
/** Commit message inspections (Settings › Version Control › Commit). */
|
||||
export function messageProblems(
|
||||
message: string,
|
||||
@@ -976,8 +984,7 @@ export function messageProblems(
|
||||
const out: string[] = [];
|
||||
if (c.limitSubject && (lines[0]?.length ?? 0) > c.subjectLimit)
|
||||
out.push(`Subject line is longer than ${c.subjectLimit} characters`);
|
||||
if (c.blankLineAfterSubject && lines.length > 1 && lines[1]!.trim() !== "")
|
||||
out.push("Missing blank line between subject and body");
|
||||
if (c.blankLineAfterSubject && lines.length > 1 && lines[1]!.trim() !== "") out.push(MISSING_BLANK_LINE);
|
||||
if (c.limitBody) {
|
||||
const long = lines.slice(1).findIndex((l) => l.length > c.bodyLimit);
|
||||
if (long >= 0) out.push(`Body line ${long + 2} is longer than ${c.bodyLimit} characters`);
|
||||
@@ -1160,7 +1167,29 @@ export function CommitMessageField({
|
||||
)}
|
||||
{problems.length > 0 && (
|
||||
<div className={styles.inspections} role="status">
|
||||
{problems.join(" · ")}
|
||||
{problems.map((p, i) => (
|
||||
<span key={p}>
|
||||
{i > 0 && " · "}
|
||||
{txTemplate(p)}
|
||||
{p === MISSING_BLANK_LINE && (
|
||||
<button
|
||||
type="button"
|
||||
className={styles.inspectionFix}
|
||||
onClick={() => {
|
||||
const el = ref.current;
|
||||
const caret = el ? el.selectionStart + (el.selectionStart > first.length ? 1 : 0) : 0;
|
||||
useCommit.setState({ message: addBlankLineAfterSubject(message) });
|
||||
requestAnimationFrame(() => {
|
||||
el?.focus();
|
||||
el?.setSelectionRange(caret, caret);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<T>Add blank line</T>
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{checkProblems.length > 0 && (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { BranchInfo } from "@/bindings";
|
||||
import { messageProblems, wrapAtMargin } from "../CommitView";
|
||||
import { addBlankLineAfterSubject, messageProblems, wrapAtMargin } from "../CommitView";
|
||||
import { linkifyIssues } from "../issueLinks";
|
||||
import {
|
||||
isProtectedBranch,
|
||||
@@ -41,6 +41,14 @@ describe("commit message inspections", () => {
|
||||
expect(messageProblems("x".repeat(20), { ...cfg, limitSubject: false })).toEqual([]);
|
||||
});
|
||||
|
||||
it("adds the missing blank line after the subject", () => {
|
||||
const fixed = addBlankLineAfterSubject("111\n111");
|
||||
expect(fixed).toBe("111\n\n111");
|
||||
expect(messageProblems(fixed, cfg)).toEqual([]);
|
||||
expect(addBlankLineAfterSubject("subject\nline 2\nline 3")).toBe("subject\n\nline 2\nline 3");
|
||||
expect(addBlankLineAfterSubject("subject")).toBe("subject");
|
||||
});
|
||||
|
||||
it("wraps body lines at the last space before the margin", () => {
|
||||
const text = "subject\n\nhello world again";
|
||||
expect(wrapAtMargin(text, text.length, 12)).toEqual({ text: "subject\n\nhello world\nagain", caret: text.length });
|
||||
|
||||
@@ -2158,5 +2158,8 @@
|
||||
"The interface could not be extracted": "The interface could not be extracted",
|
||||
"Extract Interface is not supported for {name}": "Extract Interface is not supported for {name}",
|
||||
"Package for new interface": "Package for new interface",
|
||||
"Untitled files were not saved": "Untitled files were not saved"
|
||||
"Untitled files were not saved": "Untitled files were not saved",
|
||||
"Missing blank line between subject and body": "Missing blank line between subject and body",
|
||||
"Body line {0} is longer than {1} characters": "Body line {0} is longer than {1} characters",
|
||||
"Add blank line": "Add blank line"
|
||||
}
|
||||
|
||||
@@ -8541,5 +8541,8 @@
|
||||
"The interface could not be extracted": "无法提取接口",
|
||||
"Extract Interface is not supported for {name}": "{name} 不支持提取接口",
|
||||
"Package for new interface": "新接口的软件包",
|
||||
"Untitled files were not saved": "未命名文件未保存"
|
||||
"Untitled files were not saved": "未命名文件未保存",
|
||||
"Missing blank line between subject and body": "主题和正文之间缺少空行",
|
||||
"Body line {0} is longer than {1} characters": "正文第 {0} 行超过 {1} 个字符",
|
||||
"Add blank line": "添加空行"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user