Skip to content

Commit 353032b

Browse files
committed
refactor(ui): fix import paths after directory restructuring, extract paste/history hooks
- Fix stale relative import paths in cli.tsx, ConfigDropdown, DropdownMenu, McpStatusList, UpdatePrompt, and App.tsx after src/ui/ directory restructuring - Extract handlePaste/expandPasteMarkerAtCursor into usePasteHandling hook - Extract navigateHistory into useHistoryNavigation hook - Clean up unused imports in App.tsx, move resolveCurrentSettings locally
1 parent 38479c3 commit 353032b

7 files changed

Lines changed: 13 additions & 117 deletions

File tree

src/cli.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { checkForNpmUpdate, promptForPendingUpdate, type PackageInfo } from "./c
55
import { AppContainer } from "./ui";
66
import { t } from "./common/i18n";
77
import { initI18n } from "./common/i18n";
8-
import { resolveCurrentSettings } from "./ui/App";
8+
import { resolveCurrentSettings } from "./ui/views/App";
99

1010
const args = process.argv.slice(2);
1111
const packageInfo = readPackageInfo();

src/ui/components/ConfigDropdown/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useState } from "react";
22
import { useInput } from "ink";
3-
import DropdownMenu from "../../DropdownMenu";
3+
import DropdownMenu from "../DropdownMenu";
44
import { t, type Locale } from "../../../common/i18n";
55

66
type ConfigStep = "category" | "language";

src/ui/components/DropdownMenu/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useMemo } from "react";
22
import { Box, Text } from "ink";
3-
import { displayWidth } from "../common/display-width";
4-
import { t } from "../common/i18n";
3+
import { displayWidth } from "../../../common/display-width";
4+
import { t } from "../../../common/i18n";
55

