Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: add right-click context menu to timeline track list

esenginee2a5387dc467
diff --git a/editor/src/panels/timeline/TimelinePanel.ts b/editor/src/panels/timeline/TimelinePanel.ts
index 1bc209bfb..58ee85d4e 100644
--- a/editor/src/panels/timeline/TimelinePanel.ts
+++ b/editor/src/panels/timeline/TimelinePanel.ts
@@ -7,7 +7,7 @@ import { TimelineToolbar } from './TimelineToolbar';
import { TimelineTrackList } from './TimelineTrackList';
import { TimelineKeyframeArea, type TimelineAssetData, type TimelineTrackData } from './TimelineKeyframeArea';
import { TimelineCurveEditor } from './TimelineCurveEditor';
-import { AddKeyframeCommand, ReorderTrackCommand, RenameTrackCommand } from './TimelineCommands';
+import { AddKeyframeCommand, ReorderTrackCommand, RenameTrackCommand, DeleteTrackCommand } from './TimelineCommands';
import { getEditorContext } from '../../context/EditorContext';
import { getSharedRenderContext } from '../../renderer';
import { getComponent as getComponentDef } from 'esengine';
@@ -570,6 +570,7 @@ export class TimelinePanel implements PanelInstance {
(from, to) => this.reorderTrack(from, to),
(idx, oldName, newName) => this.renameTrack(idx, oldName, newName),
(ti, ci) => this.showCurveEditor(ti, ci),
+ (idx) => this.deleteTrack(idx),
);
this.keyframeArea_ = new TimelineKeyframeArea(keyframesEl, this.state_, this);
this.keyframeArea_.onKeyframeSelectionChange = (summary) => this.toolbar_?.setSelectionSummary(summary);
@@ -640,6 +641,15 @@ export class TimelinePanel implements PanelInstance {
this.executeCommand(cmd);
}
+ private deleteTrack(trackIndex: number): void {
+ if (!this.assetData_) return;
+ const cmd = new DeleteTrackCommand(
+ this.assetData_, trackIndex,
+ () => this.onAssetDataChanged(),
+ );
+ this.executeCommand(cmd);
+ }
+
private renameTrack(trackIndex: number, oldName: string, newName: string): void {
if (!this.assetData_) return;
const cmd = new RenameTrackCommand(
diff --git a/editor/src/panels/timeline/TimelineTrackList.ts b/editor/src/panels/timeline/TimelineTrackList.ts
index fe69f8b5c..af5adcc59 100644
--- a/editor/src/panels/timeline/TimelineTrackList.ts
+++ b/editor/src/panels/timeline/TimelineTrackList.ts
@@ -2,6 +2,7 @@ import { icons } from '../../utils/icons';
import type { TimelineState, TimelineTrackState } from './TimelineState';
import { TRACK_HEIGHT } from './TimelineState';
import type { TimelineAssetData } from './TimelineKeyframeArea';
+import { showContextMenu } from '../../ui/ContextMenu';
const TRACK_TYPE_ICONS: Record<string, (size: number) => string> = {
property: icons.settings,
@@ -27,6 +28,7 @@ function escapeHtml(text: string): string {
export type TrackReorderCallback = (fromIndex: number, toIndex: number) => void;
export type TrackRenameCallback = (trackIndex: number, oldName: string, newName: string) => void;
+export type TrackDeleteCallback = (trackIndex: number) => void;
export type ChannelClickCallback = (trackIndex: number, channelIndex: number) => void;
export class TimelineTrackList {
@@ -37,6 +39,7 @@ export class TimelineTrackList {
private assetData_: TimelineAssetData | null = null;
private onReorder_: TrackReorderCallback | null = null;
private onRename_: TrackRenameCallback | null = null;
+ private onDelete_: TrackDeleteCallback | null = null;
private onChannelClick_: ChannelClickCallback | null = null;
private dragState_: { trackIndex: number; startY: number; timer: number | null } | null = null;
private dragIndicator_: HTMLElement | null = null;
@@ -48,11 +51,13 @@ export class TimelineTrackList {
onReorder?: TrackReorderCallback,
onRename?: TrackRenameCallback,
onChannelClick?: ChannelClickCallback,
+ onDelete?: TrackDeleteCallback,
) {
this.el_ = container;
this.state_ = state;
this.onReorder_ = onReorder ?? null;
this.onRename_ = onRename ?? null;
+ this.onDelete_ = onDelete ?? null;
this.onChannelClick_ = onChannelClick ?? null;
this.render();
this.unsub_ = state.onChange(() => this.update());
@@ -126,6 +131,26 @@ export class TimelineTrackList {
this.state_.notify();
});
+ row.addEventListener('contextmenu', (e) => {
+ e.preventDefault();
+ this.state_.selectedTrackIndex = track.index;
+ this.state_.notify();
+ showContextMenu({
+ x: e.clientX,
+ y: e.clientY,
+ items: [
+ { label: 'Rename', icon: icons.pencil(12), onClick: () => {
+ const el = row.querySelector('.es-timeline-track-name') as HTMLElement;
+ if (el) this.startInlineRename(el, track);
+ }},
+ { label: '', separator: true },
+ { label: 'Delete Track', icon: icons.trash(12), onClick: () => {
+ this.onDelete_?.(track.index);
+ }},
+ ],
+ });
+ });
+
const nameEl = row.querySelector('.es-timeline-track-name') as HTMLElement;
nameEl?.addEventListener('dblclick', (e) => {
e.stopPropagation();