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: Fixes #7834: Merged shorthand variants of spellcheck languages #9983

Merged
merged 9 commits into from
Feb 26, 2024

Conversation

HahaBill
Copy link
Contributor

@HahaBill HahaBill commented Feb 23, 2024

Summary

Introduction from the Joplin Forum: https://discourse.joplinapp.org/t/introducing-hahabill/36075/3

I fixed the issue regarding the multiple variants of the same spellcheck languages showing duplicate values in the title bar. Merged shorthand variants, e.g. [en-US, en-GB, en-AU] -> 'en'

  • added "spellCheckerMenu.test.ts" to test the changes and the expected behavior: all passed!
  • added jest.mock in "jest.setup.js" to mock the Menu from @electron/remote.
  • modified "buildScriptIndexes" to ignore ".test.ts" files so it does not include them in index.ts. That caused some issues with duplicate identifiers and more errors.

🐛 Fixes: #7834

Testing and Verification Process

1. To ensure the changes are working as expected:

Screen.Recording.2024-02-22.at.23.56.06.mov

2. Unit Testing: showSpellCheckerMenu.test.ts

Screenshot 2024-02-22 at 22 30 41

Notes

I noticed that when I add multiple spellchecker languages, the block expands to the point that it covers the notebook's title.

Screenshot 2024-02-23 at 0 20 16

This is out of the scope of this PR, but I would suggest maybe making the "spellchecker language" block in the title bar horizontally scrollable so that it does not cover the notebook title.

What do you think?
(this suggestion would be out of the scope of this PR, a new issue would be created)

Checklist:

  • Fixed the issue
  • Created test units
  • Complete and working PR

HahaBill and others added 2 commits February 22, 2024 23:52
…e bar

- Fixed the issue laurent22#7834

- added "spellCheckerMenu.test.ts" to test the changes and the expected behavior: all passed!

- added jest.mock in "jest.setup.js" to mock the Menu from @electron/remote.

-  modified "buildScriptIndexes" to ignore ".test.ts" files so it does not include them in index.ts. That caused some issues with duplicate identifiers and more errors.
Copy link
Contributor

github-actions bot commented Feb 23, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@HahaBill
Copy link
Contributor Author

recheck

@HahaBill HahaBill marked this pull request as ready for review February 23, 2024 00:46
@laurent22
Copy link
Owner

You need to accept the CLA.