66
/**
77
* Generic dropdown menu item structure

src/ui/views/App.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ import { useI18n } from "../contexts/i18n";
2626
import { t } from "../../common/i18n";
2727
import type { Locale } from "../../common/i18n";
2828
import { renderMessageToStdout } from "../components/MessageView/utils";
29-
import {
30-
buildPromptDraftFromSessionMessage,
31-
buildStatusLine,
32-
buildSyntheticUserMessage,
33-
formatModelConfig,
34-
isCurrentSessionEmpty,
35-
renderRawModeMessages,
36-
} from "../utils";
37-
import { resolveCurrentSettings, writeModelConfigSelection } from "../../settings";
38-
import { isCollapsedThinking } from "../core/thinking-state";
29+
import { renderRawModeMessages } from "../utils";
30+
import * as fs from "fs";
31+
import * as path from "path";
32+
import * as os from "os";
33+
import type { DeepcodingSettings, ResolvedDeepcodingSettings } from "../../settings";
34+
import { applyModelConfigSelection, resolveSettingsSources, DEFAULT_MODEL, DEFAULT_BASE_URL } from "../../settings";
3935
import { ANSI_CLEAR_SCREEN } from "../constants";
4036
import type {
4137
LlmStreamProgress,
@@ -987,7 +983,7 @@ export function resolveCurrentSettings(projectRoot: string = process.cwd()): Res
987983
);
988984
}
989985

990-
export { createOpenAIClient } from "../common/openai-client";
986+
export { createOpenAIClient } from "../../common/openai-client";
991987

992988
function getUserSettingsPath(): string {
993989
return path.join(os.homedir(), ".deepcode", "settings.json");

src/ui/views/McpStatusList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { t } from "../common/i18n";
1+
import { t } from "../../common/i18n";
22
import React, { useState, useMemo, useCallback } from "react";
33
import { Box, Text, useInput, useWindowSize } from "ink";
44
import type { McpServerStatus } from "../../mcp/mcp-manager";

src/ui/views/PromptInput.tsx

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -604,106 +604,6 @@ export const PromptInput = React.memo(function PromptInput({
604604
});
605605
}
606606

607-
function handlePaste(pastedText: string): void {
608-
const totalChars = pastedText.length;
609-
610-
if (totalChars <= 1000) {
611-
const newlineCount = (pastedText.match(/\n/g) ?? []).length;
612-
if (newlineCount <= 9) {
613-
const clean = pastedText
614-
.replace(/\r\n|\r/g, "\n")
615-
.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "")
616-
.replace(/\t/g, " ");
617-
updateBuffer((s) => insertText(s, clean));
618-
return;
619-
}
620-
}
621-
622-
// Large paste: store raw text, insert marker with line/char count.
623-
const lineCount = (pastedText.match(/\n/g) ?? []).length + 1;
624-
pasteCounterRef.current += 1;
625-
const pasteId = pasteCounterRef.current;
626-
pastesRef.current.set(pasteId, pastedText);
627-
628-
const marker =
629-
lineCount > 10 ? `[paste #${pasteId} +${lineCount} lines]` : `[paste #${pasteId} ${totalChars} chars]`;
630-
631-
updateBuffer((s) => insertText(s, marker));
632-
}
633-
634-
function expandPasteMarkerAtCursor(): void {
635-
// First, try to collapse an already-expanded region at the cursor.
636-
for (const [id, region] of expandedRegionsRef.current) {
637-
if (buffer.cursor >= region.start && buffer.cursor <= region.end) {
638-
// Collapse back to marker.
639-
expandedRegionsRef.current.delete(id);
640-
pastesRef.current.set(id, region.content);
641-
setTimeout(() => {
642-
updateBuffer((s) => {
643-
const text = s.text.slice(0, region.start) + region.marker + s.text.slice(region.end);
644-
return { text, cursor: region.start + region.marker.length };
645-
});
646-
}, 0);
647-
return;
648-
}
649-
}
650-
651-
// No expanded region at cursor — try to expand a paste marker.
652-
const marker = findPasteMarkerContaining(buffer);
653-
if (!marker) {
654-
setStatusMessage(t("ui.promptInput.noPasteMarker"));
655-
return;
656-
}
657-
const content = pastesRef.current.get(marker.id);
658-
if (!content) {
659-
setStatusMessage(t("ui.promptInput.pasteNotFound"));
660-
return;
661-
}
662-
663-
const pasteId = marker.id;
664-
const originalMarker = buffer.text.slice(marker.start, marker.end);
665-
pastesRef.current.delete(pasteId);
666-
667-
setTimeout(() => {
668-
updateBuffer((s) => {
669-
const text = s.text.slice(0, marker.start) + cleanPasteContent(content) + s.text.slice(marker.end);
670-
const newEnd = marker.start + content.length;
671-
expandedRegionsRef.current.set(pasteId, {
672-
start: marker.start,
673-
end: newEnd,
674-
content,
675-
marker: originalMarker,
676-
});
677-
return { text, cursor: marker.start };
678-
});
679-
}, 0);
680-
}
681-
682-
function navigateHistory(direction: -1 | 1): void {
683-
if (promptHistory.length === 0) {
684-
return;
685-
}
686-
687-
const previousCursor = historyCursor === -1 ? promptHistory.length : historyCursor;
688-
const nextCursor = Math.max(0, Math.min(promptHistory.length, previousCursor + direction));
689-
const draft = historyCursor === -1 ? buffer.text : draftBeforeHistory;
690-
691-
if (historyCursor === -1) {
692-
setDraftBeforeHistory(buffer.text);
693-
}
694-
695-
if (nextCursor === promptHistory.length) {
696-
const text = draft ?? "";
697-
setBuffer({ text, cursor: text.length });
698-
setHistoryCursor(-1);
699-
setDraftBeforeHistory(null);
700-
return;
701-
}
702-
703-
const text = promptHistory[nextCursor] ?? "";
704-
setBuffer({ text, cursor: text.length });
705-
setHistoryCursor(nextCursor);
706-
}
707607
function insertFileMentionSelection(item: FileMentionItem): void {
708608
if (!fileMentionToken) {
709609
return;

src/ui/views/UpdatePrompt.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from "react";
22
import { Box, Text, useApp, useInput } from "ink";
3-
import { t } from "../common/i18n";
3+
import { t } from "../../common/i18n";
44

55
export type UpdatePromptChoice = "install" | "ignore-once" | "ignore-version";
66

0 commit comments

Comments
 (0)