From 77c3a4037bf62e272657d817acbc37604ce57998 Mon Sep 17 00:00:00 2001 From: Eric Amodio <eamodio@gmail.com> Date: Sun, 25 Feb 2018 16:37:14 -0500 Subject: [PATCH] Truncates messages for display in quick picks --- CHANGELOG.md | 2 +- src/git/formatters/commit.ts | 6 +----- src/git/models/commit.ts | 7 +++++++ src/quickPicks/commitDetails.ts | 8 ++++---- src/quickPicks/commitFileDetails.ts | 4 ++-- src/quickPicks/common.ts | 7 +------ 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25e8ea2..e818f52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Adds `gitlens.heatmap.toggleMode` setting to specify how the gutter heatmap annotations will be toggled, per file or window - Adds `gitlens.recentChanges.toggleMode` setting to specify how the recently changed lines annotations will be toggled, per file or window - ### Changed - Renames *Compare Selected Ancestor with Working Tree* command to *Compare Ancestry with Working Tree* and removes the need to select a branch first, since all compares are done to the working tree — closes [#279](https://github.com/eamodio/vscode-gitlens/issues/279) ### Fixed - Fixes [#294](https://github.com/eamodio/vscode-gitlens/issues/294) - Keyboard shortcuts will now default to *chorded* to avoid conflicts. FYI, only affects new installs or if you remove the `gitlens.keymap` setting) - Fixes issue where Recent Changes annotations weren't restored properly on tab switch +- Fixes quick pick menu issue with commits with newlines in the message ## [8.0.2] - 2018-02-19 ### Fixed diff --git a/src/git/formatters/commit.ts b/src/git/formatters/commit.ts index a14accc..abdb15b 100644 --- a/src/git/formatters/commit.ts +++ b/src/git/formatters/commit.ts @@ -2,7 +2,6 @@ import { Strings } from '../../system'; import { GitCommit } from '../models/commit'; import { Formatter, IFormatOptions } from './formatter'; -import { GlyphChars } from '../../constants'; export interface ICommitFormatOptions extends IFormatOptions { truncateMessageAtNewLine?: boolean; @@ -46,10 +45,7 @@ export class CommitFormatter extends Formatter<GitCommit, ICommitFormatOptions> get 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}`; - } + message = this._item.getShortMessage(); } return this._padOrTruncate(message, this._options.tokenOptions!.message); diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index c96ba02..948a12d 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -192,6 +192,13 @@ export abstract class GitCommit { return gravatar; } + getShortMessage(truncationSuffix: string = `${GlyphChars.Space}${GlyphChars.Ellipsis}`) { + const index = this.message.indexOf('\n'); + if (index === -1) return this.message; + + return `${this.message.substring(0, index)}${truncationSuffix}`; + } + async resolvePreviousFileSha(): Promise<void> { if (this._resolvedPreviousFileSha !== undefined) return; diff --git a/src/quickPicks/commitDetails.ts b/src/quickPicks/commitDetails.ts index e8076d5..bb7f44f 100644 --- a/src/quickPicks/commitDetails.ts +++ b/src/quickPicks/commitDetails.ts @@ -101,7 +101,7 @@ export class CommitDetailsQuickPick { if (stash) { items.splice(index++, 0, new CommandQuickPickItem({ label: `$(git-pull-request) Apply Stashed Changes`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}` + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}` }, Commands.StashApply, [ { confirm: true, @@ -114,7 +114,7 @@ export class CommitDetailsQuickPick { items.splice(index++, 0, new CommandQuickPickItem({ label: `$(x) Delete Stashed Changes`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}` + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}` }, Commands.StashDelete, [ { confirm: true, @@ -179,7 +179,7 @@ export class CommitDetailsQuickPick { items.splice(index++, 0, new CommandQuickPickItem({ label: `$(clippy) Copy Commit Message to Clipboard`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}` + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}` }, Commands.CopyMessageToClipboard, [ uri, { @@ -303,7 +303,7 @@ export class CommitDetailsQuickPick { const pick = await window.showQuickPick(items, { matchOnDescription: true, matchOnDetail: true, - placeHolder: `${commit.shortSha} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.author ? `${commit.author}, ` : ''}${commit.formattedDate} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.message}`, + placeHolder: `${commit.shortSha} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.author ? `${commit.author}, ` : ''}${commit.formattedDate} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}`, ignoreFocusOut: getQuickPickIgnoreFocusOut(), onDidSelectItem: (item: QuickPickItem) => { scope.setKeyCommand('right', item); diff --git a/src/quickPicks/commitFileDetails.ts b/src/quickPicks/commitFileDetails.ts index a883e55..e7557dc 100644 --- a/src/quickPicks/commitFileDetails.ts +++ b/src/quickPicks/commitFileDetails.ts @@ -156,7 +156,7 @@ export class CommitFileDetailsQuickPick { items.push(new CommandQuickPickItem({ label: `$(clippy) Copy Commit Message to Clipboard`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}` + description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}` }, Commands.CopyMessageToClipboard, [ uri, { @@ -310,7 +310,7 @@ export class CommitFileDetailsQuickPick { const pick = await window.showQuickPick(items, { matchOnDescription: true, - placeHolder: `${commit.getFormattedPath()} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${isUncommitted ? `Uncommitted ${GlyphChars.ArrowRightHollow} ` : ''}${commit.shortSha} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.author}, ${commit.formattedDate} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.message}`, + placeHolder: `${commit.getFormattedPath()} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${isUncommitted ? `Uncommitted ${GlyphChars.ArrowRightHollow} ` : ''}${commit.shortSha} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.author}, ${commit.formattedDate} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}`, ignoreFocusOut: getQuickPickIgnoreFocusOut(), onDidSelectItem: (item: QuickPickItem) => { scope.setKeyCommand('right', item as KeyCommand); diff --git a/src/quickPicks/common.ts b/src/quickPicks/common.ts index d3abccd..74d304d 100644 --- a/src/quickPicks/common.ts +++ b/src/quickPicks/common.ts @@ -155,12 +155,7 @@ export class CommitQuickPickItem implements QuickPickItem { detail: string; constructor(public readonly commit: GitLogCommit) { - let message = commit.message; - const index = message.indexOf('\n'); - if (index !== -1) { - message = `${message.substring(0, index)}${GlyphChars.Space}$(ellipsis)`; - } - + const message = commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`); if (commit.isStash) { this.label = message; this.description = '';