diff --git a/src/plus/webviews/timeline/protocol.ts b/src/plus/webviews/timeline/protocol.ts index 7b91824..8a49abc 100644 --- a/src/plus/webviews/timeline/protocol.ts +++ b/src/plus/webviews/timeline/protocol.ts @@ -3,6 +3,7 @@ import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol' export interface State { dataset?: Commit[]; + emptyMessage?: string; period: Period; title: string; uri?: string; diff --git a/src/plus/webviews/timeline/timelineWebview.ts b/src/plus/webviews/timeline/timelineWebview.ts index 9c5079d..ae9ab88 100644 --- a/src/plus/webviews/timeline/timelineWebview.ts +++ b/src/plus/webviews/timeline/timelineWebview.ts @@ -174,38 +174,40 @@ export class TimelineWebview extends WebviewBase { @debug({ args: false }) private async getState(current: Context): Promise { - const access = await this.container.git.access(PlusFeatures.Timeline); const dateFormat = configuration.get('defaultDateFormat') ?? 'MMMM Do, YYYY h:mma'; const shortDateFormat = configuration.get('defaultDateShortFormat') ?? 'short'; const period = current.period ?? defaultPeriod; - if (access.allowed === false) { - const dataset = generateRandomTimelineDataset(); + if (current.uri == null) { + const access = await this.container.git.access(PlusFeatures.Timeline); return { - dataset: dataset.sort((a, b) => b.sort - a.sort), + emptyMessage: 'There are no editors open that can provide file history information', period: period, - title: 'src/app/index.ts', - uri: Uri.file('src/app/index.ts').toString(), + title: '', dateFormat: dateFormat, shortDateFormat: shortDateFormat, access: access, }; } - if (current.uri == null) { + const gitUri = await GitUri.fromUri(current.uri); + const repoPath = gitUri.repoPath!; + + const access = await this.container.git.access(PlusFeatures.Timeline, repoPath); + if (access.allowed === false) { + const dataset = generateRandomTimelineDataset(); return { + dataset: dataset.sort((a, b) => b.sort - a.sort), period: period, - title: 'There are no editors open that can provide file history information', + title: 'src/app/index.ts', + uri: Uri.file('src/app/index.ts').toString(), dateFormat: dateFormat, shortDateFormat: shortDateFormat, access: access, }; } - const gitUri = await GitUri.fromUri(current.uri); - const repoPath = gitUri.repoPath!; const title = gitUri.relativePath; - this.title = `${this.originalTitle}: ${gitUri.fileName}`; const [currentUser, log] = await Promise.all([ @@ -220,8 +222,9 @@ export class TimelineWebview extends WebviewBase { if (log == null) { return { dataset: [], + emptyMessage: 'No commits found for the specified time period', period: period, - title: 'No commits found for the specified time period', + title: title, uri: current.uri.toString(), dateFormat: dateFormat, shortDateFormat: shortDateFormat, diff --git a/src/plus/webviews/timeline/timelineWebviewView.ts b/src/plus/webviews/timeline/timelineWebviewView.ts index e553663..0e219eb 100644 --- a/src/plus/webviews/timeline/timelineWebviewView.ts +++ b/src/plus/webviews/timeline/timelineWebviewView.ts @@ -82,7 +82,7 @@ export class TimelineWebviewView extends WebviewViewBase { return [ this.container.subscription.onDidChange(this.onSubscriptionChanged, this), - window.onDidChangeActiveTextEditor(this.onActiveEditorChanged, this), + window.onDidChangeActiveTextEditor(debounce(this.onActiveEditorChanged, 250), this), this.container.git.onDidChangeRepository(this.onRepositoryChanged, this), this.container.git.onDidChangeRepositories(this.onRepositoriesChanged, this), ]; @@ -151,7 +151,14 @@ export class TimelineWebviewView extends WebviewViewBase { @debug({ args: false }) private onActiveEditorChanged(editor: TextEditor | undefined) { - if (editor == null || !this.container.git.isTrackable(editor.document.uri)) return; + if (editor != null) { + if (!isTextEditor(editor)) return; + + if (!this.container.git.isTrackable(editor.document.uri)) { + editor = undefined; + } + } + if (!this.updatePendingEditor(editor)) return; this.updateState(); @@ -186,38 +193,40 @@ export class TimelineWebviewView extends WebviewViewBase { @debug({ args: false }) private async getState(current: Context): Promise { - const access = await this.container.git.access(PlusFeatures.Timeline); const dateFormat = configuration.get('defaultDateFormat') ?? 'MMMM Do, YYYY h:mma'; const shortDateFormat = configuration.get('defaultDateShortFormat') ?? 'short'; const period = current.period ?? defaultPeriod; - if (access.allowed === false) { - const dataset = generateRandomTimelineDataset(); + if (current.uri == null) { + const access = await this.container.git.access(PlusFeatures.Timeline); return { - dataset: dataset.sort((a, b) => b.sort - a.sort), + emptyMessage: 'There are no editors open that can provide file history information', period: period, - title: 'src/app/index.ts', - uri: Uri.file('src/app/index.ts').toString(), + title: '', dateFormat: dateFormat, shortDateFormat: shortDateFormat, access: access, }; } - if (current.uri == null) { + const gitUri = await GitUri.fromUri(current.uri); + const repoPath = gitUri.repoPath!; + + const access = await this.container.git.access(PlusFeatures.Timeline, repoPath); + if (access.allowed === false) { + const dataset = generateRandomTimelineDataset(); return { + dataset: dataset.sort((a, b) => b.sort - a.sort), period: period, - title: 'There are no editors open that can provide file history information', + title: 'src/app/index.ts', + uri: Uri.file('src/app/index.ts').toString(), dateFormat: dateFormat, shortDateFormat: shortDateFormat, access: access, }; } - const gitUri = await GitUri.fromUri(current.uri); - const repoPath = gitUri.repoPath!; const title = gitUri.relativePath; - this.description = gitUri.fileName; const [currentUser, log] = await Promise.all([ @@ -232,8 +241,9 @@ export class TimelineWebviewView extends WebviewViewBase { if (log == null) { return { dataset: [], + emptyMessage: 'No commits found for the specified time period', period: period, - title: 'No commits found for the specified time period', + title: title, uri: current.uri.toString(), dateFormat: dateFormat, shortDateFormat: shortDateFormat, diff --git a/src/webviews/apps/plus/timeline/chart.ts b/src/webviews/apps/plus/timeline/chart.ts index 2501a3f..4272249 100644 --- a/src/webviews/apps/plus/timeline/chart.ts +++ b/src/webviews/apps/plus/timeline/chart.ts @@ -100,7 +100,7 @@ export class TimelineChart { $overlay?.classList.toggle('hidden', false); const $emptyMessage = $overlay.querySelector('[data-bind="empty"]')!; - $emptyMessage.textContent = state.title; + $emptyMessage.textContent = state.emptyMessage ?? ''; return; } diff --git a/src/webviews/apps/plus/timeline/timeline.scss b/src/webviews/apps/plus/timeline/timeline.scss index 7dd5c99..0631d7e 100644 --- a/src/webviews/apps/plus/timeline/timeline.scss +++ b/src/webviews/apps/plus/timeline/timeline.scss @@ -168,7 +168,6 @@ span.button-subaction { left: 0; width: 100vw; height: 100vh; - background-color: var(--color-background); h1 { font-weight: 600; diff --git a/src/webviews/apps/plus/timeline/timeline.ts b/src/webviews/apps/plus/timeline/timeline.ts index 44829c5..f987562 100644 --- a/src/webviews/apps/plus/timeline/timeline.ts +++ b/src/webviews/apps/plus/timeline/timeline.ts @@ -2,6 +2,7 @@ /*global*/ import './timeline.scss'; import { provideVSCodeDesignSystem, vsCodeButton, vsCodeDropdown, vsCodeOption } from '@vscode/webview-ui-toolkit'; +import { GlyphChars } from '../../../../constants'; import type { State } from '../../../../plus/webviews/timeline/protocol'; import { DidChangeNotificationType, @@ -93,7 +94,7 @@ export class TimelineApp extends App { const $slot = document.getElementById('overlay-slot') as HTMLDivElement; - if (this.state.access.allowed !== true) { + if (this.state.access.allowed === false) { const { current: subscription, required } = this.state.access.subscription; const requiresPublic = required === SubscriptionPlanId.FreePlus; @@ -128,11 +129,6 @@ export class TimelineApp extends App { let { title } = this.state; - const empty = this.state.dataset == null || this.state.dataset.length === 0; - if (empty) { - title = ''; - } - let description = ''; const index = title.lastIndexOf('/'); if (index >= 0) { @@ -144,7 +140,7 @@ export class TimelineApp extends App { for (const [key, value] of Object.entries({ title: title, description: description })) { const $el = document.querySelector(`[data-bind="${key}"]`); if ($el != null) { - $el.textContent = String(value); + $el.textContent = String(value) || GlyphChars.Space; } }