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

feat: Added divider to work with * #118

Merged
merged 5 commits into from
Jun 7, 2023
Merged

feat: Added divider to work with * #118

merged 5 commits into from
Jun 7, 2023

Conversation

glunkad
Copy link
Contributor

@glunkad glunkad commented May 14, 2023

Description

Underline parser implementation to support markdown code format

Feature Preview

Partially Implemented divider to work with star .
Changes to decoder and encoder are yet to be made

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

PR Checklist

  • My code adheres to the AppFlowy Style Guide
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

@CLAassistant
Copy link

CLAassistant commented May 14, 2023

CLA assistant check
All committers have signed the CLA.

@LucasXu0
Copy link
Collaborator

LucasXu0 commented May 15, 2023

Hey, @glunkad. Why do you add divider to this repo? any related issue?

@glunkad
Copy link
Contributor Author

glunkad commented May 15, 2023

Hey, @glunkad. Why do you add divider to this repo? any related issue?

AppFlowy-IO/AppFlowy#2371

// ---
ShortcutEvent insertDividerEvent = ShortcutEvent(
key: 'Divider',
command: 'Minus,shift+digit 8',
Copy link
Collaborator

Choose a reason for hiding this comment

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

use character instead of the command.

@LucasXu0
Copy link
Collaborator

LucasXu0 commented May 15, 2023

Hey, @glunkad. Can you implement it in the mobile branch?

Here's the migration guide. #97 (comment)
Also, you can refer to the branch develop_new_editor in appflowy project.

@annieappflowy annieappflowy added new feature this is something new for the end user editor features related to the rich-text editor labels May 15, 2023
@glunkad
Copy link
Contributor Author

glunkad commented May 16, 2023

Hey, @glunkad. Can you implement it in the mobile branch?

Here's the migration guide. #97 (comment)
Also, you can refer to the branch develop_new_editor in appflowy project.

Absolutely! I'll be happy to implement it .

Comment on lines 24 to 27
Key? key,
required this.node,
required this.editorState,
}) : super(key: key);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Key? key,
required this.node,
required this.editorState,
}) : super(key: key);
super.key,
required this.node,
required this.editorState,
});

padding: const EdgeInsets.symmetric(vertical: 10),
child: Container(
height: 1,
color: Colors.grey,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not have a color for the divider in editor style? If not we should add one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need a if statement to check?

// ---
ShortcutEvent insertDividerEvent = ShortcutEvent(
key: 'Divider',
command: 'Minus,shift+digit 8',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
command: 'Minus,shift+digit 8',
character: '-',

@glunkad
Copy link
Contributor Author

glunkad commented May 18, 2023

Should I add multiple characters ie '_','*' in character ?

@Xazin
Copy link
Contributor

Xazin commented May 18, 2023

Should I add multiple characters ie '_','*' in character ?

No, not for now. It's not supported. I will make a PR this week for support for that.

@glunkad
Copy link
Contributor Author

glunkad commented May 20, 2023

Ok works.

@codecov
Copy link

codecov bot commented May 20, 2023

Codecov Report

Merging #118 (b61ced3) into main (25ac5b2) will decrease coverage by 0.16%.
The diff coverage is 50.40%.

@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
- Coverage   59.05%   58.89%   -0.16%     
==========================================
  Files         211      215       +4     
  Lines        9512     9624     +112     
==========================================
+ Hits         5617     5668      +51     
- Misses       3895     3956      +61     
Impacted Files Coverage Δ
...vider_block_component/divider_block_component.dart 6.81% <6.81%> (ø)
...ent/divider_block_component/divider_menu_item.dart 20.00% <20.00%> (ø)
lib/src/service/standard_block_components.dart 98.46% <80.00%> (-1.54%) ⬇️
.../render/selection_menu/selection_menu_service.dart 76.69% <80.76%> (-1.33%) ⬇️
...src/render/selection_menu/selection_menu_icon.dart 87.50% <87.50%> (ø)
...er_block_component/divider_character_shortcut.dart 100.00% <100.00%> (ø)

... and 18 files with indirect coverage changes

Comment on lines 13 to 41
ShortcutEventHandler _insertDividerHandler = (editorState, event) {
final selection = editorState.service.selectionService.currentSelection.value;
final textNodes = editorState.service.selectionService.currentSelectedNodes
.whereType<TextNode>();
if (textNodes.length != 1 || selection == null) {
return KeyEventResult.ignored;
}
final textNode = textNodes.first;
if (textNode.toPlainText() != '--') {
return KeyEventResult.ignored;
}
final transaction = editorState.transaction
..deleteText(textNode, 0, 2) // remove the existing minuses.
..insertNode(textNode.path, Node(type: kDividerType)) // insert the divder
..afterSelection = Selection.single(
// update selection to the next text node.
path: textNode.path.next,
startOffset: 0,
);
editorState.apply(transaction);
return KeyEventResult.handled;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I am thinking to allow this to be used for multiple different characters, we can change it like this:

Suggested change
ShortcutEventHandler _insertDividerHandler = (editorState, event) {
final selection = editorState.service.selectionService.currentSelection.value;
final textNodes = editorState.service.selectionService.currentSelectedNodes
.whereType<TextNode>();
if (textNodes.length != 1 || selection == null) {
return KeyEventResult.ignored;
}
final textNode = textNodes.first;
if (textNode.toPlainText() != '--') {
return KeyEventResult.ignored;
}
final transaction = editorState.transaction
..deleteText(textNode, 0, 2) // remove the existing minuses.
..insertNode(textNode.path, Node(type: kDividerType)) // insert the divder
..afterSelection = Selection.single(
// update selection to the next text node.
path: textNode.path.next,
startOffset: 0,
);
editorState.apply(transaction);
return KeyEventResult.handled;
};
ShortcutEventHandler _insertDividerHandler = (editorState, event) {
final character = event?.character;
if (character == null) {
return KeyEventResult.ignored;
}
final selection = editorState.service.selectionService.currentSelection.value;
final textNodes = editorState.service.selectionService.currentSelectedNodes
.whereType<TextNode>();
if (textNodes.length != 1 || selection == null) {
return KeyEventResult.ignored;
}
final textNode = textNodes.first;
if (textNode.toPlainText() != (character * 2)) {
return KeyEventResult.ignored;
}
final transaction = editorState.transaction
..deleteText(textNode, 0, 2) // remove the existing characters.
..insertNode(textNode.path, Node(type: kDividerType)) // insert the divider
..afterSelection = Selection.single( // update selection
path: textNode.path.next,
startOffset: 0,
);
editorState.apply(transaction);
return KeyEventResult.handled;
};

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 suggest we can add if block to check if character is '-','*','_' and only then insert the divider .

Copy link
Contributor

Choose a reason for hiding this comment

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

Why? The event handler will be hooked to a certain character, and so that will decide which is allowed.

Copy link
Contributor Author

@glunkad glunkad May 21, 2023

Choose a reason for hiding this comment

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

Okay.

@glunkad
Copy link
Contributor Author

glunkad commented May 22, 2023

Can I know to files that need to be updated ?

@LucasXu0 LucasXu0 merged commit eeae6fe into AppFlowy-IO:main Jun 7, 2023
@glunkad glunkad deleted the feat_markdown_divider_star branch June 13, 2023 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor features related to the rich-text editor new feature this is something new for the end user
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants