Keeping last project open
This commit is contained in:
@ -25,13 +25,15 @@
|
||||
onChange?: (value: string) => void;
|
||||
onExecute?: (code: string, source: 'selection' | 'block' | 'document') => void;
|
||||
editorSettings: EditorSettingsStore;
|
||||
mode: 'composition' | 'livecoding';
|
||||
}
|
||||
|
||||
let {
|
||||
value = '',
|
||||
onChange,
|
||||
onExecute,
|
||||
editorSettings
|
||||
editorSettings,
|
||||
mode = 'composition'
|
||||
}: Props = $props();
|
||||
|
||||
let editorContainer: HTMLDivElement;
|
||||
@ -44,6 +46,13 @@
|
||||
function handleExecute() {
|
||||
if (!editorView) return;
|
||||
|
||||
if (mode === 'composition') {
|
||||
const doc = getDocument(editorView.state);
|
||||
flash(editorView, doc.from, doc.to);
|
||||
onExecute?.(doc.text, 'document');
|
||||
return;
|
||||
}
|
||||
|
||||
const selection = getSelection(editorView.state);
|
||||
if (selection.text) {
|
||||
flash(editorView, selection.from, selection.to);
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
onExecute?: (code: string, source: 'selection' | 'block' | 'document') => void;
|
||||
logs?: string[];
|
||||
editorSettings: EditorSettingsStore;
|
||||
mode: 'composition' | 'livecoding';
|
||||
}
|
||||
|
||||
let {
|
||||
@ -17,7 +18,8 @@
|
||||
onChange,
|
||||
onExecute,
|
||||
logs = [],
|
||||
editorSettings
|
||||
editorSettings,
|
||||
mode = 'composition'
|
||||
}: Props = $props();
|
||||
|
||||
let logPanelRef: LogPanel;
|
||||
@ -84,6 +86,7 @@
|
||||
{onChange}
|
||||
{onExecute}
|
||||
{editorSettings}
|
||||
{mode}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
17
src/lib/project-system/persistence.ts
Normal file
17
src/lib/project-system/persistence.ts
Normal file
@ -0,0 +1,17 @@
|
||||
const LAST_PROJECT_KEY = 'oldboy:lastProjectId';
|
||||
|
||||
export function saveLastProjectId(projectId: string | null): void {
|
||||
if (projectId === null) {
|
||||
localStorage.removeItem(LAST_PROJECT_KEY);
|
||||
} else {
|
||||
localStorage.setItem(LAST_PROJECT_KEY, projectId);
|
||||
}
|
||||
}
|
||||
|
||||
export function loadLastProjectId(): string | null {
|
||||
return localStorage.getItem(LAST_PROJECT_KEY);
|
||||
}
|
||||
|
||||
export function clearLastProjectId(): void {
|
||||
localStorage.removeItem(LAST_PROJECT_KEY);
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import type { CsoundProject, ProjectManager } from '../project-system';
|
||||
import { saveLastProjectId } from '../project-system/persistence';
|
||||
|
||||
interface ProjectEditorState {
|
||||
currentProject: CsoundProject | null;
|
||||
@ -54,6 +55,7 @@ export class ProjectEditor {
|
||||
this.state.content = project.content;
|
||||
this.state.hasUnsavedChanges = false;
|
||||
this.state.isNewUnsavedBuffer = false;
|
||||
saveLastProjectId(project.id);
|
||||
}
|
||||
|
||||
createNew(template: string) {
|
||||
@ -61,6 +63,7 @@ export class ProjectEditor {
|
||||
this.state.content = template;
|
||||
this.state.hasUnsavedChanges = false;
|
||||
this.state.isNewUnsavedBuffer = true;
|
||||
saveLastProjectId(null);
|
||||
}
|
||||
|
||||
async save(): Promise<boolean> {
|
||||
@ -105,6 +108,7 @@ export class ProjectEditor {
|
||||
this.state.currentProject = result.data;
|
||||
this.state.hasUnsavedChanges = false;
|
||||
this.state.isNewUnsavedBuffer = false;
|
||||
saveLastProjectId(result.data.id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user