Skip to content

Commit fc5b628

Browse files
committed
Remove welcome file and dist artifact
1 parent 286fd76 commit fc5b628

4 files changed

Lines changed: 14 additions & 93 deletions

File tree

anycode-react/dist/Component.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

anycode-react/src/Component.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef } from 'react';
1+
import React, { useLayoutEffect, useRef } from 'react';
22
import { AnycodeEditor } from 'anycode-base';
33

44
interface AnycodeEditorProps {
@@ -10,35 +10,38 @@ export default function AnycodeEditorReact({ id, editorState, }: AnycodeEditorP
1010

1111
const containerRef = useRef<HTMLDivElement>(null);
1212

13-
useEffect(() => {
13+
useLayoutEffect(() => {
1414
if (!editorState || !containerRef.current) return;
1515

16-
containerRef.current.innerHTML = '';
16+
const host = containerRef.current;
17+
const editorContainer = editorState.getContainer();
18+
host.replaceChildren(editorContainer);
19+
1720
if (editorState.hasScroll()) {
18-
containerRef.current.appendChild(editorState.getContainer());
1921
let focus = editorState.requestedFocus();
2022

21-
if(focus) {
23+
if (focus) {
2224
let { line, column } = editorState.getCursor();
2325
if (line !== undefined && column !== undefined) {
2426
editorState.requestFocus(line, column);
2527
editorState.renderCursorOrSelection();
2628
}
2729
} else {
28-
editorState.restoreScroll();
29-
editorState.renderCursorOrSelection();
30+
editorState.onAttach();
3031
}
3132
} else {
3233
editorState.render();
33-
containerRef.current.appendChild(editorState.getContainer());
34-
3534
let { line, column } = editorState.getCursor();
3635
if (line !== undefined && column !== undefined) {
3736
editorState.requestFocus(line, column);
3837
editorState.renderCursorOrSelection();
3938
}
4039
}
41-
40+
41+
return () => {
42+
// The editor node is moved between hosts on the next mount.
43+
// Avoid clearing here to prevent a brief blank frame during switches.
44+
};
4245
}, [id, editorState]);
4346

4447
return <div ref={containerRef} style={{ width: '100%', height: '100%' }} />;

anycode/constants.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
import { FileState } from './types';
2-
3-
export const DEFAULT_FILE: FileState = {
4-
id: 'welcome.js',
5-
name: 'welcome.js',
6-
language: 'javascript',
7-
};
8-
9-
export const DEFAULT_FILE_CONTENT =
10-
`// Welcome to Anycode Editor!
11-
12-
// This is a default file created for you. You can:
13-
// - Open files from the file tree on the left
14-
// - Edit files in the main editor area
15-
// - undo changes with meta + z, redo meta + shift + z
16-
// - copy/paste meta + c/ meta + v
17-
// - cut on meta + x, duplicate on meta + d
18-
// - comment line on meta + /
19-
// - Save changes using the meta + s button
20-
// - Open Files panel with contol + 1
21-
// - Open Terminal panel with contol + 2
22-
23-
console.log('Happy coding! 🚀');
24-
25-
function hello() {
26-
return 'Hello, World!';
27-
}
28-
29-
// Try editing this file!
30-
`;
31-
321
// Backend connection settings
332
// if curent port is 5173 then use 3000 else use current port
343
const port = window.location.port === '5173' ? '3000' : window.location.port;

anycode/hooks/useEditors.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type PendingBatch,
99
type WatcherEdits,
1010
} from '../types';
11-
import { BATCH_DELAY_MS, DEFAULT_FILE, DEFAULT_FILE_CONTENT } from '../constants';
11+
import { BATCH_DELAY_MS } from '../constants';
1212
import { getFileName, getLanguageFromFileName } from '../utils';
1313
import {
1414
Completion,
@@ -48,7 +48,6 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
4848
const [editorStates, setEditorStates] = useState<Map<string, AnycodeEditor>>(new Map());
4949
const editorStatesRef = useRef<Map<string, AnycodeEditor>>(new Map());
5050
const editorRefs = useRef<Map<string, AnycodeEditor>>(new Map());
51-
const defaultFileInitializedRef = useRef(false);
5251

5352
const savedFileContentsRef = useRef<Map<string, string>>(new Map());
5453
const diagnosticsRef = useRef<Map<string, Diagnostic[]>>(new Map());
@@ -442,17 +441,6 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
442441
}
443442
}, [files, initializeEditors]);
444443

445-
useEffect(() => {
446-
if (files.length === 0 && !defaultFileInitializedRef.current) {
447-
defaultFileInitializedRef.current = true;
448-
setFiles([DEFAULT_FILE]);
449-
setPaneActiveFileIds((prev) => ({ ...prev, [DEFAULT_EDITOR_PANE_ID]: DEFAULT_FILE.id }));
450-
setActiveEditorPaneId(DEFAULT_EDITOR_PANE_ID);
451-
cursorHistory.current.undoStack.push({ file: DEFAULT_FILE.id, cursor: { line: 0, column: 0 } });
452-
savedFileContentsRef.current.set(DEFAULT_FILE.id, DEFAULT_FILE_CONTENT);
453-
}
454-
}, [files.length]);
455-
456444
const closeFile = useCallback((fileId: string) => {
457445
flushChanges(fileId);
458446

0 commit comments

Comments
 (0)