Browse Source

Closes #429 - Adds emoji support 😄

main
Eric Amodio 6 years ago
parent
commit
307090a70a
7 changed files with 44 additions and 9 deletions
  1. +1
    -1
      .vscodeignore
  2. +1
    -0
      CHANGELOG.md
  3. +1
    -0
      emoji/emojis.json
  4. +25
    -0
      emoji/shortcodeToEmoji.js
  5. +1
    -1
      src/annotations/annotations.ts
  6. +12
    -2
      src/git/formatters/commitFormatter.ts
  7. +3
    -5
      src/git/models/commit.ts

+ 1
- 1
.vscodeignore View File

@ -1,3 +1,4 @@
emoji/**
!images/dark/** !images/dark/**
!images/light/** !images/light/**
!images/settings/** !images/settings/**
@ -6,7 +7,6 @@
!images/cl-*.png !images/cl-*.png
images/** images/**
.vscode/** .vscode/**
.vscode-test/**
test/** test/**
src/** src/**
out/ui/** out/ui/**

+ 1
- 0
CHANGELOG.md View File

@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased] ## [Unreleased]
### Added ### Added
- Adds emoji support, e.g. :smile: in commit messages will now be 😃 — closes [#429](https://github.com/eamodio/vscode-gitlens/issues/429)
- Adds *Compare with Selected* and *Select for Compare* commands to file nodes in the *GitLens*, *GitLens File History*, and *GitLens Results* explorers — closes [#446](https://github.com/eamodio/vscode-gitlens/issues/446) - Adds *Compare with Selected* and *Select for Compare* commands to file nodes in the *GitLens*, *GitLens File History*, and *GitLens Results* explorers — closes [#446](https://github.com/eamodio/vscode-gitlens/issues/446)
- Adds `gitlens.historyExplorer.avatars` setting to specify whether to show avatar images instead of status icons in the `GitLens File History` explorer — allows for an independent value from the other explorers - Adds `gitlens.historyExplorer.avatars` setting to specify whether to show avatar images instead of status icons in the `GitLens File History` explorer — allows for an independent value from the other explorers

+ 1
- 0
emoji/emojis.json
File diff suppressed because it is too large
View File


+ 25
- 0
emoji/shortcodeToEmoji.js View File

@ -0,0 +1,25 @@
const fs = require('fs');
const path = require('path');
// Get emoji data from https://github.com/milesj/emojibase
// https://github.com/milesj/emojibase/blob/master/packages/data/en/data.json
function generate() {
const map = Object.create(null);
const emojis = require(path.join(process.cwd(), 'data.json'));
for (const emoji of emojis) {
if (emoji.shortcodes == null || emoji.shortcodes.length === 0) continue;
for (const code of emoji.shortcodes) {
if (map[code] !== undefined) {
console.warn(code);
}
map[code] = emoji.emoji;
}
}
fs.writeFileSync(path.join(process.cwd(), 'emojis.json'), JSON.stringify(map), 'utf8');
}
generate();

+ 1
- 1
src/annotations/annotations.ts View File

@ -141,7 +141,7 @@ export class Annotations {
commit.sha commit.sha
)} "Show Commit Details")`; )} "Show Commit Details")`;
message = commit.message;
message = CommitFormatter.fromTemplate('${message}', commit);
for (const r of remotes) { for (const r of remotes) {
if (r.provider === undefined) continue; if (r.provider === undefined) continue;

+ 12
- 2
src/git/formatters/commitFormatter.ts View File

@ -1,10 +1,14 @@
'use strict'; 'use strict';
import { DateStyle } from '../../configuration'; import { DateStyle } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { Strings } from '../../system'; import { Strings } from '../../system';
import { GitCommit } from '../models/commit'; import { GitCommit } from '../models/commit';
import { Formatter, IFormatOptions } from './formatter'; import { Formatter, IFormatOptions } from './formatter';
const emojiMap: { [key: string]: string } = require('../../../emoji/emojis.json');
const emojiRegex = /:([-+_a-z0-9]+):/g;
export interface ICommitFormatOptions extends IFormatOptions { export interface ICommitFormatOptions extends IFormatOptions {
dateStyle?: DateStyle; dateStyle?: DateStyle;
truncateMessageAtNewLine?: boolean; truncateMessageAtNewLine?: boolean;
@ -67,7 +71,7 @@ export class CommitFormatter extends Formatter
} }
get message() { get message() {
let message;
let message: string;
if (this._item.isStagedUncommitted) { if (this._item.isStagedUncommitted) {
message = 'Staged changes'; message = 'Staged changes';
} }
@ -76,11 +80,17 @@ export class CommitFormatter extends Formatter
} }
else { else {
if (this._options.truncateMessageAtNewLine) { if (this._options.truncateMessageAtNewLine) {
message = this._item.getShortMessage();
const index = this._item.message.indexOf('\n');
message =
index === -1
? this._item.message
: `${this._item.message.substring(0, index)}${GlyphChars.Space}${GlyphChars.Ellipsis}`;
} }
else { else {
message = this._item.message; message = this._item.message;
} }
message = message.replace(emojiRegex, (s, code) => emojiMap[code] || s);
} }
return this._padOrTruncate(message, this._options.tokenOptions!.message); return this._padOrTruncate(message, this._options.tokenOptions!.message);

+ 3
- 5
src/git/models/commit.ts View File

@ -5,6 +5,7 @@ import { configuration, DateStyle, GravatarDefaultStyle } from '../../configurat
import { GlyphChars } from '../../constants'; import { GlyphChars } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { Dates, Strings } from '../../system'; import { Dates, Strings } from '../../system';
import { CommitFormatter } from '../formatters/formatters';
import { Git } from '../git'; import { Git } from '../git';
import { GitUri } from '../gitUri'; import { GitUri } from '../gitUri';
@ -199,11 +200,8 @@ export abstract class GitCommit {
return gravatar; 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}`;
getShortMessage() {
return CommitFormatter.fromTemplate('${message}', this, { truncateMessageAtNewLine: true });
} }
async resolvePreviousFileSha(): Promise<void> { async resolvePreviousFileSha(): Promise<void> {

Loading…
Cancel
Save