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

Inline field with list only displays last entry in Live Preview mode #2281

Open
rben01 opened this issue Mar 26, 2024 · 4 comments
Open

Inline field with list only displays last entry in Live Preview mode #2281

rben01 opened this issue Mar 26, 2024 · 4 comments
Labels
bug Something isn't working.

Comments

@rben01
Copy link
Contributor

rben01 commented Mar 26, 2024

What happened?

In Live Preview, when using an inline field of the form [property:: "value1", "value2"], only value2 (or whatever the last value in the list is) is shown. In the other two modes (Source and Reading) the inline field appears as expected. This occurs in the sandbox vault where Dataview is the only plugin installed.

Source mode

38E52108-0D94-4C05-B1C9-DA91E2A19BAE

Live Preview mode

24BD2B89-AE50-46BB-AACA-0E30EDE348BE

Reading mode

F60B1789-5CB7-4B33-B33D-8C9023CE0382

DQL

[property:: 1, 2]
[property:: "x", "y"]

JS

N/A

Dataview Version

0.5.66

Obsidian Version

Version 1.5.11

OS

MacOS

@rben01 rben01 added the bug Something isn't working. label Mar 26, 2024
@holroy
Copy link
Contributor

holroy commented Mar 26, 2024

I reckon, without knowing, this could be a side effect of the bug described in #2216. I've seen it before.

The current workaround if I remember it correctly is to split the value setting into two, i.e. [prop:: 1] [prop:: 2]] It might not look nice, but in terms of setting the value to a list value it should work.

@holroy
Copy link
Contributor

holroy commented Mar 26, 2024

Sorry for adding to the confusion, but I just saw that this happens only in live preview, and the other one is happening in reading mode. So they might not be connected after all, but then again the changes in the other variant does something strange...

@rben01
Copy link
Contributor Author

rben01 commented Mar 26, 2024

Looking at the source code,

container.replaceChildren(...paragraph.childNodes);
seems like it just replaces the rendered span with each element of the list, so only the last one wins.

Passing the context through in

export async function renderCompactMarkdown(
and then checking whether it's "list" in
if (tmpContainer.childNodes.length == 1 && paragraph) {
(where? not sure), and if it is, then appending children instead of replacing. (Or maybe just always appending? Not sure what replacing does that appending wouldn't do — what are the initial children of the node in question?)

Anyway, making these changes, to get the following code,

async function renderCompactMarkdownForInlineFieldLivePreview(
    app: App,
    markdown: string,
    container: HTMLElement,
    sourcePath: string,
    component: Component,
    context: ValueRenderContext
) {
    const tmpContainer = createSpan();
    await MarkdownRenderer.render(app, markdown, tmpContainer, sourcePath, component);

    let paragraph = tmpContainer.querySelector(":scope > p");

    if (tmpContainer.childNodes.length == 1 && paragraph) {
        if (context !== "list") {
            container.replaceChildren(...paragraph.childNodes);
        } else {
            for (let child of paragraph.childNodes) {
                container.appendChild(child);
            }
        }
    } else {
        container.replaceChildren(...tmpContainer.childNodes);
    }

    tmpContainer.remove();
}

I get the following output in live preview:

image

I'm wary of submitting a PR because I really have no idea how this plugin works; I just followed the trail of the console.logs I added and ended up here.

@kazerniel
Copy link

kazerniel commented Apr 15, 2024

Thank you for opening this issue, I encountered the same problem (on Windows).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants