Ver código fonte

Fixes some emoji codes

Adds emoji support to tag annotations
main
Eric Amodio 5 anos atrás
pai
commit
78c296528a
5 arquivos alterados com 42 adições e 7 exclusões
  1. +24
    -1
      generateEmojiShortcodeMap.js
  2. +1
    -1
      src/emojis.json
  3. +11
    -0
      src/emojis.ts
  4. +2
    -4
      src/git/formatters/commitFormatter.ts
  5. +4
    -1
      src/views/nodes/tagNode.ts

+ 24
- 1
generateEmojiShortcodeMap.js Ver arquivo

@ -1,19 +1,31 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const https = require('https');
const path = require('path');
async function generate() {
/**
* @type {{ [code: string]: string }}
*/
let map = Object.create(null);
// Get emoji data from https://github.com/milesj/emojibase
// https://github.com/milesj/emojibase/blob/master/packages/data/en/raw.json
await download('https://raw.githubusercontent.com/milesj/emojibase/master/packages/data/en/raw.json', 'raw.json');
/**
* @type {({ emoji: string; shortcodes: string[] })[]}
*/
// eslint-disable-next-line import/no-dynamic-require
const emojis = require(path.join(process.cwd(), 'raw.json'));
for (const emoji of emojis) {
if (emoji.shortcodes == null || emoji.shortcodes.length === 0) continue;
for (const code of emoji.shortcodes) {
for (let code of emoji.shortcodes) {
if (code[0] === ':' && code[code.length - 1] === ':') {
code = code.substring(1, code.length - 2);
}
if (map[code] !== undefined) {
console.warn(code);
}
@ -30,8 +42,16 @@ async function generate() {
'gitmojis.json'
);
/**
* @type {({ code: string; emoji: string })[]}
*/
// eslint-disable-next-line import/no-dynamic-require
const gitmojis = require(path.join(process.cwd(), 'gitmojis.json')).gitmojis;
for (const emoji of gitmojis) {
if (emoji.code[0] === ':' && emoji.code[emoji.code.length - 1] === ':') {
emoji.code = emoji.code.substring(1, emoji.code.length - 2);
}
if (map[emoji.code] !== undefined) {
console.warn(emoji.code);
continue;
@ -42,6 +62,9 @@ async function generate() {
fs.unlink('gitmojis.json', () => {});
// Sort the emojis for easier diff checking
/**
* @type { [string, string][] }}
*/
const list = Object.entries(map);
list.sort();

+ 1
- 1
src/emojis.json
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 11
- 0
src/emojis.ts Ver arquivo

@ -0,0 +1,11 @@
'use strict';
import * as emojis from './emojis.json';
const emojiMap: { [key: string]: string } = (emojis as any).default;
const emojiRegex = /:([-+_a-z0-9]+):/g;
export function emojify(message: string) {
return message.replace(emojiRegex, (s, code) => {
return emojiMap[code] || s;
});
}

+ 2
- 4
src/git/formatters/commitFormatter.ts Ver arquivo

@ -13,13 +13,11 @@ import { Container } from '../../container';
import { GitCommit, GitLogCommit, GitRemote, GitService, GitUri } from '../gitService';
import { Strings } from '../../system';
import { FormatOptions, Formatter } from './formatter';
import * as emojis from '../../emojis.json';
import { ContactPresence } from '../../vsls/vsls';
import { getPresenceDataUri } from '../../avatars';
import { emojify } from '../../emojis';
const emptyStr = '';
const emojiMap: { [key: string]: string } = emojis;
const emojiRegex = /:([-+_a-z0-9]+):/g;
const escapeMarkdownRegex = /[`>#*_\-+.]/g;
// const sampleMarkdown = '## message `not code` *not important* _no underline_ \n> don\'t quote me \n- don\'t list me \n+ don\'t list me \n1. don\'t list me \nnot h1 \n=== \nnot h2 \n---\n***\n---\n___';
@ -298,7 +296,7 @@ export class CommitFormatter extends Formatter {
message = this._item.message;
}
message = message.replace(emojiRegex, (s, code) => emojiMap[code] || s);
message = emojify(message);
}
message = this._padOrTruncate(message, this._options.tokenOptions.message);

+ 4
- 1
src/views/nodes/tagNode.ts Ver arquivo

@ -9,6 +9,7 @@ import { CommitNode } from './commitNode';
import { MessageNode, ShowMoreNode } from './common';
import { getBranchesAndTagTipsFn, insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, ViewNode, ViewRefNode } from './viewNode';
import { emojify } from '../../emojis';
export class TagNode extends ViewRefNode<RepositoriesView> implements PageableViewNode {
readonly supportsPaging = true;
@ -59,7 +60,9 @@ export class TagNode extends ViewRefNode implements PageableVi
const item = new TreeItem(this.label, TreeItemCollapsibleState.Collapsed);
item.id = this.id;
item.contextValue = ResourceType.Tag;
item.tooltip = `${this.tag.name}${this.tag.annotation === undefined ? '' : `\n${this.tag.annotation}`}`;
item.tooltip = `${this.tag.name}${
this.tag.annotation === undefined ? '' : `\n${emojify(this.tag.annotation)}`
}`;
return item;
}

Carregando…
Cancelar
Salvar