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

Desktop: fix #3170: always make the first item selected when typing in GotoAnything #3181

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

ylc395
Copy link
Contributor

@ylc395 ylc395 commented May 9, 2020

fix #3170. Whlie updating GotoAnything search input, the selectedItemIndex was reused between two updates, which caused that pressing Arrow Down key didn't select the second item. That made users confused. Fix this problem by ignoring the previous selectedItemIndex when updating GotoAnything search input.

@ylc395 ylc395 changed the title Desktop: bugfix #3170 Desktop: Bugfix #3170 May 9, 2020
@laurent22
Copy link
Owner

We need a description of what this pull request does. Also please give the issue a meaningful title, according to the template: https://github.com/laurent22/joplin/blob/master/.github/PULL_REQUEST_TEMPLATE

@ylc395 ylc395 changed the title Desktop: Bugfix #3170 Desktop: fix #3170: always make the first item selected when typing in GotoAnywhere May 11, 2020
@ylc395 ylc395 changed the title Desktop: fix #3170: always make the first item selected when typing in GotoAnywhere Desktop: fix #3170: always make the first item selected when typing in GotoAnything May 11, 2020
Comment on lines 371 to 373
if (this.state.results.length > 0 && (keyCode === 40 || keyCode === 38)) { // DOWN / UP
if ((keyCode === 40 || keyCode === 38) && this.state.results.length > 0) { // DOWN / UP
event.preventDefault();

const inc = keyCode === 38 ? -1 : +1;
let index = this.selectedItemIndex();
if (index < 0) return; // Not possible, but who knows

index += inc;
if (index < 0) index = 0;
if (index >= this.state.results.length) index = this.state.results.length - 1;

const newId = this.state.results[index].id;
index = Math.min(
index + (keyCode === 38 ? -1 : +1),
this.state.results.length - 1,
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, the new code does the same as the previous one, so please undo these changes. It makes it easier to review pull request if we limit to only the necessary changes.

Comment on lines 263 to 276
let selectedItemId = null;
const itemIndex = this.selectedItemIndex(results, this.state.selectedItemId);
if (itemIndex > 0) {
selectedItemId = this.state.selectedItemId;
} else if (results.length > 0) {
selectedItemId = results[0].id;
}

this.itemListRef.current.makeItemIndexVisible(0);
this.setState({
listType: listType,
results: results,
listType,
results,
resultsInBody,
selectedItemId: results.length === 0 ? null : results[0].id,
keywords: this.keywords(searchQuery),
selectedItemId: selectedItemId,
resultsInBody: resultsInBody,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel there's too many changes, and some of them aren't necessary. I feel the previous logic also made more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've converted some changes.

selectedItemId = this.state.selectedItemId;
} else if (results.length > 0) {
selectedItemId = results[0].id;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to keep selectedItemId

@ylc395 ylc395 requested a review from laurent22 May 17, 2020 06:53
@laurent22
Copy link
Owner

Thanks for the update, but I don't know what bug is being fixed as I can't replicate it. Could you provide step by step instructions on how to replicate it? Also I think the selected item should be preserved between updates - see for example how it works in Sublime Text.

@ylc395
Copy link
Contributor Author

ylc395 commented May 25, 2020

@laurent22

target

key sequence: test

Look at scroll bar, after typing "test", I press down arrow, and it jumps to an un-excepted position(I think most users except the second item to be selected after typing down arrow), where is keeped since I typed "t".

BTW: I hope you can give me some advice on #3180. I've added some tests. Anything else to be done?

@laurent22
Copy link
Owner

Ok that looks good too then, so let's merge. Thanks @ylc395!

@laurent22 laurent22 merged commit dd34b15 into laurent22:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Goto Anything: Keyboard selection starts at bottom of visible results
2 participants