Skip to content

Commit 94298c5

Browse files
committed
feat(icon): Append conflict icon
1 parent c1d4fc0 commit 94298c5

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,11 @@ export default class InvioPlugin extends Plugin {
946946
log.debug('file modified: ', file);
947947
if (this.isUnderWatch(file)) {
948948
this.setRibbonPendingStatus();
949+
if (file.name.endsWith('.conflict.md')) {
950+
setTimeout(() => {
951+
addIconForconflictFile(this, file)
952+
}, 300)
953+
}
949954
}
950955
})
951956
)

src/sync.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import { isInsideObsFolder, ObsConfigDirFileType } from "./obsFolderLister";
5656
import { Utils } from './utils/utils';
5757
import { Path } from './utils/path';
5858
import { log } from "./moreOnLog";
59-
import { settings } from "assets/webworker.txt";
6059
import { getRemoteFileDiff } from './diff/index';
6160

6261
export const RemoteSrcPrefix = 'op-remote-source-raw/'

src/utils/icon.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createElement, FolderSync, RefreshCcw, FileText, FolderSymlink, CopySla
66
import InvioPlugin from '../main';
77
import style from './style';
88
import svg from './svg';
9+
import { LocalConflictPrefix, RemoteConflictPrefix } from '../sync'
910

1011
export interface Icon {
1112
name: string;
@@ -150,7 +151,8 @@ const createIconNode = (plugin: InvioPlugin, path: string, svgStr: string, color
150151
// path from the document itself.
151152
const paths = path.split('/');
152153
let parentNode: any = null;
153-
paths?.reduce((left, cur) => {
154+
paths?.reduce(async (leftPromise, cur) => {
155+
const left = await leftPromise;
154156
let target = '';
155157
if (!left) {
156158
target = cur;
@@ -159,28 +161,26 @@ const createIconNode = (plugin: InvioPlugin, path: string, svgStr: string, color
159161
}
160162
// checking target path
161163
let node: any = document.querySelector(`[data-path="${target}"]`);
162-
console.log('check node...', target, node)
163164
if (node) {
164165
parentNode = node;
165166
} else {
166167
if (parentNode) {
167168
parentNode.click();
168-
console.log('clicking node: ', target, parentNode);
169+
await sleep(300);
169170
node = document.querySelector(`[data-path="${target}"]`);
170-
console.log('to find child node: ', node);
171171
if (node) {
172172
parentNode = node;
173173
}
174174
} else {
175175
if (!repeated) {
176176
setTimeout(() => {
177177
createIconNode(plugin, path, svgStr, color, true);
178-
}, 3000)
178+
}, 3000);
179179
}
180180
}
181181
}
182182
return target;
183-
}, '')
183+
}, Promise.resolve(''))
184184
const node = document.querySelector(`[data-path="${path}"]`);
185185

186186
if (!node) {
@@ -218,6 +218,18 @@ export const addIconForconflictFile = (plugin: InvioPlugin, fileOrFolder: TAbstr
218218
if ((fileOrFolder instanceof TFile) && fileOrFolder.name.endsWith('.conflict.md')) {
219219
// Add alert icon for conflict file
220220
const { iconSvgCopySlash } = getIconSvg();
221+
const fileP = fileOrFolder.path;
222+
223+
const idx1 = fileP.indexOf(LocalConflictPrefix);
224+
if (idx1 > 0) {
225+
const folderP = fileP.slice(0, idx1) + LocalConflictPrefix
226+
createIconNode(plugin, folderP, iconSvgCopySlash, '#dd1b9a');
227+
}
228+
const idx2 = fileP.indexOf(RemoteConflictPrefix);
229+
if (idx2 > 0) {
230+
const folderP = fileP.slice(0, idx2) + RemoteConflictPrefix
231+
createIconNode(plugin, folderP, iconSvgCopySlash, '#dd1b9a');
232+
}
221233
createIconNode(plugin, fileOrFolder.path, iconSvgCopySlash, '#dd1b9a');
222234
}
223235
}

0 commit comments

Comments
 (0)