Skip to content

Commit

Permalink
fix(drag-patch): fix compatibility issue with legacy editor
Browse files Browse the repository at this point in the history
close #73
  • Loading branch information
aidenlx committed Apr 19, 2022
1 parent 9732259 commit 91ec54a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/drag-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ declare module "obsidian" {
// ) => void;
}
interface MarkdownView {
editMode: MarkdownEditView;
editMode?: MarkdownEditView;
sourceMode?: MarkdownEditView;
}
interface MarkdownEditView {
clipboardManager: ClipboardManager;
Expand Down Expand Up @@ -99,10 +100,15 @@ function VD(e: DragEvent, t: DataTransfer["dropEffect"]) {
const PatchDragManager = (plugin: ALxFolderNote) => {
const { getFolderNote } = plugin.CoreApi;

const view = new MarkdownView(new (WorkspaceLeaf as any)(plugin.app)),
editMode = view.editMode ?? view.sourceMode;

if (!editMode)
throw new Error("Failed to patch clipboard manager: no edit view found");

plugin.register(
around(
new MarkdownView(new (WorkspaceLeaf as any)(plugin.app)).editMode
.clipboardManager.constructor.prototype as ClipboardManager,
editMode.clipboardManager.constructor.prototype as ClipboardManager,
{
handleDragOver: (next) =>
function (this: ClipboardManager, evt, ...args) {
Expand Down
2 changes: 1 addition & 1 deletion src/fn-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export default class ALxFolderNote extends Plugin {
initialized = false;
initialize() {
if (this.initialized) return;
PatchDragManager(this);
PatchFileExplorer(this);
document.body.toggleClass(
MobileNoClickMark,
Expand Down Expand Up @@ -103,6 +102,7 @@ export default class ALxFolderNote extends Plugin {
initCalled = true;
registerSetFolderIconCmd(this);
this.app.workspace.onLayoutReady(this.initialize.bind(this));
PatchDragManager(this);
this.noticeFoldervChange();
};

Expand Down

0 comments on commit 91ec54a

Please sign in to comment.