1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Desktop: Fixes #2157: Prevent app from crashing when pressing focus shortcut from search bar

This commit is contained in:
Laurent Cozic 2019-12-18 11:16:13 +00:00
parent 797b71d903
commit c534305c7b

View File

@ -221,6 +221,10 @@ class SideBarComponent extends React.Component {
if (item) { if (item) {
const anchorRef = this.anchorItemRefs[item.type][item.id]; const anchorRef = this.anchorItemRefs[item.type][item.id];
if (anchorRef) anchorRef.current.focus(); if (anchorRef) anchorRef.current.focus();
} else {
const anchorRef = this.firstAnchorItemRef('folder');
console.info('anchorRef', anchorRef);
if (anchorRef) anchorRef.current.focus();
} }
} }
} else if (command.name === 'synchronize') { } else if (command.name === 'synchronize') {
@ -417,13 +421,6 @@ class SideBarComponent extends React.Component {
}); });
} }
// searchItem_click(search) {
// this.props.dispatch({
// type: "SEARCH_SELECT",
// id: search ? search.id : null,
// });
// }
async sync_click() { async sync_click() {
await shared.synchronize_press(this); await shared.synchronize_press(this);
} }
@ -435,6 +432,18 @@ class SideBarComponent extends React.Component {
return this.anchorItemRefs[type][id]; return this.anchorItemRefs[type][id];
} }
firstAnchorItemRef(type) {
const refs = this.anchorItemRefs[type];
if (!refs) return null;
const n = `${type}s`;
const item = this.props[n] && this.props[n].length ? this.props[n][0] : null;
console.info('props', this.props[n], item);
if (!item) return null;
return refs[item.id];
}
noteCountElement(count) { noteCountElement(count) {
return <div style={this.style().noteCount}>({count})</div>; return <div style={this.style().noteCount}>({count})</div>;
} }
@ -590,8 +599,6 @@ class SideBarComponent extends React.Component {
return { type: 'folder', id: this.props.selectedFolderId }; return { type: 'folder', id: this.props.selectedFolderId };
} else if (this.props.notesParentType === 'Tag' && this.props.selectedTagId) { } else if (this.props.notesParentType === 'Tag' && this.props.selectedTagId) {
return { type: 'tag', id: this.props.selectedTagId }; return { type: 'tag', id: this.props.selectedTagId };
} else if (this.props.notesParentType === 'Search' && this.props.selectedSearchId) {
return { type: 'search', id: this.props.selectedSearchId };
} }
return null; return null;