mrjackphil / obsidian-text-expand

A simple text expand plugin for Obsidian.md
186 stars 12 forks source link

Results Not Rendered. Error: Cannot Read Properties of Undefined (reading 'view') #83

Open AdamLenda-Relativity opened 1 year ago

AdamLenda-Relativity commented 1 year ago

Context

I've been very happy with Text Expand until recently. In the last weeks the plugin began erroring out while trying to render search results.

I know I'm using the same view template I've used for months, because my obsidian "daily note template" includes the same text expand query and template. Notes generated from this template several months ago are just as affected as the note generated today.

The error message reported by the developer console is:

image

Using the query shown here:

image

While the example New Note for 2023-04-14 shows up in the search results to the left, it is not included in the expander output.

image

AdamLenda-Relativity commented 1 year ago

Debugging this on my own...

image

Evaluating this line in the console yields and empty array: image

AdamLenda commented 1 year ago

Okay, the problem is that the view is displaying more than one child in the left split.

I've tested and validated this as a solution by editing the local copy of main.js.


    getLeftSplitElementOfViewStateType(viewStateType) {
        // @ts-ignore
        for (const child of this.app.workspace.leftSplit.children) {
            const filterForSearchResult = child.children.filter(e => e.getViewState().type === viewStateType);
            if (filterForSearchResult === undefined || filterForSearchResult.length < 1) {
                continue;
            }

            return filterForSearchResult[0];
        }
        return undefined;
    }

    getSearchView() {
        const searchElement = this.getLeftSplitElementOfViewStateType('search');
        if (undefined == searchElement) {
            return undefined;
        }

        const view = searchElement.view;
        if ('searchComponent' in view) {
            return view;
        }
        return undefined;
    }

I've used my very limited TS skills to converted the above into TS, and created PR #84 to resolve this issue.