mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
Fixes issues with create/copy/rename/delete
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
'use strict';
|
||||
import { commands, Event, EventEmitter, FileStat, FileType, Memento, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode';
|
||||
import { getRootUri, getRelativePath } from './extension';
|
||||
import { getRootUri, getRelativePath, isChild } from './extension';
|
||||
import { sha1 } from './sha1';
|
||||
|
||||
const textDecoder = new TextDecoder();
|
||||
@@ -191,21 +191,29 @@ export class ChangeStore implements IChangeStore, IWritableChangeStore {
|
||||
return entries;
|
||||
}
|
||||
|
||||
const folderPath = getRelativePath(rootUri, uri);
|
||||
|
||||
const operations = this.getChanges(rootUri);
|
||||
for (const operation of operations) {
|
||||
switch (operation.type) {
|
||||
case 'changed':
|
||||
continue;
|
||||
|
||||
case 'created': {
|
||||
const file = getRelativePath(rootUri, operation.uri);
|
||||
entries.push([file, FileType.File]);
|
||||
const filePath = getRelativePath(rootUri, operation.uri);
|
||||
if (isChild(folderPath, filePath)) {
|
||||
entries.push([filePath, FileType.File]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'deleted': {
|
||||
const file = getRelativePath(rootUri, operation.uri);
|
||||
const index = entries.findIndex(([path]) => path === file);
|
||||
if (index !== -1) {
|
||||
entries.splice(index, 1);
|
||||
const filePath = getRelativePath(rootUri, operation.uri);
|
||||
if (isChild(folderPath, filePath)) {
|
||||
const index = entries.findIndex(([path]) => path === filePath);
|
||||
if (index !== -1) {
|
||||
entries.splice(index, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -48,13 +48,21 @@ export function activate(context: ExtensionContext) {
|
||||
}
|
||||
|
||||
export function getRelativePath(rootUri: Uri, uri: Uri) {
|
||||
return uri.fsPath.substr(rootUri.fsPath.length + 1);
|
||||
return uri.path.substr(rootUri.path.length + 1);
|
||||
}
|
||||
|
||||
export function getRootUri(uri: Uri) {
|
||||
return workspace.getWorkspaceFolder(uri)?.uri;
|
||||
}
|
||||
|
||||
export function isChild(folderPath: string, filePath: string) {
|
||||
return isDescendent(folderPath, filePath) && filePath.substr(folderPath.length + (folderPath.endsWith('/') ? 0 : 1)).split('/').length === 1;
|
||||
}
|
||||
|
||||
export function isDescendent(folderPath: string, filePath: string) {
|
||||
return folderPath.length === 0 || filePath.startsWith(folderPath.endsWith('/') ? folderPath : `${folderPath}/`);
|
||||
}
|
||||
|
||||
// function openWorkspace(uri: Uri, name: string, location: 'currentWindow' | 'newWindow' | 'addToCurrentWorkspace') {
|
||||
// if (location === 'addToCurrentWorkspace') {
|
||||
// const count = (workspace.workspaceFolders && workspace.workspaceFolders.length) || 0;
|
||||
|
||||
@@ -152,19 +152,21 @@ export class GitHubApi implements Disposable {
|
||||
updatedTree.push({ path: operation.path, mode: '100644', type: 'blob', content: operation.content });
|
||||
break;
|
||||
|
||||
case 'changed':
|
||||
const item = updatedTree.find(item => item.path === operation.path);
|
||||
if (item !== undefined) {
|
||||
updatedTree.push({ ...item, content: operation.content });
|
||||
case 'changed': {
|
||||
const index = updatedTree.findIndex(item => item.path === operation.path);
|
||||
if (index !== -1) {
|
||||
const { path, mode, type } = updatedTree[index];
|
||||
updatedTree.splice(index, 1, { path: path, mode: mode, type: type, content: operation.content });
|
||||
}
|
||||
break;
|
||||
|
||||
case 'deleted':
|
||||
}
|
||||
case 'deleted': {
|
||||
const index = updatedTree.findIndex(item => item.path === operation.path);
|
||||
if (index !== -1) {
|
||||
updatedTree.splice(index, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -179,7 +181,8 @@ export class GitHubApi implements Disposable {
|
||||
case 'changed':
|
||||
const item = treeResp.data.tree.find(item => item.path === operation.path) as GitCreateTreeParamsTree;
|
||||
if (item !== undefined) {
|
||||
updatedTree.push({ ...item, content: operation.content });
|
||||
const { path, mode, type } = item;
|
||||
updatedTree.push({ path: path, mode: mode, type: type, content: operation.content });
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user