MCPcopy
hub / github.com/wavetermdev/waveterm / CodeEditPreview

Function CodeEditPreview

frontend/app/view/preview/preview-edit.tsx:39–109  ·  view source on GitHub ↗
({ model }: SpecializedViewProps)

Source from the content-addressed store, hash-verified

37};
38
39function CodeEditPreview({ model }: SpecializedViewProps) {
40 const fileContent = useAtomValue(model.fileContent);
41 const setNewFileContent = useSetAtom(model.newFileContent);
42 const fileInfo = useAtomValue(model.statFile);
43 const fileName = fileInfo?.path || fileInfo?.name;
44
45 const baseName = fileName ? fileName.split("/").pop() : null;
46 const language = baseName && shellFileMap[baseName] ? shellFileMap[baseName] : undefined;
47
48 function codeEditKeyDownHandler(e: WaveKeyboardEvent): boolean {
49 if (checkKeyPressed(e, "Cmd:e")) {
50 fireAndForget(() => model.setEditMode(false));
51 return true;
52 }
53 if (checkKeyPressed(e, "Cmd:s") || checkKeyPressed(e, "Ctrl:s")) {
54 fireAndForget(model.handleFileSave.bind(model));
55 return true;
56 }
57 if (checkKeyPressed(e, "Cmd:r")) {
58 fireAndForget(model.handleFileRevert.bind(model));
59 return true;
60 }
61 return false;
62 }
63
64 useEffect(() => {
65 model.codeEditKeyDownHandler = codeEditKeyDownHandler;
66 model.refreshCallback = () => {
67 globalStore.set(model.refreshVersion, (v) => v + 1);
68 };
69 return () => {
70 model.codeEditKeyDownHandler = null;
71 model.monacoRef.current = null;
72 model.refreshCallback = null;
73 };
74 }, []);
75
76 function onMount(editor: MonacoTypes.editor.IStandaloneCodeEditor, monacoApi: typeof monaco): () => void {
77 model.monacoRef.current = editor;
78
79 const keyDownDisposer = editor.onKeyDown((e: MonacoTypes.IKeyboardEvent) => {
80 const waveEvent = adaptFromReactOrNativeKeyEvent(e.browserEvent);
81 const handled = tryReinjectKey(waveEvent);
82 if (handled) {
83 e.stopPropagation();
84 e.preventDefault();
85 }
86 });
87
88 const isFocused = globalStore.get(model.nodeModel.isFocused);
89 if (isFocused) {
90 editor.focus();
91 }
92
93 return () => {
94 keyDownDisposer.dispose();
95 };
96 }

Callers

nothing calls this directly

Calls 2

popMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected