瀏覽代碼

Fixes hovers & details commit message formatting

main
Eric Amodio 2 年之前
父節點
當前提交
aef2183219
共有 6 個文件被更改,包括 43 次插入23 次删除
  1. +5
    -3
      src/git/formatters/commitFormatter.ts
  2. +2
    -2
      src/system/string.ts
  3. +1
    -0
      src/webviews/apps/commitDetails/commitDetails.scss
  4. +8
    -4
      src/webviews/apps/commitDetails/commitDetails.ts
  5. +25
    -14
      src/webviews/commitDetails/commitDetailsWebviewView.ts
  6. +2
    -0
      src/webviews/commitDetails/protocol.ts

+ 5
- 3
src/git/formatters/commitFormatter.ts 查看文件

@ -631,9 +631,11 @@ export class CommitFormatter extends Formatter {
return this._padOrTruncate(message, this._options.tokenOptions.message); return this._padOrTruncate(message, this._options.tokenOptions.message);
} }
let message = this._options.messageTruncateAtNewLine
? this._item.summary
: this._item.message ?? this._item.summary;
let message = (
this._options.messageTruncateAtNewLine ? this._item.summary : this._item.message ?? this._item.summary
)
.trim()
.replace(/\r?\n/g, '\n');
message = emojify(message); message = emojify(message);
message = this._padOrTruncate(message, this._options.tokenOptions.message); message = this._padOrTruncate(message, this._options.tokenOptions.message);

+ 2
- 2
src/system/string.ts 查看文件

