UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 1.97 kB
import*as Workspace from"../../models/workspace/workspace.js";import*as SourceFrame from"../../ui/legacy/components/source_frame/source_frame.js";export const HistoryDepth=20;export class EditingLocationHistoryManager{sourcesView;entries=[];current=-1;revealing=!1;constructor(t){this.sourcesView=t}trackSourceFrameCursorJumps(t){t.addEventListener("EditorUpdate",(e=>this.onEditorUpdate(e.data,t)))}onEditorUpdate(t,e){t.docChanged&&this.mapEntriesFor(e.uiSourceCode(),t.changes);const r=t.startState.selection.main,s=t.state.selection.main;!this.revealing&&r.anchor!==s.anchor&&t.transactions.some((t=>Boolean(t.isUserEvent("select.pointer")||t.isUserEvent("select.reveal")||t.isUserEvent("select.search"))))&&(this.updateCurrentState(e.uiSourceCode(),r.head),this.entries.length>this.current+1&&(this.entries.length=this.current+1),this.entries.push(new EditingLocationHistoryEntry(e.uiSourceCode(),s.head)),this.current++,this.entries.length>20&&(this.entries.shift(),this.current--))}updateCurrentState(t,e){if(!this.revealing){const r=this.current>=0?this.entries[this.current]:null;r?.matches(t)&&(r.position=e)}}mapEntriesFor(t,e){for(const r of this.entries)r.matches(t)&&(r.position=e.mapPos(r.position))}reveal(t){const e=Workspace.Workspace.WorkspaceImpl.instance().uiSourceCode(t.projectId,t.url);e&&(this.revealing=!0,this.sourcesView.showSourceLocation(e,t.position,!1,!0),this.revealing=!1)}rollback(){this.current>0&&(this.current--,this.reveal(this.entries[this.current]))}rollover(){this.current<this.entries.length-1&&(this.current++,this.reveal(this.entries[this.current]))}removeHistoryForSourceCode(t){for(let e=this.entries.length-1;e>=0;e--)this.entries[e].matches(t)&&(this.entries.splice(e,1),this.current>=e&&this.current--)}}class EditingLocationHistoryEntry{projectId;url;position;constructor(t,e){this.projectId=t.project().id(),this.url=t.url(),this.position=e}matches(t){return this.url===t.url()&&this.projectId===t.project().id()}}