Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Live Preview Support #19

Closed
Archie-2021 opened this issue Jan 14, 2022 · 8 comments · Fixed by #42
Closed

Feature Request: Live Preview Support #19

Archie-2021 opened this issue Jan 14, 2022 · 8 comments · Fixed by #42

Comments

@Archie-2021
Copy link

Please add Live Preview support for this wonderful plugin.

Thanks

@laurastephsmith
Copy link

I'd love this too!

@ycbrd
Copy link

ycbrd commented Jul 15, 2022

Please! I would be very thankful.

@Archie-2021
Copy link
Author

Please! I would be very thankful.

it used to not work after some updates a while ago. it is working for me , have you test it in live-preview?

@huachuman
Copy link

Not working for me either. Is this plugin dead?

@huachuman
Copy link

I came here hoping to comment on the fact the live preview mode doesn't work... and saw my comment from last year. Is there any chance of this getting an updated release? Or does someone know how it could be adapted?

@huachuman
Copy link

I was asking copilot how to modify it and it came back with this:

To make this work in live edit mode, you'll need to modify the modifyOnUnloadFile function in src/bf-main.ts to handle live edit mode.

Currently, it seems like the function is only handling the preview mode. You can check the mode of the current leaf using leaf.view.getViewState().mode. If the mode is 'source', then it's in live edit mode.

Here's a rough idea of how you might modify the function:

modifyOnUnloadFile: leafAction = (leaf) => {
  if (!isIntact(leaf.view)) return;
  const view = leaf.view;
  const mode = view.getViewState().mode;
  if (mode === 'source') {
    // Handle live edit mode
    // You might need to create a new function similar to onUnloadFile for live edit mode
  } else {
    // Existing code to handle preview mode
    const revert = around(leaf.view, {
      // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
      onUnloadFile(next) {
        return function (this: any, ...args) {
          const bridgeEl = view.previewMode.containerEl.querySelector(
            ".markdown-preview-section",
          ) as BridgeEl;
          const { infoList, singleton } = bridgeEl;
          if (infoList) {
            infoList.forEach((info) => info.popover?.tippy.destroy());
            infoList.clear();
          }
          if (singleton) {
            singleton.destroy();
            bridgeEl.singleton = null;
          }
        };
      },
    });
  }
};

I'm not sure how to go about implementing that bu maybe this will give someone a hint

@cut01ass
Copy link

I was asking copilot how to modify it and it came back with this:

To make this work in live edit mode, you'll need to modify the modifyOnUnloadFile function in src/bf-main.ts to handle live edit mode.

Currently, it seems like the function is only handling the preview mode. You can check the mode of the current leaf using leaf.view.getViewState().mode. If the mode is 'source', then it's in live edit mode.

Here's a rough idea of how you might modify the function:

modifyOnUnloadFile: leafAction = (leaf) => {
  if (!isIntact(leaf.view)) return;
  const view = leaf.view;
  const mode = view.getViewState().mode;
  if (mode === 'source') {
    // Handle live edit mode
    // You might need to create a new function similar to onUnloadFile for live edit mode
  } else {
    // Existing code to handle preview mode
    const revert = around(leaf.view, {
      // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
      onUnloadFile(next) {
        return function (this: any, ...args) {
          const bridgeEl = view.previewMode.containerEl.querySelector(
            ".markdown-preview-section",
          ) as BridgeEl;
          const { infoList, singleton } = bridgeEl;
          if (infoList) {
            infoList.forEach((info) => info.popover?.tippy.destroy());
            infoList.clear();
          }
          if (singleton) {
            singleton.destroy();
            bridgeEl.singleton = null;
          }
        };
      },
    });
  }
};

I'm not sure how to go about implementing that bu maybe this will give someone a hint

Thank you for your suggestion, Im trying to add the plugin function in preview mode, and I will attach the improved plugin to this thread. btw, which copilot is this? It looks pretty smart.

@huachuman
Copy link

huachuman commented Jan 10, 2024

Nice, happy to hear that might be useful. I'm not sure what I used but given that it suggested which file to edit I'm guessing it was github copilot with the @workspace command, but it's hard to say, I've experimented with these kinds of tools a fair bit in the past few months. Wish I could remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants