1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-27 10:32:58 +02:00

Desktop: Resolves #5184: GotoAnything sometimes is not working on first try

This commit is contained in:
Laurent Cozic 2021-08-05 14:40:54 +01:00
parent 69f0578ca9
commit 5b7a5de826

View File

@ -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<Props, State> {
}
// 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<Props, State> {
}
}
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<Props, State> {
const newId = this.state.results[index].id;
this.itemListRef.current.makeItemIndexVisible(index);
this.makeItemIndexVisible(index);
this.setState({ selectedItemId: newId });
}