fix apply button
This commit is contained in:
parent
ea561861b8
commit
82e4137088
3 changed files with 15 additions and 12 deletions
|
|
@ -34,10 +34,11 @@ export async function resolveRelativePathInDir(
|
|||
If no meaninful path match just concatenates to first dir's uri
|
||||
*/
|
||||
export async function inferResolvedUriFromRelativePath(
|
||||
relativePath: string,
|
||||
_relativePath: string,
|
||||
ide: IDE,
|
||||
dirCandidates?: string[],
|
||||
): Promise<string> {
|
||||
const relativePath = _relativePath.trim().replaceAll("\\", "/");
|
||||
const dirs = dirCandidates ?? (await ide.getWorkspaceDirs());
|
||||
|
||||
if (dirs.length === 0) {
|
||||
|
|
@ -51,7 +52,7 @@ export async function inferResolvedUriFromRelativePath(
|
|||
suffixes.push(segments.slice(i).join("/"));
|
||||
}
|
||||
|
||||
// For each suffix, try to find a unique matching directory
|
||||
// For each suffix, try to find a unique matching dir/file
|
||||
for (const suffix of suffixes) {
|
||||
const uris = dirs.map((dir) => ({
|
||||
dir,
|
||||
|
|
@ -78,6 +79,13 @@ export async function inferResolvedUriFromRelativePath(
|
|||
}
|
||||
}
|
||||
|
||||
// Sometimes the model will decide to only output the base name or small number of path parts
|
||||
// in which case we shouldn't create a new file if it matches the current file
|
||||
const activeFile = await ide.getCurrentFile();
|
||||
if (activeFile && activeFile.path.endsWith(relativePath)) {
|
||||
return activeFile.path;
|
||||
}
|
||||
|
||||
// If no unique match found, use the first directory
|
||||
return joinPathsToUri(dirs[0], relativePath);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
updateApplyState,
|
||||
setMode,
|
||||
newSession,
|
||||
selectIsInEditMode,
|
||||
} from "../redux/slices/sessionSlice";
|
||||
import { getFontSize, isMetaEquivalentKeyPressed } from "../util";
|
||||
import { ROUTES } from "../util/navigation";
|
||||
|
|
@ -221,7 +222,11 @@ const Layout = () => {
|
|||
[],
|
||||
);
|
||||
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
useWebviewListener("exitEditMode", async () => {
|
||||
if (!isInEditMode) {
|
||||
return;
|
||||
}
|
||||
dispatch(
|
||||
loadLastSession({
|
||||
saveCurrentSession: false,
|
||||
|
|
|
|||
|
|
@ -99,16 +99,6 @@ export default function StepContainerPreToolbar(
|
|||
ideMessenger.ide,
|
||||
);
|
||||
|
||||
// Sometimes the model will decide to only output the base name
|
||||
// in which case we shouldn't create a new file if it matches the current file
|
||||
const exists = await ideMessenger.ide.fileExists(fileUri);
|
||||
if (!exists) {
|
||||
const activeFile = await ideMessenger.ide.getCurrentFile();
|
||||
if (activeFile && activeFile.path.endsWith(props.relativeFilepath)) {
|
||||
fileUri = activeFile.path;
|
||||
}
|
||||
}
|
||||
|
||||
ideMessenger.post("applyToFile", {
|
||||
streamId: streamIdRef.current,
|
||||
filepath: fileUri,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue