Skip to content

Commit a2dc65c

Browse files
committed
Adds message truncation at newline
1 parent 4102bdd commit a2dc65c

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

src/annotations/annotations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ export class Annotations {
187187
}
188188

189189
static trailing(commit: GitCommit, format: string, dateFormat: string | null, cfgTheme: IThemeConfig): DecorationOptions {
190-
const message = CommitFormatter.fromTemplate(format, commit, dateFormat);
190+
const message = CommitFormatter.fromTemplate(format, commit, {
191+
truncateMessageAtNewLine: true,
192+
dateFormat: dateFormat
193+
} as ICommitFormatOptions);
191194
return {
192195
renderOptions: {
193196
after: {

src/currentLineController.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Commands } from './commands';
77
import { TextEditorComparer } from './comparers';
88
import { IConfig, StatusBarCommand } from './configuration';
99
import { DocumentSchemes, ExtensionKey } from './constants';
10-
import { BlameabilityChangeEvent, CommitFormatter, GitCommit, GitCommitLine, GitContextTracker, GitService, GitUri } from './gitService';
10+
import { BlameabilityChangeEvent, CommitFormatter, GitCommit, GitCommitLine, GitContextTracker, GitService, GitUri, ICommitFormatOptions } from './gitService';
1111
import { Logger } from './logger';
1212

1313
const annotationDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({
@@ -462,7 +462,10 @@ export class CurrentLineController extends Disposable {
462462
const cfg = this._config.statusBar;
463463
if (!cfg.enabled || this._statusBarItem === undefined) return;
464464

465-
this._statusBarItem.text = `$(git-commit) ${CommitFormatter.fromTemplate(cfg.format, commit, cfg.dateFormat === null ? this._config.defaultDateFormat : cfg.dateFormat)}`;
465+
this._statusBarItem.text = `$(git-commit) ${CommitFormatter.fromTemplate(cfg.format, commit, {
466+
truncateMessageAtNewLine: true,
467+
dateFormat: cfg.dateFormat === null ? this._config.defaultDateFormat : cfg.dateFormat
468+
} as ICommitFormatOptions)}`;
466469

467470
switch (cfg.command) {
468471
case StatusBarCommand.BlameAnnotate:

src/git/formatters/commit.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { Strings } from '../../system';
33
import { GitCommit } from '../models/commit';
44
import { Formatter, IFormatOptions } from './formatter';
55
import * as moment from 'moment';
6+
import { GlyphChars } from '../../constants';
67

78
export interface ICommitFormatOptions extends IFormatOptions {
9+
truncateMessageAtNewLine?: boolean;
10+
811
tokenOptions?: {
912
ago?: Strings.ITokenOptions;
1013
author?: Strings.ITokenOptions;
@@ -41,7 +44,14 @@ export class CommitFormatter extends Formatter<GitCommit, ICommitFormatOptions>
4144
}
4245

4346
get message() {
44-
const message = this._item.isUncommitted ? 'Uncommitted change' : this._item.message;
47+
let message = this._item.isUncommitted ? 'Uncommitted change' : this._item.message;
48+
if (this._options.truncateMessageAtNewLine) {
49+
const index = message.indexOf('\n');
50+
if (index !== -1) {
51+
message = `${message.substring(0, index)}${GlyphChars.Space}${GlyphChars.Ellipsis}`;
52+
}
53+
}
54+
4555
return this._padOrTruncate(message, this._options.tokenOptions!.message);
4656
}
4757

src/views/commitNode.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'v
44
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
55
import { CommitFileNode } from './commitFileNode';
66
import { ExplorerNode, ResourceType } from './explorerNode';
7-
import { CommitFormatter, getGitStatusIcon, GitLogCommit, GitService, GitUri } from '../gitService';
7+
import { CommitFormatter, getGitStatusIcon, GitLogCommit, GitService, GitUri, ICommitFormatOptions } from '../gitService';
88
import * as path from 'path';
99

1010
export class CommitNode extends ExplorerNode {
@@ -28,7 +28,11 @@ export class CommitNode extends ExplorerNode {
2828
}
2929

3030
getTreeItem(): TreeItem {
31-
const item = new TreeItem(CommitFormatter.fromTemplate(this.template, this.commit, this.git.config.defaultDateFormat));
31+
const item = new TreeItem(CommitFormatter.fromTemplate(this.template, this.commit, {
32+
truncateMessageAtNewLine: true,
33+
dataFormat: this.git.config.defaultDateFormat
34+
} as ICommitFormatOptions));
35+
3236
if (this.commit.type === 'file') {
3337
item.collapsibleState = TreeItemCollapsibleState.None;
3438
item.command = this.getCommand();
@@ -55,17 +59,6 @@ export class CommitNode extends ExplorerNode {
5559
}
5660

5761
getCommand(): Command | undefined {
58-
let allowMissingPrevious = false;
59-
let prefix = undefined;
60-
const status = this.commit.fileStatuses[0];
61-
if (status.status === 'A') {
62-
allowMissingPrevious = true;
63-
prefix = 'added in ';
64-
}
65-
else if (status.status === 'D') {
66-
prefix = 'deleted in ';
67-
}
68-
6962
return {
7063
title: 'Compare File with Previous Revision',
7164
command: Commands.DiffWithPrevious,
@@ -77,9 +70,7 @@ export class CommitNode extends ExplorerNode {
7770
showOptions: {
7871
preserveFocus: true,
7972
preview: true
80-
},
81-
allowMissingPrevious: allowMissingPrevious,
82-
rightTitlePrefix: prefix
73+
}
8374
} as DiffWithPreviousCommandArgs
8475
]
8576
};

src/views/stashNode.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
import { Event, EventEmitter, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
33
import { ExplorerNode, ResourceType } from './explorerNode';
4-
import { CommitFormatter, GitService, GitStashCommit, GitUri } from '../gitService';
4+
import { CommitFormatter, GitService, GitStashCommit, GitUri, ICommitFormatOptions } from '../gitService';
55
import { StashFileNode } from './stashFileNode';
66

77
export class StashNode extends ExplorerNode {
@@ -22,9 +22,10 @@ export class StashNode extends ExplorerNode {
2222
}
2323

2424
getTreeItem(): TreeItem {
25-
const label = CommitFormatter.fromTemplate(this.git.config.gitExplorer.stashFormat, this.commit, this.git.config.defaultDateFormat);
26-
27-
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
25+
const item = new TreeItem(CommitFormatter.fromTemplate(this.git.config.gitExplorer.stashFormat, this.commit, {
26+
truncateMessageAtNewLine: true,
27+
dataFormat: this.git.config.defaultDateFormat
28+
} as ICommitFormatOptions), TreeItemCollapsibleState.Collapsed);
2829
item.contextValue = this.resourceType;
2930
return item;
3031
}

0 commit comments

Comments
 (0)