diff --git a/packages/app-desktop/plugins/GotoAnything.tsx b/packages/app-desktop/plugins/GotoAnything.tsx index 97ddb90b4..55aabd1cd 100644 --- a/packages/app-desktop/plugins/GotoAnything.tsx +++ b/packages/app-desktop/plugins/GotoAnything.tsx @@ -18,6 +18,9 @@ const { surroundKeywords, nextWhitespaceIndex, removeDiacritics } = require('@jo const { mergeOverlappingIntervals } = require('@joplin/lib/ArrayUtils.js'); import markupLanguageUtils from '../utils/markupLanguageUtils'; import focusEditorIfEditorCommand from '@joplin/lib/services/commands/focusEditorIfEditorCommand'; +import Logger from '../../lib/Logger'; + +const logger = Logger.create('GotoAnything'); const PLUGIN_NAME = 'gotoAnything'; @@ -381,7 +384,7 @@ class Dialog extends React.PureComponent { } // make list scroll to top in every search - this.itemListRef.current.makeItemIndexVisible(0); + this.makeItemIndexVisible(0); this.setState({ listType: listType, @@ -394,6 +397,17 @@ class Dialog extends React.PureComponent { } } + private makeItemIndexVisible(index: number) { + // Looks like it's not always defined + // https://github.com/laurent22/joplin/issues/5184#issuecomment-879714850 + if (!this.itemListRef || !this.itemListRef.current) { + logger.warn('Trying to set item index but the item list is not defined. Index: ', index); + return; + } + + this.itemListRef.current.makeItemIndexVisible(index); + } + async gotoItem(item: any) { this.props.dispatch({ pluginName: PLUGIN_NAME, @@ -517,7 +531,7 @@ class Dialog extends React.PureComponent { const newId = this.state.results[index].id; - this.itemListRef.current.makeItemIndexVisible(index); + this.makeItemIndexVisible(index); this.setState({ selectedItemId: newId }); }