Skip to content

Commit

Permalink
fix(command): notice is always shown in corresponding target's window
Browse files Browse the repository at this point in the history
close #252
  • Loading branch information
aidenlx committed Mar 19, 2024
1 parent dcd2b49 commit f5b7cdb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 8 additions & 1 deletion apps/app/src/media-note/command/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ export function registerControlCommands(plugin: MxPlugin) {
if (!player) return false;
if (check && !check(player)) return false;
if (checking) return true;
action(player);
if (player.el?.doc) {
const prevActiveDoc = window.activeDocument;
window.activeDocument = player.el.doc;
action(player);
window.activeDocument = prevActiveDoc;
} else {
action(player);
}
},
},
plugin,
Expand Down
20 changes: 14 additions & 6 deletions apps/app/src/media-note/command/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ export function registerNoteCommands(plugin: MxPlugin) {
return;
}
if (checking) return true;
action(view, {
file: active.view.file,
editor: active.view.editor,
from: "player",
});
(async () => {
// keep notice in same window with note
const prevActiveDoc = window.activeDocument;
window.activeDocument = active.containerEl.doc;
await action(view, {
file: active.view.file,
editor: active.view.editor,
from: "player",
});
window.activeDocument = prevActiveDoc;
})();
},
noteCheckCallback: (checking, view, { isMediaNote, ...ctx }) => {
let _view: Promise<MediaView>;
Expand All @@ -158,7 +164,9 @@ export function registerNoteCommands(plugin: MxPlugin) {
plugin.app.workspace.revealLeaf(view.leaf);
_view = Promise.resolve(view);
}
_view.then((v) => action(v, { ...ctx, from: "note" }));
_view.then(async (v) => {
await action(v, { ...ctx, from: "note" });
});
},
};
}
Expand Down

0 comments on commit f5b7cdb

Please sign in to comment.