Skip to content

Commit 77c3a40

Browse files
committed
Truncates messages for display in quick picks
1 parent 664f745 commit 77c3a40

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1313
- Adds `gitlens.heatmap.toggleMode` setting to specify how the gutter heatmap annotations will be toggled, per file or window
1414
- Adds `gitlens.recentChanges.toggleMode` setting to specify how the recently changed lines annotations will be toggled, per file or window
1515

16-
1716
### Changed
1817
- 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)
1918

2019
### Fixed
2120
- 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)
2221
- Fixes issue where Recent Changes annotations weren't restored properly on tab switch
22+
- Fixes quick pick menu issue with commits with newlines in the message
2323

2424
## [8.0.2] - 2018-02-19
2525
### Fixed

src/git/formatters/commit.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { Strings } from '../../system';
33
import { GitCommit } from '../models/commit';
44
import { Formatter, IFormatOptions } from './formatter';
5-
import { GlyphChars } from '../../constants';
65

76
export interface ICommitFormatOptions extends IFormatOptions {
87
truncateMessageAtNewLine?: boolean;
@@ -46,10 +45,7 @@ export class CommitFormatter extends Formatter<GitCommit, ICommitFormatOptions>
4645
get message() {
4746
let message = this._item.isUncommitted ? 'Uncommitted change' : this._item.message;
4847
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-
}
48+
message = this._item.getShortMessage();
5349
}
5450

5551
return this._padOrTruncate(message, this._options.tokenOptions!.message);

src/git/models/commit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ export abstract class GitCommit {
192192
return gravatar;
193193
}
194194

195+
getShortMessage(truncationSuffix: string = `${GlyphChars.Space}${GlyphChars.Ellipsis}`) {
196+
const index = this.message.indexOf('\n');
197+
if (index === -1) return this.message;
198+
199+
return `${this.message.substring(0, index)}${truncationSuffix}`;
200+
}
201+
195202
async resolvePreviousFileSha(): Promise<void> {
196203
if (this._resolvedPreviousFileSha !== undefined) return;
197204

src/quickPicks/commitDetails.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class CommitDetailsQuickPick {
101101
if (stash) {
102102
items.splice(index++, 0, new CommandQuickPickItem({
103103
label: `$(git-pull-request) Apply Stashed Changes`,
104-
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}`
104+
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}`
105105
}, Commands.StashApply, [
106106
{
107107
confirm: true,
@@ -114,7 +114,7 @@ export class CommitDetailsQuickPick {
114114

115115
items.splice(index++, 0, new CommandQuickPickItem({
116116
label: `$(x) Delete Stashed Changes`,
117-
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}`
117+
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}`
118118
}, Commands.StashDelete, [
119119
{
120120
confirm: true,
@@ -179,7 +179,7 @@ export class CommitDetailsQuickPick {
179179

180180
items.splice(index++, 0, new CommandQuickPickItem({
181181
label: `$(clippy) Copy Commit Message to Clipboard`,
182-
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}`
182+
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}`
183183
}, Commands.CopyMessageToClipboard, [
184184
uri,
185185
{
@@ -303,7 +303,7 @@ export class CommitDetailsQuickPick {
303303
const pick = await window.showQuickPick(items, {
304304
matchOnDescription: true,
305305
matchOnDetail: true,
306-
placeHolder: `${commit.shortSha} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.author ? `${commit.author}, ` : ''}${commit.formattedDate} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${commit.message}`,
306+
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)`)}`,
307307
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
308308
onDidSelectItem: (item: QuickPickItem) => {
309309
scope.setKeyCommand('right', item);

src/quickPicks/commitFileDetails.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class CommitFileDetailsQuickPick {
156156

157157
items.push(new CommandQuickPickItem({
158158
label: `$(clippy) Copy Commit Message to Clipboard`,
159-
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.message}`
159+
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`)}`
160160
}, Commands.CopyMessageToClipboard, [
161161
uri,
162162
{
@@ -310,7 +310,7 @@ export class CommitFileDetailsQuickPick {
310310

311311
const pick = await window.showQuickPick(items, {
312312
matchOnDescription: true,
313-
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}`,
313+
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)`)}`,
314314
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
315315
onDidSelectItem: (item: QuickPickItem) => {
316316
scope.setKeyCommand('right', item as KeyCommand);

src/quickPicks/common.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,7 @@ export class CommitQuickPickItem implements QuickPickItem {
155155
detail: string;
156156

157157
constructor(public readonly commit: GitLogCommit) {
158-
let message = commit.message;
159-
const index = message.indexOf('\n');
160-
if (index !== -1) {
161-
message = `${message.substring(0, index)}${GlyphChars.Space}$(ellipsis)`;
162-
}
163-
158+
const message = commit.getShortMessage(`${GlyphChars.Space}$(ellipsis)`);
164159
if (commit.isStash) {
165160
this.label = message;
166161
this.description = '';

0 commit comments

Comments
 (0)