11import { Dates , Strings } from '../system' ;
22import { DecorationInstanceRenderOptions , DecorationOptions , MarkdownString , ThemableDecorationRenderOptions } from 'vscode' ;
3- import { DiffWithCommand , ShowQuickCommitDetailsCommand } from '../commands' ;
3+ import { DiffWithCommand , OpenCommitInRemoteCommand , ShowQuickCommitDetailsCommand } from '../commands' ;
44import { IThemeConfig , themeDefaults } from '../configuration' ;
55import { GlyphChars } from '../constants' ;
66import { CommitFormatter , GitCommit , GitDiffChunkLine , GitService , GitUri , ICommitFormatOptions } from '../gitService' ;
7+ const Datauri = require ( 'datauri' ) ;
78
89interface IHeatmapConfig {
910 enabled : boolean ;
@@ -25,6 +26,25 @@ export const endOfLineIndex = 1000000;
2526const escapeMarkdownRegEx = / [ ` \> \# \* \_ \- \+ \. ] / g;
2627// 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___';
2728
29+ const linkIconSvg = `<?xml version="1.0" encoding="utf-8"?>
30+ <svg width="12" height="18" version="1.1" xmlns="http://www.w3.org/2000/svg">
31+ <path fill="\${color}" d="m11,14l1,0l0,3c0,0.55 -0.45,1 -1,1l-10,0c-0.55,0 -1,-0.45 -1,-1l0,-10c0,-0.55 0.45,-1 1,-1l3,0l0,1l-3,0l0,10l10,0l0,-3l0,0zm-5,-8l2.25,2.25l-3.25,3.25l1.5,1.5l3.25,-3.25l2.25,2.25l0,-6l-6,0l0,0z" />
32+ </svg>` ;
33+
34+ const themeForegroundColor = '#a0a0a0' ;
35+ let linkIconDataUri : string | undefined ;
36+
37+ function getLinkIconDataUri ( foregroundColor : string ) : string {
38+ if ( linkIconDataUri === undefined || foregroundColor !== themeForegroundColor ) {
39+ const datauri = new Datauri ( ) ;
40+ datauri . format ( '.svg' , Strings . interpolate ( linkIconSvg , { color : foregroundColor } ) ) ;
41+ linkIconDataUri = datauri . content ;
42+ foregroundColor = themeForegroundColor ;
43+ }
44+
45+ return linkIconDataUri ! ;
46+ }
47+
2848export class Annotations {
2949
3050 static applyHeatmap ( decoration : DecorationOptions , date : Date , now : number ) {
@@ -47,7 +67,7 @@ export class Annotations {
4767 return '#793738' ;
4868 }
4969
50- static getHoverMessage ( commit : GitCommit , dateFormat : string | null ) : MarkdownString {
70+ static getHoverMessage ( commit : GitCommit , dateFormat : string | null , hasRemotes : boolean ) : MarkdownString {
5171 if ( dateFormat === null ) {
5272 dateFormat = 'MMMM Do, YYYY h:MMa' ;
5373 }
@@ -64,7 +84,11 @@ export class Annotations {
6484 message = `\n\n> ${ message } ` ;
6585 }
6686
67- const markdown = new MarkdownString ( `[\`${ commit . shortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs ( commit . sha ) } ) __${ commit . author } __, ${ commit . fromNow ( ) } _(${ commit . formatDate ( dateFormat ) } )_${ message } ` ) ;
87+ const openInRemoteCommand = hasRemotes
88+ ? `${ ' ' . repeat ( 3 ) } [ } )](${ OpenCommitInRemoteCommand . getMarkdownCommandArgs ( commit . sha ) } "Open in Remote")`
89+ : '' ;
90+
91+ const markdown = new MarkdownString ( `[\`${ commit . shortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs ( commit . sha ) } "Show Commit Details") __${ commit . author } __, ${ commit . fromNow ( ) } _(${ commit . formatDate ( dateFormat ) } )_ ${ openInRemoteCommand } ${ message } ` ) ;
6892 markdown . isTrusted = true ;
6993 return markdown ;
7094 }
@@ -74,8 +98,8 @@ export class Annotations {
7498
7599 const codeDiff = this . _getCodeDiff ( chunkLine ) ;
76100 const markdown = new MarkdownString ( commit . isUncommitted
77- ? `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs ( commit ) } ) ${ GlyphChars . Dash } _uncommitted_\n${ codeDiff } `
78- : `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs ( commit ) } ) ${ GlyphChars . Dash } [\`${ commit . previousShortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs ( commit . previousSha ! ) } ) ${ GlyphChars . ArrowLeftRight } [\`${ commit . shortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs ( commit . sha ) } )\n${ codeDiff } ` ) ;
101+ ? `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs ( commit ) } "Open Changes" ) ${ GlyphChars . Dash } _uncommitted_\n${ codeDiff } `
102+ : `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs ( commit ) } "Open Changes" ) ${ GlyphChars . Dash } [\`${ commit . previousShortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs ( commit . previousSha ! ) } "Show Commit Details" ) ${ GlyphChars . ArrowLeftRight } [\`${ commit . shortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs ( commit . sha ) } "Show Commit Details" )\n${ codeDiff } ` ) ;
79103 markdown . isTrusted = true ;
80104 return markdown ;
81105 }
@@ -97,8 +121,8 @@ export class Annotations {
97121 } as DecorationOptions ;
98122 }
99123
100- static detailsHover ( commit : GitCommit , dateFormat : string | null ) : DecorationOptions {
101- const message = this . getHoverMessage ( commit , dateFormat ) ;
124+ static detailsHover ( commit : GitCommit , dateFormat : string | null , hasRemotes : boolean ) : DecorationOptions {
125+ const message = this . getHoverMessage ( commit , dateFormat , hasRemotes ) ;
102126 return {
103127 hoverMessage : message
104128 } as DecorationOptions ;
@@ -163,9 +187,9 @@ export class Annotations {
163187 } as IRenderOptions ;
164188 }
165189
166- static hover ( commit : GitCommit , renderOptions : IRenderOptions , heatmap : boolean , dateFormat : string | null ) : DecorationOptions {
190+ static hover ( commit : GitCommit , renderOptions : IRenderOptions , heatmap : boolean , dateFormat : string | null , hasRemotes : boolean ) : DecorationOptions {
167191 return {
168- hoverMessage : this . getHoverMessage ( commit , dateFormat ) ,
192+ hoverMessage : this . getHoverMessage ( commit , dateFormat , hasRemotes ) ,
169193 renderOptions : heatmap ? { before : { ...renderOptions . before } } : undefined
170194 } as DecorationOptions ;
171195 }
0 commit comments