From a2dc65c0440e57189af457f371a0a2e8f951c2bd Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 11 Sep 2017 00:41:11 -0400 Subject: [PATCH] Adds message truncation at newline --- src/annotations/annotations.ts | 5 ++++- src/currentLineController.ts | 7 +++++-- src/git/formatters/commit.ts | 12 +++++++++++- src/views/commitNode.ts | 23 +++++++---------------- src/views/stashNode.ts | 9 +++++---- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/annotations/annotations.ts b/src/annotations/annotations.ts index 00ae458..8647779 100644 --- a/src/annotations/annotations.ts +++ b/src/annotations/annotations.ts @@ -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: { diff --git a/src/currentLineController.ts b/src/currentLineController.ts index 52f1e2d..52e4fc0 100644 --- a/src/currentLineController.ts +++ b/src/currentLineController.ts @@ -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: diff --git a/src/git/formatters/commit.ts b/src/git/formatters/commit.ts index 1463a6c..63b9bf1 100644 --- a/src/git/formatters/commit.ts +++ b/src/git/formatters/commit.ts @@ -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); } diff --git a/src/views/commitNode.ts b/src/views/commitNode.ts index 7ee3a5f..5e60f34 100644 --- a/src/views/commitNode.ts +++ b/src/views/commitNode.ts @@ -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 ] }; diff --git a/src/views/stashNode.ts b/src/views/stashNode.ts index 9fc5e64..1172027 100644 --- a/src/views/stashNode.ts +++ b/src/views/stashNode.ts @@ -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; }