@@ -30,8 +30,9 @@ export const runtime = (): CommandRuntime => {
const s: string[] = [];
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
languages.forEach((language: string) => {
s.push(language.split('-')[0]);
Copy link
Owner

Choose a reason for hiding this comment

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

Obviously it was previously implemented this way for a reason, and you removed that feature.

So what's your reasoning, why do you think it was implemented this way, and is the best fix really to remove it without even a discussion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I am sorry that I did not discuss my changes before. I saw in the docs that contributions should be first addressed and discussed in the GitHub issues or Joplin forum. In the future, I will be more aware of that and provide more explicit explanations.

Copy link
Contributor Author

@HahaBill HahaBill Feb 23, 2024

Choose a reason for hiding this comment

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

I added only s.push(language) and removed s.push(language.split('-')[0] because to explicitly display the spellcheck languages with different variants like "en-AU, en-GB, en-US" instead of "en, en, en". This is something that tomasz1986 wanted to see and I agree that from the UI/UX perspective, it is better this way.

The changes should not affect SpellCheckerService.ts and the state: AppState.

I might have missed something based on your review, let me know!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here are a few other options:

1. Only show the region code when it prevents duplicate values from being added to s

Another option might be to only include the region code when there are multiple copies of the same language.

For example,

  • languages = [ 'en-GB', 'en-US' ] => s = [ 'en-GB', 'en-US' ]
  • languages = [ 'en-GB', 'es-MX' ] => s = [ 'en', 'es' ].

2. Remove duplicates

For example,

  • languages = [ 'en', 'en', 'en' ] => s = [ 'en' ]

This is based on one of the list items in "describe what you expected to happen" in the original issue.

Copy link

@tomasz1986 tomasz1986 Feb 23, 2024

Choose a reason for hiding this comment

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

2. Remove duplicates

For example,

  • languages = [ 'en', 'en', 'en' ] => s = [ 'en' ]

This is based on one of the list items in "describe what you expected to happen" in the original issue.

As the author of the original issue, I actually like this approach a lot. It would allow for the language list to take less space, so that more title text could be displayed on the screen, which is precious especially on narrower displays.

Copy link
Owner

@laurent22 laurent22 Feb 23, 2024

Choose a reason for hiding this comment

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

I agree, the second solution is good in terms of usability and reduces clutter. @HahaBill, this is what I was trying to get at: first find out why something was done in a particular way. It was indeed to reduce clutter because putting the language as eg fr-FR or it-IT doesn't help the user.

So the idea would be to keep the clutter to a minimum while solving the original bug report. Actually both solutions 1 or 2 would work but indeed 2 seems better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me, the second solution also looks better than the first one, and everyone seems to lean towards that. The second solution it is! :)

(at sign)laurent22 I see now! That is a really good point and lesson learned. I will keep that in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the solution:

Screenshot 2024-02-23 at 22 41 55

@HahaBill
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@HahaBill
Copy link
Contributor Author

recheck

github-actions bot added a commit that referenced this pull request Feb 23, 2024
packages/lib/determineProfileDir.js Outdated Show resolved Hide resolved
@@ -30,8 +30,9 @@ export const runtime = (): CommandRuntime => {
const s: string[] = [];
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
languages.forEach((language: string) => {
s.push(language.split('-')[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here are a few other options:

1. Only show the region code when it prevents duplicate values from being added to s

Another option might be to only include the region code when there are multiple copies of the same language.

For example,

  • languages = [ 'en-GB', 'en-US' ] => s = [ 'en-GB', 'en-US' ]
  • languages = [ 'en-GB', 'es-MX' ] => s = [ 'en', 'es' ].

2. Remove duplicates

For example,

  • languages = [ 'en', 'en', 'en' ] => s = [ 'en' ]

This is based on one of the list items in "describe what you expected to happen" in the original issue.

@@ -12,7 +12,7 @@ async function processDirectory(dir, indexFilePath = null, typeScriptType = null

const tsFiles = glob.sync('{**/*.ts,**/*.tsx}', {
cwd: dir,
}).filter(f => `${dir}/${f}` !== indexFilePath);
}).filter(f => `${dir}/${f}` !== indexFilePath && !f.endsWith('.test.ts'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
}).filter(f => `${dir}/${f}` !== indexFilePath && !f.endsWith('.test.ts'));
}).filter(f => `${dir}/${f}` !== indexFilePath)
// Exclude Jest test files to prevent them from being imported
// by index.ts.
.filter(f => !f.endsWith('.test.ts'));

(Optional) A brief comment might be helpful here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will do that. Thanks for sharing your implementation!

@personalizedrefrigerator
Copy link
Collaborator

This is out of the scope of this PR, but I would suggest maybe making the "spellchecker language" block in the title bar horizontally scrollable so that it does not cover the notebook title.

Because it's possible to click on the spellcheck button and show the full list of languages, I think limiting its size and using text-overflow: ellipsis (or something similar in JS) might make sense. I agree that this would probably be best in a separate PR.

@tomasz1986
Copy link

tomasz1986 commented Feb 23, 2024

This is out of the scope of this PR, but I would suggest maybe making the "spellchecker language" block in the title bar horizontally scrollable so that it does not cover the notebook title.

Because it's possible to click on the spellcheck button and show the full list of languages, I think limiting its size and using text-overflow: ellipsis (or something similar in JS) might make sense. I agree that this would probably be best in a separate PR.

I think there is an issue with the spellcheck button, as it only shows one language enabled in the menu that pops up on click,

image

even though there are actually four languages enabled. You need to go through the whole "Change language" list to see all of them.

@HahaBill
Copy link
Contributor Author

HahaBill commented Feb 23, 2024

This is out of the scope of this PR, but I would suggest maybe making the "spellchecker language" block in the title bar horizontally scrollable so that it does not cover the notebook title.

Because it's possible to click on the spellcheck button and show the full list of languages, I think limiting its size and using text-overflow: ellipsis (or something similar in JS) might make sense. I agree that this would probably be best in a separate PR.

Yeah, limiting the size and using something like text overflow makes much more sense. Let's talk about that more after this PR and see if other members agree.

Another example of using 3 languages where it doesn't look nice:

Screenshot 2024-02-23 at 21 36 30

- Test case passed: ['en-GB', 'en-US', 'en-CA', 'es-ES', 'es-MX'] -> 'en, es'
@HahaBill HahaBill changed the title Desktop: Fixes #7834: Provided more specific shorthand variants of spellcheck languages, e.g. en-AU, en-GB, en-US, etc. Desktop: Fixes #7834: Merged shorthand variants of spellcheck languages Feb 23, 2024
@HahaBill
Copy link
Contributor Author

I made all the necessary changes. I hope I got everything.

@laurent22
Copy link
Owner

Notes

I noticed that when I add multiple spellchecker languages, the block expands to the point that it covers the notebook's title.
Screenshot 2024-02-23 at 0 20 16

This is out of the scope of this PR, but I would suggest maybe making the "spellchecker language" block in the title bar horizontally scrollable so that it does not cover the notebook title.

What do you think? (this suggestion would be out of the scope of this PR, a new issue would be created)

Would you mind creating a new issue for this? As a fix we'll just make the languages not wrap. We don't need to do anything smart because the UI is not really usable at a very small size anyway.

@HahaBill
Copy link
Contributor Author

Notes

I noticed that when I add multiple spellchecker languages, the block expands to the point that it covers the notebook's title.
Screenshot 2024-02-23 at 0 20 16
This is out of the scope of this PR, but I would suggest maybe making the "spellchecker language" block in the title bar horizontally scrollable so that it does not cover the notebook title.
What do you think? (this suggestion would be out of the scope of this PR, a new issue would be created)

Would you mind creating a new issue for this? As a fix we'll just make the languages not wrap. We don't need to do anything smart because the UI is not really usable at a very small size anyway.

Right, also, by removing duplicates, we have partially solved the issue. I think overflowing the text should suffice. I am happy to create a new issue for that!

@HahaBill
Copy link
Contributor Author

Notes

I noticed that when I add multiple spellchecker languages, the block expands to the point that it covers the notebook's title.
Screenshot 2024-02-23 at 0 20 16
This is out of the scope of this PR, but I would suggest maybe making the "spellchecker language" block in the title bar horizontally scrollable so that it does not cover the notebook title.
What do you think? (this suggestion would be out of the scope of this PR, a new issue would be created)

Would you mind creating a new issue for this? As a fix we'll just make the languages not wrap. We don't need to do anything smart because the UI is not really usable at a very small size anyway.

Right, also, by removing duplicates, we have partially solved the issue. I think overflowing the text should suffice. I am happy to create a new issue for that!

Here's the issue: #9998

@laurent22
Copy link
Owner

That looks good now, thanks everyone!

@laurent22 laurent22 merged commit 64684dc into laurent22:dev Feb 26, 2024
10 checks passed
@HahaBill
Copy link
Contributor Author

HahaBill commented Mar 1, 2024

@PackElend label me please

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.

Multiple variants of the same spellcheck languages in the title bar should be more specific (or merged)
5 participants