Parcourir la source

Adds message truncation at newline

main
Eric Amodio il y a 7 ans
Parent
révision
a2dc65c044
5 fichiers modifiés avec 32 ajouts et 24 suppressions
  1. +4
    -1
      src/annotations/annotations.ts
  2. +5
    -2
      src/currentLineController.ts
  3. +11
    -1
      src/git/formatters/commit.ts
  4. +7
    -16
      src/views/commitNode.ts
  5. +5
    -4
      src/views/stashNode.ts

+ 4
- 1
src/annotations/annotations.ts Voir le fichier

@ -187,7 +187,10 @@ export class Annotations {
}
static trailing(commit: GitCommit, format: string, dateFormat: string | null, cfgTheme: IThemeConfig): DecorationOptions {
const message = CommitFormatter.fromTemplate(format, commit, dateFormat);
const message = CommitFormatter.fromTemplate(format, commit, {
truncateMessageAtNewLine: true,
dateFormat: dateFormat
} as ICommitFormatOptions);
return {
renderOptions: {
after: {

+ 5
- 2
src/currentLineController.ts Voir le fichier

@ -7,7 +7,7 @@ import { Commands } from './commands';
import { TextEditorComparer } from './comparers';
import { IConfig, StatusBarCommand } from './configuration';
import { DocumentSchemes, ExtensionKey } from './constants';
import { BlameabilityChangeEvent, CommitFormatter, GitCommit, GitCommitLine, GitContextTracker, GitService, GitUri } from './gitService';
import { BlameabilityChangeEvent, CommitFormatter, GitCommit, GitCommitLine, GitContextTracker, GitService, GitUri, ICommitFormatOptions } from './gitService';
import { Logger } from './logger';
const annotationDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({
@ -462,7 +462,10 @@ export class CurrentLineController extends Disposable {
const cfg = this._config.statusBar;
if (!cfg.enabled || this._statusBarItem === undefined) return;
this._statusBarItem.text = `$(git-commit) ${CommitFormatter.fromTemplate(cfg.format, commit, cfg.dateFormat === null ? this._config.defaultDateFormat : cfg.dateFormat)}`;
this._statusBarItem.text = `$(git-commit) ${CommitFormatter.fromTemplate(cfg.format, commit, {
truncateMessageAtNewLine: true,
dateFormat: cfg.dateFormat === null ? this._config.defaultDateFormat : cfg.dateFormat
} as ICommitFormatOptions)}`;
switch (cfg.command) {
case StatusBarCommand.BlameAnnotate:

+ 11
- 1
src/git/formatters/commit.ts Voir le fichier

@ -3,8 +3,11 @@ import { Strings } from '../../system';
import { GitCommit } from '../models/commit';
import { Formatter, IFormatOptions } from './formatter';
import * as moment from 'moment';
import { GlyphChars } from '../../constants';
export interface ICommitFormatOptions extends IFormatOptions {
truncateMessageAtNewLine?: boolean;
tokenOptions?: {
ago?: Strings.ITokenOptions;
author?: Strings.ITokenOptions;
@ -41,7 +44,14 @@ export class CommitFormatter extends Formatter
}
get message() {
const message = this._item.isUncommitted ? 'Uncommitted change' : this._item.message;
let message = this._item.isUncommitted ? 'Uncommitted change' : this._item.message;
if (this._options.truncateMessageAtNewLine) {
const index = message.indexOf('\n');
if (index !== -1) {
message = `${message.substring(0, index)}${GlyphChars.Space}${GlyphChars.Ellipsis}`;
}
}
return this._padOrTruncate(message, this._options.tokenOptions!.message);
}

+ 7
- 16
src/views/commitNode.ts Voir le fichier

@ -4,7 +4,7 @@ import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'v
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
import { CommitFileNode } from './commitFileNode';
import { ExplorerNode, ResourceType } from './explorerNode';
import { CommitFormatter, getGitStatusIcon, GitLogCommit, GitService, GitUri } from '../gitService';
import { CommitFormatter, getGitStatusIcon, GitLogCommit, GitService, GitUri, ICommitFormatOptions } from '../gitService';
import * as path from 'path';
export class CommitNode extends ExplorerNode {
@ -28,7 +28,11 @@ export class CommitNode extends ExplorerNode {
}
getTreeItem(): TreeItem {
const item = new TreeItem(CommitFormatter.fromTemplate(this.template, this.commit, this.git.config.defaultDateFormat));
const item = new TreeItem(CommitFormatter.fromTemplate(this.template, this.commit, {
truncateMessageAtNewLine: true,
dataFormat: this.git.config.defaultDateFormat
} as ICommitFormatOptions));
if (this.commit.type === 'file') {
item.collapsibleState = TreeItemCollapsibleState.None;
item.command = this.getCommand();
@ -55,17 +59,6 @@ export class CommitNode extends ExplorerNode {
}
getCommand(): Command | undefined {
let allowMissingPrevious = false;
let prefix = undefined;
const status = this.commit.fileStatuses[0];
if (status.status === 'A') {
allowMissingPrevious = true;
prefix = 'added in ';
}
else if (status.status === 'D') {
prefix = 'deleted in ';
}
return {
title: 'Compare File with Previous Revision',
command: Commands.DiffWithPrevious,
@ -77,9 +70,7 @@ export class CommitNode extends ExplorerNode {
showOptions: {
preserveFocus: true,
preview: true
},
allowMissingPrevious: allowMissingPrevious,
rightTitlePrefix: prefix
}
} as DiffWithPreviousCommandArgs
]
};

+ 5
- 4
src/views/stashNode.ts Voir le fichier

@ -1,7 +1,7 @@
'use strict';
import { Event, EventEmitter, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ExplorerNode, ResourceType } from './explorerNode';
import { CommitFormatter, GitService, GitStashCommit, GitUri } from '../gitService';
import { CommitFormatter, GitService, GitStashCommit, GitUri, ICommitFormatOptions } from '../gitService';
import { StashFileNode } from './stashFileNode';
export class StashNode extends ExplorerNode {
@ -22,9 +22,10 @@ export class StashNode extends ExplorerNode {
}
getTreeItem(): TreeItem {
const label = CommitFormatter.fromTemplate(this.git.config.gitExplorer.stashFormat, this.commit, this.git.config.defaultDateFormat);
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
const item = new TreeItem(CommitFormatter.fromTemplate(this.git.config.gitExplorer.stashFormat, this.commit, {
truncateMessageAtNewLine: true,
dataFormat: this.git.config.defaultDateFormat
} as ICommitFormatOptions), TreeItemCollapsibleState.Collapsed);
item.contextValue = this.resourceType;
return item;
}

Chargement…
Annuler
Enregistrer