@ -116,7 +116,7 @@ export function encodeHtmlWeak(s: string | undefined): string | undefined {
const escapeMarkdownRegex = /[\\`*_{}[\]()#+\-.!]/g; const escapeMarkdownRegex = /[\\`*_{}[\]()#+\-.!]/g;
const escapeMarkdownHeaderRegex = /^===/gm; const escapeMarkdownHeaderRegex = /^===/gm;
// const sampleMarkdown = '## message `not code` *not important* _no underline_ \n> don\'t quote me \n- don\'t list me \n+ don\'t list me \n1. don\'t list me \nnot h1 \n=== \nnot h2 \n---\n***\n---\n___'; // const sampleMarkdown = '## message `not code` *not important* _no underline_ \n> don\'t quote me \n- don\'t list me \n+ don\'t list me \n1. don\'t list me \nnot h1 \n=== \nnot h2 \n---\n***\n---\n___';
const markdownQuotedRegex = /\n/g;
const markdownQuotedRegex = /\r?\n/g;
export function escapeMarkdown(s: string, options: { quoted?: boolean } = {}): string { export function escapeMarkdown(s: string, options: { quoted?: boolean } = {}): string {
s = s s = s
@ -128,7 +128,7 @@ export function escapeMarkdown(s: string, options: { quoted?: boolean } = {}): s
if (!options.quoted) return s; if (!options.quoted) return s;
// Keep under the same block-quote but with line breaks // Keep under the same block-quote but with line breaks
return s.replace(markdownQuotedRegex, '\t\\\n> ');
return s.trim().replace(markdownQuotedRegex, '\t\\\n> ');
} }
export function escapeRegex(s: string) { export function escapeRegex(s: string) {

+ 1
- 0
src/webviews/apps/commitDetails/commitDetails.scss 查看文件

@ -254,6 +254,7 @@ ul {
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
max-height: 9rem; max-height: 9rem;
white-space: break-spaces;
strong { strong {
font-weight: 600; font-weight: 600;

+ 8
- 4
src/webviews/apps/commitDetails/commitDetails.ts 查看文件

@ -10,6 +10,7 @@ import {
CommitActionsCommandType, CommitActionsCommandType,
DidChangeNotificationType, DidChangeNotificationType,
FileActionsCommandType, FileActionsCommandType,
messageHeadlineSplitterToken,
OpenFileCommandType, OpenFileCommandType,
OpenFileComparePreviousCommandType, OpenFileComparePreviousCommandType,
OpenFileCompareWorkingCommandType, OpenFileCompareWorkingCommandType,
@ -482,11 +483,14 @@ export class CommitDetailsApp extends App> {
const $el = document.querySelector<HTMLElement>('[data-region="message"]'); const $el = document.querySelector<HTMLElement>('[data-region="message"]');
if ($el == null) return; if ($el == null) return;
const [headline, ...lines] = state.selected.message.split('<br />');
if (lines.length > 0) {
$el.innerHTML = /*html*/ `<strong>${headline}</strong><br />${lines.join('<br />')}`;
const index = state.selected.message.indexOf(messageHeadlineSplitterToken);
if (index === -1) {
$el.innerHTML = /*html*/ `<strong>${state.selected.message}</strong>`;
} else { } else {
$el.innerHTML = /*html*/ `<strong>${headline}</strong>`;
$el.innerHTML = /*html*/ `<strong>${state.selected.message.substring(
0,
index,
)}</strong><br />${state.selected.message.substring(index + 3)}`;
} }
} }

+ 25
- 14
src/webviews/commitDetails/commitDetailsWebviewView.ts 查看文件

@ -10,6 +10,7 @@ import { configuration } from '../../configuration';
import { Commands, ContextKeys, CoreCommands } from '../../constants'; import { Commands, ContextKeys, CoreCommands } from '../../constants';
import type { Container } from '../../container'; import type { Container } from '../../container';
import { getContext } from '../../context'; import { getContext } from '../../context';
import { CommitFormatter } from '../../git/formatters/commitFormatter';
import type { GitCommit } from '../../git/models/commit'; import type { GitCommit } from '../../git/models/commit';
import { isCommit } from '../../git/models/commit'; import { isCommit } from '../../git/models/commit';
import type { GitFileChange } from '../../git/models/file'; import type { GitFileChange } from '../../git/models/file';
@ -20,6 +21,7 @@ import type { PullRequest } from '../../git/models/pullRequest';
import { serializePullRequest } from '../../git/models/pullRequest'; import { serializePullRequest } from '../../git/models/pullRequest';
import type { GitRevisionReference } from '../../git/models/reference'; import type { GitRevisionReference } from '../../git/models/reference';
import { GitReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference';
import type { GitRemote } from '../../git/models/remote';
import { Logger } from '../../logger'; import { Logger } from '../../logger';
import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/graphWebview'; import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/graphWebview';
import { executeCommand, executeCoreCommand } from '../../system/command'; import { executeCommand, executeCoreCommand } from '../../system/command';
@ -27,6 +29,7 @@ import type { DateTimeFormat } from '../../system/date';
import { debug, getLogScope } from '../../system/decorators/log'; import { debug, getLogScope } from '../../system/decorators/log';
import type { Deferrable } from '../../system/function'; import type { Deferrable } from '../../system/function';
import { debounce } from '../../system/function'; import { debounce } from '../../system/function';
import type { PromiseCancelledError } from '../../system/promise';
import { getSettledValue } from '../../system/promise'; import { getSettledValue } from '../../system/promise';
import type { Serialized } from '../../system/serialize'; import type { Serialized } from '../../system/serialize';
import { serialize } from '../../system/serialize'; import { serialize } from '../../system/serialize';
@ -46,6 +49,7 @@ import {
CommitActionsCommandType, CommitActionsCommandType,
DidChangeNotificationType, DidChangeNotificationType,
FileActionsCommandType, FileActionsCommandType,
messageHeadlineSplitterToken,
OpenFileCommandType, OpenFileCommandType,
OpenFileComparePreviousCommandType, OpenFileComparePreviousCommandType,
OpenFileCompareWorkingCommandType, OpenFileCompareWorkingCommandType,
@ -376,11 +380,9 @@ export class CommitDetailsWebviewView extends WebviewViewBase
let autolinkedIssuesOrPullRequests; let autolinkedIssuesOrPullRequests;
let pr; let pr;
const message = commit.message ?? commit.summary;
if (remote?.provider != null) { if (remote?.provider != null) {
const [autolinkedIssuesOrPullRequestsResult, prResult] = await Promise.allSettled([ const [autolinkedIssuesOrPullRequestsResult, prResult] = await Promise.allSettled([
this.container.autolinks.getLinkedIssuesAndPullRequests(message, remote),
this.container.autolinks.getLinkedIssuesAndPullRequests(commit.message ?? commit.summary, remote),
commit.getAssociatedPullRequest({ remote: remote }), commit.getAssociatedPullRequest({ remote: remote }),
]); ]);
@ -390,12 +392,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase
pr = getSettledValue(prResult); pr = getSettledValue(prResult);
} }
const formattedMessage = this.container.autolinks.linkify(
message.replace(/\n/, '<br />'),
'html',
remote != null ? [remote] : undefined,
autolinkedIssuesOrPullRequests,
);
const formattedMessage = this.getFormattedMessage(commit, remote, autolinkedIssuesOrPullRequests);
// Remove possible duplicate pull request // Remove possible duplicate pull request
if (pr != null) { if (pr != null) {
@ -623,11 +620,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase
const remote = getSettledValue(remoteResult); const remote = getSettledValue(remoteResult);
if (formattedMessage == null) { if (formattedMessage == null) {
formattedMessage = this.container.autolinks.linkify(
(commit.message ?? commit.summary).replace(/\n/, '<br />'),
'html',
remote != null ? [remote] : undefined,
);
formattedMessage = this.getFormattedMessage(commit, remote);
} }
return { return {
@ -658,6 +651,24 @@ export class CommitDetailsWebviewView extends WebviewViewBase
}; };
} }
private getFormattedMessage(
commit: GitCommit,
remote: GitRemote | undefined,
issuesOrPullRequests?: Map<string, IssueOrPullRequest | PromiseCancelledError | undefined>,
) {
let message = CommitFormatter.fromTemplate(`\${message}`, commit);
const index = message.indexOf('\n');
if (index !== -1) {
message = `${message.substring(0, index)}${messageHeadlineSplitterToken}${message.substring(index + 1)}`;
}
return this.container.autolinks.linkify(
message,
'html',
remote != null ? [remote] : undefined,
issuesOrPullRequests,
);
}
private async getFileCommitFromParams( private async getFileCommitFromParams(
params: FileActionParams, params: FileActionParams,
): Promise<[commit: GitCommit, file: GitFileChange] | undefined> { ): Promise<[commit: GitCommit, file: GitFileChange] | undefined> {

+ 2
- 0
src/webviews/commitDetails/protocol.ts 查看文件

@ -6,6 +6,8 @@ import type { PullRequestShape } from '../../git/models/pullRequest';
import type { Serialized } from '../../system/serialize'; import type { Serialized } from '../../system/serialize';
import { IpcCommandType, IpcNotificationType } from '../protocol'; import { IpcCommandType, IpcNotificationType } from '../protocol';
export const messageHeadlineSplitterToken = '\x00\n\x00';
export type FileShowOptions = TextDocumentShowOptions; export type FileShowOptions = TextDocumentShowOptions;
export type CommitSummary = { export type CommitSummary = {

Loading…
取消
儲存