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: Resolves #4813 : skip empty lines while converting selection to list #4832

Merged
merged 7 commits into from
May 4, 2021

Conversation

adarsh-sgh
Copy link
Contributor

@adarsh-sgh adarsh-sgh commented Apr 12, 2021

Before
before
After Fix
fixed
Steps:

  1. Copy paste following content to joplin
    item1
    item2
    item3
    a paragraph

  2. Take cursor to beggining of document and press shift+down arrow thrice to select 1st 3 lines.

  3. Toggle list using editor toolbar.

@@ -89,6 +89,7 @@ export default function useCursorUtils(CodeMirror: any) {

for (let j = 0; j < lines.length; j++) {
const line = lines[j];
if (!line) continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it should be break instead?
What'd happen if you select the text below and convert it to a list?

list
list


not list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What'd happen if you select the text below and convert it to a list?

After the fix:

Case 1: Only 1st and 2nd lines are selected

Both 1st and 2nd lines will be converted to list;

Case 2: All four lines are selected

"All except third (empty)" line will be converted to list.

Before fix : in case 2 above; all 4 lines will be converted to list

Copy link
Contributor Author

@adarsh-sgh adarsh-sgh Apr 12, 2021

Choose a reason for hiding this comment

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

Maybe it should be break instead?

I'm not sure; It depends on what is the expected behaviour for the case you described?
should I change it to break ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just checked the behaviour of google docs and microsoft word. It looks like Word behaves with the continue behaviour. Google docs just adds a bullet to every line.

I have no personal preference, but someone else might. It could probably be worth putting this to a poll on the forum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LInk to the poll on joplin forum.

@adarsh-sgh adarsh-sgh changed the title Desktop: Resolves #4813: skip empty lines while converting selection to list Desktop: Resolves #4813 : skip empty lines while converting selection to list Apr 12, 2021
@laurent22
Copy link
Owner

By the way, from the look of it there's again an opportunity to add tests here. As I understand a good part of the function simply processes some strings so that could be extracted to a function and properly unit tested. Maybe with a bit of extra effort it's even possible to setup tests for the whole hook.

@tessus tessus added the desktop All desktop platforms label Apr 21, 2021
@adarsh-sgh
Copy link
Contributor Author

adarsh-sgh commented Apr 22, 2021

I've added the tests and some modifications are done in the file to be tested to implement tests.

I manually tested inserting and removing lists to ensure that i did not broke anything while trying to test it.

one additional test will be added when result of this poll is finalised.

@laurent22
Copy link
Owner

For the list behaviour, it seems the most common across editors is this one:

image

So could you implement it that way please?

@adarsh-sgh
Copy link
Contributor Author

adarsh-sgh commented Apr 27, 2021

ollist-2021-04-27_16 26 59

I have made changes to get the behaviour as asked by laurent sir in the above message.
The code used to achive this behaviour is written in a way so as to allow easy switching to other behaviours in consideration (if we decide to do so in future).

@@ -1,6 +1,24 @@
import markdownUtils from '@joplin/lib/markdownUtils';
import Setting from '@joplin/lib/models/Setting';

export function modifyListLines(lines: string[],num: number,string1: string) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please could you give a descriptive name to "string1"?

export function modifyListLines(lines: string[],num: number,string1: string) {
for (let j = 0; j < lines.length; j++) {
const line = lines[j];
if (!line && j == lines.length - 1) continue;
Copy link
Owner

Choose a reason for hiding this comment

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

strict equality ===

@@ -1,20 +1,21 @@
import markdownUtils from '@joplin/lib/markdownUtils';
import Setting from '@joplin/lib/models/Setting';
export function modifyListLines(lines: string[],num: number,string1: string) {
export function modifyListLines(lines: string[],num: number,listSymbol: string) {
console.log(listSymbol,':string');
Copy link
Owner

Choose a reason for hiding this comment

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

Console

@laurent22 laurent22 merged commit b1ecb75 into laurent22:dev May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop All desktop platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants