Przeglądaj źródła

Closes #429 - Adds emoji support 😄

main
Eric Amodio 6 lat temu
rodzic
commit
307090a70a
7 zmienionych plików z 44 dodań i 9 usunięć
  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 Wyświetl plik

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

+ 1
- 0
CHANGELOG.md Wyświetl plik

@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased]
### 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 `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
Plik diff jest za duży
Wyświetl plik


+ 25
- 0
emoji/shortcodeToEmoji.js Wyświetl plik

@ -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 Wyświetl plik

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

+ 12
- 2
src/git/formatters/commitFormatter.ts Wyświetl plik

@ -1,10 +1,14 @@
'use strict';
import { DateStyle } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { Strings } from '../../system';
import { GitCommit } from '../models/commit';
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 {
dateStyle?: DateStyle;
truncateMessageAtNewLine?: boolean;
@ -67,7 +71,7 @@ export class CommitFormatter extends Formatter
}
get message() {
let message;
let message: string;
if (this._item.isStagedUncommitted) {
message = 'Staged changes';
}
@ -76,11 +80,17 @@ export class CommitFormatter extends Formatter
}
else {
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 {
message = this._item.message;
}
message = message.replace(emojiRegex, (s, code) => emojiMap[code] || s);
}
return this._padOrTruncate(message, this._options.tokenOptions!.message);

+ 3
- 5
src/git/models/commit.ts Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz