Skip to content

Commit 519a651

Browse files
zhangtengjinwewoor
authored andcommitted
feat: code format premitter
code format premitter
1 parent 6c80a4f commit 519a651

File tree

3 files changed

+67
-48
lines changed

3 files changed

+67
-48
lines changed

src/controller/explorer/explorer.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
explorerService,
88
} from 'mo';
99
import * as React from 'react';
10-
import { IFolderTree } from 'mo/model'
10+
import { IFolderTree } from 'mo/model';
1111
import { ExplorerView, FolderTreeView } from 'mo/workbench/sidebar/explore';
1212
import { IActionBarItem } from 'mo/components/actionBar';
1313

@@ -100,7 +100,7 @@ export class ExplorerController
100100
id: 'new_file',
101101
title: 'New File',
102102
iconName: 'codicon-new-file',
103-
onClick: () => { },
103+
onClick: () => {},
104104
},
105105
{
106106
id: 'new_folder',

src/controller/explorer/folderTree.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class FolderTreeController
3333
this.initView();
3434
}
3535

36-
private initView() { }
36+
private initView() {}
3737

3838
public readonly onSelectFile = (file: ITreeNodeItem) => {
3939
const tabData = {

src/services/workbench/explorerService.ts

+64-45
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class TreeView implements ITreeInterface {
154154
1,
155155
{
156156
...node,
157-
...extra
157+
...extra,
158158
}
159159
);
160160
this.updateChildren(parentIndex[this.childNodeName]);
@@ -164,14 +164,12 @@ export class TreeView implements ITreeInterface {
164164

165165
updateChildren(children: IIndex) {
166166
const self = this;
167-
children.forEach(
168-
function (id, i) {
169-
const index = self.getIndex(id);
170-
index.prev = index.next = null;
171-
if (i > 0) index.prev = children[i - 1];
172-
if (i < children.length - 1) index.next = children[i + 1];
173-
}
174-
);
167+
children.forEach(function (id, i) {
168+
const index = self.getIndex(id);
169+
index.prev = index.next = null;
170+
if (i > 0) index.prev = children[i - 1];
171+
if (i < children.length - 1) index.next = children[i + 1];
172+
});
175173
}
176174

177175
insert(obj: ITreeNodeItem, parentId: number, i: number) {
@@ -222,7 +220,6 @@ export class TreeView implements ITreeInterface {
222220
}
223221
}
224222

225-
226223
export interface IExplorerService extends Component<IExplorer> {
227224
addPanel(panel: IPanelItem | IPanelItem[]): void;
228225
reset(): void;
@@ -275,13 +272,16 @@ export class ExplorerService
275272
next.splice(index, 1);
276273
}
277274
this.setState({
278-
data: next
275+
data: next,
279276
});
280277
}
281278

282279
/* ============================Tree============================ */
283280

284-
private getFileIconByExtensionName(name: string, fileType: FileType): string {
281+
private getFileIconByExtensionName(
282+
name: string,
283+
fileType: FileType
284+
): string {
285285
if (fileType === FileTypes.FOLDER) return '';
286286
const fileExtension = name && name.split('.')?.[1];
287287
let icon = 'symbol-file';
@@ -310,15 +310,19 @@ export class ExplorerService
310310

311311
private getCurrentRootFolderAndIndex(id: number) {
312312
const currentRootFolder: ITreeNodeItem = this.getRootFolderById(id);
313-
const index = this.getRootFolderIndexByRootId((currentRootFolder as any).id) as number;
313+
const index = this.getRootFolderIndexByRootId(
314+
(currentRootFolder as any).id
315+
) as number;
314316
return {
315317
index,
316-
currentRootFolder
317-
}
318+
currentRootFolder,
319+
};
318320
}
319321

320322
public getRootFolderIndexByRootId(id: number): number | undefined {
321-
return this.state.folderTree?.data!.findIndex((folder) => folder.id === id);
323+
return this.state.folderTree?.data!.findIndex(
324+
(folder) => folder.id === id
325+
);
322326
}
323327

324328
public getRootFolderByRootId(id: number): ITreeNodeItem | undefined {
@@ -327,12 +331,12 @@ export class ExplorerService
327331

328332
public getRootFolderById(id: number): ITreeNodeItem {
329333
let rootNode = {};
330-
this.state.folderTree?.data?.forEach(folder => {
334+
this.state.folderTree?.data?.forEach((folder) => {
331335
const treeInstance = new TreeView(folder);
332336
if (treeInstance.get(id)) {
333337
rootNode = folder;
334338
}
335-
})
339+
});
336340
return rootNode;
337341
}
338342

@@ -345,7 +349,7 @@ export class ExplorerService
345349
next?.push(folder);
346350
}
347351
this.setState({
348-
folderTree: { ...folderTree, data: next }
352+
folderTree: { ...folderTree, data: next },
349353
});
350354
}
351355

@@ -357,95 +361,111 @@ export class ExplorerService
357361
next.splice(index, 1);
358362
}
359363
this.setState({
360-
folderTree: { ...folderTree, data: next }
364+
folderTree: { ...folderTree, data: next },
361365
});
362366
}
363367

364368
public updateFile(file, callback) {
365369
const { folderTree } = this.state;
366370
const { id, name, fileType } = file;
367371
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
368-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
372+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
373+
id
374+
);
369375
const tree = new TreeView(currentRootFolder);
370376
if (name) {
371377
tree.update(id, {
372378
...file,
373379
icon: this.getFileIconByExtensionName(name, fileType),
374-
modify: false
375-
})
380+
modify: false,
381+
});
376382
} else {
377-
tree.remove(id)
383+
tree.remove(id);
378384
}
379385
if (index > -1) cloneData[index] = tree.obj;
380386
this.setState({
381-
folderTree: { ...folderTree, data: cloneData }
387+
folderTree: { ...folderTree, data: cloneData },
382388
});
383389
if (callback) callback();
384390
}
385391

386392
public rename(id: number, callback?: Function) {
387393
const { folderTree } = this.state;
388394
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
389-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
395+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
396+
id
397+
);
390398
const tree = new TreeView(currentRootFolder);
391399
tree.update(id, {
392-
modify: true
393-
})
400+
modify: true,
401+
});
394402
if (index > -1) cloneData[index] = tree.obj;
395403
this.setState({
396-
folderTree: { ...folderTree, data: cloneData }
404+
folderTree: { ...folderTree, data: cloneData },
397405
});
398406
if (callback) callback();
399407
}
400408

401409
public delete(id: number, callback?: Function) {
402410
const { folderTree } = this.state;
403411
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
404-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
412+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
413+
id
414+
);
405415
const tree = new TreeView(currentRootFolder);
406416
tree.remove(id);
407417
if (index > -1) cloneData[index] = tree.obj;
408418
this.setState({
409-
folderTree: { ...folderTree, data: cloneData }
419+
folderTree: { ...folderTree, data: cloneData },
410420
});
411421
if (callback) callback();
412422
}
413423

414424
public newFile(parentId: number, callback?: Function) {
415425
const { folderTree } = this.state;
416426
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
417-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(parentId)
427+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
428+
parentId
429+
);
418430
const tree = new TreeView(currentRootFolder);
419431
if (!parentId) {
420432
const tabData = {
421433
id: `${Math.random() * 10 + 1}`,
422434
name: `Untitled`,
423-
modified: false
435+
modified: false,
424436
};
425-
editorService.open(tabData)
437+
editorService.open(tabData);
426438
}
427-
tree.append(new TreeNodeModel({
428-
modify: true
429-
}), parentId)
439+
tree.append(
440+
new TreeNodeModel({
441+
modify: true,
442+
}),
443+
parentId
444+
);
430445
if (index > -1) cloneData[index] = tree.obj;
431446
this.setState({
432-
folderTree: { ...folderTree, data: cloneData }
447+
folderTree: { ...folderTree, data: cloneData },
433448
});
434449
if (callback) callback();
435450
}
436451

437452
public newFolder(parentId, callback: Function) {
438453
const { folderTree } = this.state;
439454
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
440-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(parentId)
455+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
456+
parentId
457+
);
441458
const tree = new TreeView(currentRootFolder);
442-
tree.append(new TreeNodeModel({
443-
fileType: FileTypes.FOLDER as FileType,
444-
modify: true
445-
}), parentId)
459+
tree.append(
460+
new TreeNodeModel({
461+
fileType: FileTypes.FOLDER as FileType,
462+
modify: true,
463+
}),
464+
parentId
465+
);
446466
if (index > -1) cloneData[index] = tree.obj;
447467
this.setState({
448-
folderTree: { ...folderTree, data: cloneData }
468+
folderTree: { ...folderTree, data: cloneData },
449469
});
450470
if (callback) callback();
451471
}
@@ -457,5 +477,4 @@ export class ExplorerService
457477
}),
458478
});
459479
};
460-
461480
}

0 commit comments

Comments
 (0)