Skip to content

Commit

Permalink
fix #34, untrack error
Browse files Browse the repository at this point in the history
  • Loading branch information
Newdea committed Jan 14, 2024
1 parent c7fb9f6 commit eb9dcd7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [unrelease]

- fix #34, untrack error;
-

## [1.10.5.5] 元旦快乐~

Expand Down
23 changes: 11 additions & 12 deletions src/dataStore/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ export class DataStore {
async save(path = this.dataPath) {
try {
await app.vault.adapter.write(path, JSON.stringify(this.data));
this.data.mtime = await this.getmtime();
} catch (error) {
MiscUtils.notice("Unable to save data file!");
console.log(error);
return;
}
this.data.mtime = await this.getmtime();
}

/**
Expand Down Expand Up @@ -490,12 +490,13 @@ export class DataStore {

const trackedFile = this.getTrackedFile(path);
const note = app.vault.getAbstractFileByPath(path) as TFile;
let cardName: string = null;

if (note != null && trackedFile.tags.length > 0) {
// const fileCachedData = app.metadataCache.getFileCache(note) || {};
// const tags = getAllTags(fileCachedData) || [];
const fileCachedData = app.metadataCache.getFileCache(note) || {};
const tags = getAllTags(fileCachedData) || [];
const deckname = Tags.getNoteDeckName(note, this.settings);
// const cardName = Tags.getTagFromSettingTags(tags, this.settings.flashcardTags);
cardName = Tags.getTagFromSettingTags(tags, this.settings.flashcardTags);
if (deckname !== null || this.settings.convertFoldersToDecks) {
// || cardName !== null
// it's taged file, can't untrack by this.
Expand All @@ -511,19 +512,17 @@ export class DataStore {
const lastTag = trackedFile.lastTag;
trackedFile.setUnTracked();
for (const key in trackedFile.items) {
const ind = trackedFile.items[key];
this.unTrackItem(ind);
numItems++;
const id = trackedFile.items[key];
if (id >= 0) {
this.unTrackItem(id);
numItems++;
}
}
const fileCachedData = app.metadataCache.getFileCache(note) || {};
const tags = getAllTags(fileCachedData) || [];
const cardName = Tags.getTagFromSettingTags(tags, this.settings.flashcardTags);
if (cardName == null && this.settings.trackedNoteToDecks) {
trackedFile.cardIDs.forEach(this.unTrackItem, this);
trackedFile.cardIDs.filter((id) => id >= 0).forEach(this.unTrackItem, this);
numItems += trackedFile.cardIDs.length;
}

// when file not exist, or doesn't have carditems, del it.
let nulrstr: string = "";
// this.data.trackedFiles[index] = null;
if (note == null) {
Expand Down
3 changes: 1 addition & 2 deletions src/dataStore/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ export class Queue implements IQueue {
let untrackedFiles = 0;
let removedItems = 0;
const bUnTfiles = new Set<TrackedFile>();
let validItems: RepetitionItem[] = [];
await Promise.all(
store.data.trackedFiles.map(async (file, _idx) => {
if (file?.path == undefined || !file.isTracked) return false;
Expand All @@ -205,7 +204,7 @@ export class Queue implements IQueue {
return exists;
}),
);
validItems = store.items.filter((item) => item != null && item.isTracked);
const validItems = store.items.filter((item) => item != null && item.isTracked);
validItems
.filter((item) => item.isCard)
.forEach((item) => {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/reviewresponse-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ export class reviewResponseModal {

private addKeysEvent() {
const bar = document.getElementById(this.barId);
const Markdown = app.workspace.getActiveViewOfType(MarkdownView);
// const Markdown = app.workspace.getActiveViewOfType(MarkdownView);

document.body.onkeydown = (e) => {
if (
bar &&
bar.checkVisibility() &&
this.isDisplay() &&
Markdown.getMode() === "preview"
app.workspace.getActiveViewOfType(MarkdownView).getMode() === "preview"
) {
const consume = () => {
e.preventDefault();
Expand Down

0 comments on commit eb9dcd7

Please sign in to comment.