Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit adefcd0

Browse files
committed
fixing split view compatibility
1 parent a6d8e22 commit adefcd0

File tree

2 files changed

+53
-71
lines changed

2 files changed

+53
-71
lines changed

src/helpers/VaultManagement.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RowDataType, NormalizedPath, TableDataType, TableColumn } from 'cdm/FolderModel';
1+
import { RowDataType, NormalizedPath, TableColumn } from 'cdm/FolderModel';
22
import { Notice, TFile } from 'obsidian';
33
import { VaultManagerDB } from 'services/FileManagerService';
44
import { LOGGER } from "services/Logger";
@@ -12,7 +12,6 @@ import { DatabaseYaml } from 'cdm/DatabaseModel';
1212
import { Literal } from 'obsidian-dataview/lib/data-model/value';
1313
import { DataArray } from 'obsidian-dataview/lib/api/data-array';
1414
import { EditionError } from 'errors/ErrorTypes';
15-
import { TableStateInterface } from 'cdm/TableStateInterface';
1615
import { LocalSettings } from 'cdm/SettingsModel';
1716

1817
const noBreakSpace = /\u00A0/g;
@@ -22,35 +21,34 @@ const noBreakSpace = /\u00A0/g;
2221
* @param data
2322
* @returns
2423
*/
25-
export function hasFrontmatterKey(data: string | TFile): boolean {
24+
export function hasFrontmatter(data: string): boolean {
2625
if (!data) return false;
2726

28-
if (typeof data === 'string') {
29-
const frontmatterRegex = /^---[\s\S]+?---/g;
30-
return frontmatterRegex.test(data);
31-
}
27+
const frontmatterRegex = /^---[\s\S]+?---/g;
28+
return frontmatterRegex.test(data);
29+
}
3230

31+
/** Check if file is a database note */
32+
export function isDatabaseNote(data: string | TFile) {
3333
if (data instanceof TFile) {
34+
if (!data) return false;
35+
3436
const cache = app.metadataCache.getFileCache(data);
35-
return !!cache?.frontmatter && !!cache?.frontmatter['kanban-plugin'];
36-
}
3737

38-
return false;
39-
}
38+
return !!cache?.frontmatter && !!cache?.frontmatter[DatabaseCore.FRONTMATTER_KEY];
39+
} else {
40+
const match = data.match(/---\s+([\w\W]+?)\s+---/);
4041

41-
/** Check if file is a database note */
42-
export function isDatabaseNote(data: string): boolean {
43-
if (!data) return false;
44-
const match = data.match(/---\s+([\w\W]+?)\s+---/);
42+
if (!match) {
43+
return false;
44+
}
4545

46-
if (!match) {
47-
return false;
48-
}
46+
if (!match[1].contains(DatabaseCore.FRONTMATTER_KEY)) {
47+
return false;
48+
}
4949

50-
if (!match[1].contains(DatabaseCore.FRONTMATTER_KEY)) {
51-
return false;
50+
return true;
5251
}
53-
return true;
5452
}
5553

5654
export function getNormalizedPath(path: string): NormalizedPath {
@@ -336,7 +334,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
336334
// Execute action
337335
if (updateOptions[option]) {
338336
// Check if file has frontmatter
339-
if (!hasFrontmatterKey(content)) {
337+
if (!hasFrontmatter(content)) {
340338
// If not, add it
341339
await addFrontmatter();
342340
}

src/main.ts

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { LOGGER } from 'services/Logger';
3131
import { DatabaseCore, DatabaseFrontmatterOptions, DEFAULT_SETTINGS, YAML_INDENT } from 'helpers/Constants';
3232
import { PreviewDatabaseModeService } from 'services/MarkdownPostProcessorService';
3333
import { unmountComponentAtNode } from 'react-dom';
34-
import { hasFrontmatterKey } from 'helpers/VaultManagement';
34+
import { isDatabaseNote } from 'helpers/VaultManagement';
3535
import { getParentWindow } from 'helpers/WindowElement';
3636

3737
interface WindowRegistry {
@@ -187,6 +187,16 @@ export default class DBFolderPlugin extends Plugin {
187187
return this.stateManagers.get(file);
188188
}
189189

190+
getStateManagerFromViewID(id: string, win: Window) {
191+
const view = this.getDatabaseView(id, win);
192+
193+
if (!view) {
194+
return null;
195+
}
196+
197+
return this.stateManagers.get(view.file);
198+
}
199+
190200
removeView(view: DatabaseView) {
191201
const entry = Array.from(this.windowRegistry.entries()).find(([, reg]) => {
192202
return reg.viewMap.has(view.id);
@@ -251,8 +261,20 @@ export default class DBFolderPlugin extends Plugin {
251261
return [];
252262
}
253263

254-
getDatabaseView(id: string) {
255-
return this.viewMap.get(id);
264+
getDatabaseView(id: string, win: Window) {
265+
const reg = this.windowRegistry.get(win);
266+
267+
if (reg?.viewMap.has(id)) {
268+
return reg.viewMap.get(id);
269+
}
270+
271+
for (const reg of this.windowRegistry.values()) {
272+
if (reg.viewMap.has(id)) {
273+
return reg.viewMap.get(id);
274+
}
275+
}
276+
277+
return null;
256278
}
257279

258280
mount(win: Window) {
@@ -326,26 +348,26 @@ export default class DBFolderPlugin extends Plugin {
326348
});
327349
return;
328350
}
351+
console.log('file-menu');
329352
if (
330353
!Platform.isMobile &&
331354
file instanceof TFile &&
332355
leaf &&
333356
source === 'sidebar-context-menu' &&
334-
hasFrontmatterKey(file)
357+
isDatabaseNote(file)
335358
) {
336359
const views = this.getDatabaseViews(
337360
getParentWindow(leaf.view.containerEl)
338361
);
339-
let haveDatabaseView = false;
340362

341-
for (const view of views) {
363+
const haveDatabaseView = views.some((view) => {
342364
if (view.file === file) {
343365
view.onPaneMenu(menu, 'more-options', false);
344-
haveDatabaseView = true;
345-
break;
366+
return true;
346367
}
347-
}
348-
368+
return false;
369+
});
370+
console.log('haveDatabaseView', haveDatabaseView);
349371
if (!haveDatabaseView) {
350372
menu.addItem((item) => {
351373
item
@@ -358,7 +380,6 @@ export default class DBFolderPlugin extends Plugin {
358380
this.setDatabaseView(leaf);
359381
});
360382
});
361-
362383
return;
363384
}
364385
}
@@ -367,7 +388,7 @@ export default class DBFolderPlugin extends Plugin {
367388
leaf?.view instanceof MarkdownView &&
368389
file instanceof TFile &&
369390
source === 'pane-more-options' &&
370-
hasFrontmatterKey(file)
391+
isDatabaseNote(file)
371392
) {
372393
menu.addItem((item) => {
373394
item
@@ -455,43 +476,6 @@ export default class DBFolderPlugin extends Plugin {
455476
},
456477
})
457478
);
458-
459-
// //Add a menu item to go back to database view
460-
// this.register(
461-
// around(MarkdownView.prototype, {
462-
// onPaneMenu(next) {
463-
// return function (menu: Menu) {
464-
// const file = this.file;
465-
// const cache = file
466-
// ? self.app.metadataCache.getFileCache(file)
467-
// : null;
468-
469-
// if (
470-
// !file ||
471-
// !cache?.frontmatter ||
472-
// !cache.frontmatter[DatabaseCore.FRONTMATTER_KEY]
473-
// ) {
474-
// return next.call(this, menu);
475-
// }
476-
477-
// menu
478-
// .addItem((item) => {
479-
// item
480-
// .setTitle('Open as database folder')
481-
// .setIcon(databaseIcon)
482-
// .onClick(() => {
483-
// self.databaseFileModes[this.leaf.id || file.path] =
484-
// DatabaseCore.FRONTMATTER_KEY;
485-
// self.setDatabaseView(this.leaf);
486-
// });
487-
// })
488-
// .addSeparator();
489-
490-
// next.call(this, menu);
491-
// };
492-
// },
493-
// })
494-
// );
495479
}
496480

497481
// private debuggingMobile(plugin:Plugin){

0 commit comments

Comments
 (0)