Skip to content

Commit 37bfbe9

Browse files
refactor(web): remove legacy editor (#108)
* refactor(web): remove legacy editor
1 parent 70a39fc commit 37bfbe9

File tree

4 files changed

+53
-146
lines changed

4 files changed

+53
-146
lines changed

packages/web/src/components/editor/EditorWithExecution.tsx

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createSignal,
66
Match,
77
on,
8+
onCleanup,
89
Show,
910
Switch
1011
} from 'solid-js';
@@ -28,7 +29,6 @@ import {
2829
} from '../request-workspace';
2930
import { ScriptPanel } from '../script';
3031
import { CodeEditor } from './CodeEditor';
31-
import { HttpEditor } from './HttpEditor';
3232
import { RequestSelectorBar } from './RequestSelectorBar';
3333
import { ResizableSplitPane } from './ResizableSplitPane';
3434

@@ -212,10 +212,60 @@ export const EditorWithExecution: Component<EditorWithExecutionProps> = (props)
212212

213213
const selectedExecution = () => observer.selectedExecution();
214214

215+
const handleHttpSave = async () => {
216+
if (activeRequestTab() === 'headers' && requestHeaderDraft.isDirty()) {
217+
await requestHeaderDraft.onSave();
218+
return;
219+
}
220+
221+
if (activeRequestTab() === 'body' && requestBodyDraft.isDirty()) {
222+
await requestBodyDraft.onSave();
223+
return;
224+
}
225+
226+
if (workspace.hasUnsavedChanges(props.path)) {
227+
await workspace.saveFile(props.path);
228+
await workspace.loadRequests(props.path);
229+
}
230+
};
231+
232+
createEffect(() => {
233+
if (fileType() !== 'http' || typeof window === 'undefined') {
234+
return;
235+
}
236+
237+
const handleKeyDown = (event: KeyboardEvent) => {
238+
if (
239+
event.defaultPrevented ||
240+
event.repeat ||
241+
!(event.ctrlKey || event.metaKey) ||
242+
event.shiftKey
243+
) {
244+
return;
245+
}
246+
247+
if (event.key === 'Enter') {
248+
event.preventDefault();
249+
void handleHttpExecute();
250+
return;
251+
}
252+
253+
if (event.key.toLowerCase() === 's') {
254+
event.preventDefault();
255+
void handleHttpSave();
256+
}
257+
};
258+
259+
window.addEventListener('keydown', handleKeyDown);
260+
onCleanup(() => {
261+
window.removeEventListener('keydown', handleKeyDown);
262+
});
263+
});
264+
215265
return (
216266
<div class="flex flex-col h-full">
217267
<Switch>
218-
{/* HTTP files: use HTTP editor with request selector */}
268+
{/* HTTP files: request workspace + execution panel */}
219269
<Match when={fileType() === 'http'}>
220270
<RequestSelectorBar
221271
requests={requests()}
@@ -231,7 +281,7 @@ export const EditorWithExecution: Component<EditorWithExecutionProps> = (props)
231281
<div class="flex-1 min-h-0">
232282
<ResizableSplitPane
233283
left={
234-
<div class="flex h-full min-h-0 flex-col">
284+
<div class="h-full min-h-0 overflow-auto">
235285
<RequestWorkspaceTabs
236286
activeTab={activeRequestTab()}
237287
onTabChange={setActiveRequestTab}
@@ -272,9 +322,6 @@ export const EditorWithExecution: Component<EditorWithExecutionProps> = (props)
272322
onSaveBody={requestBodyDraft.onSave}
273323
onDiscardBody={requestBodyDraft.onDiscard}
274324
/>
275-
<div class="flex-1 min-h-0">
276-
<HttpEditor path={props.path} onExecute={handleHttpExecute} />
277-
</div>
278325
</div>
279326
}
280327
right={

packages/web/src/components/editor/HttpEditor.tsx

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

packages/web/src/components/editor/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export { CreateFileDialog } from './CreateFileDialog';
22
export { EditorTabs } from './EditorTabs';
33
export { EditorWithExecution } from './EditorWithExecution';
4-
export { HttpEditor } from './HttpEditor';
54
export { httpAutocomplete } from './http-autocomplete';
65
export { http, httpLanguage } from './http-language';
76
export { DiagnosticCodes, httpLintExtension } from './http-linter';
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { lazy } from 'solid-js';
22

33
export const LazyEditorWithExecution = lazy(() => import('./EditorWithExecution'));
4-
export const LazyHttpEditor = lazy(() => import('./HttpEditor'));
54
export const LazyCodeEditor = lazy(() => import('./CodeEditor'));

0 commit comments

Comments
 (0)