-
Notifications
You must be signed in to change notification settings - Fork 212
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
Conversation
Hey, @glunkad. Why do you add divider to this repo? any related issue? |
|
// --- | ||
ShortcutEvent insertDividerEvent = ShortcutEvent( | ||
key: 'Divider', | ||
command: 'Minus,shift+digit 8', |
There was a problem hiding this comment.
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.
Hey, @glunkad. Can you implement it in the Here's the migration guide. #97 (comment) |
Absolutely! I'll be happy to implement it . |
Key? key, | ||
required this.node, | ||
required this.editorState, | ||
}) : super(key: key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
command: 'Minus,shift+digit 8', | |
character: '-', |
Should I add multiple characters ie |
No, not for now. It's not supported. I will make a PR this week for support for that. |
Ok works. |
Codecov Report
@@ 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
|
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; | ||
}; |
There was a problem hiding this comment.
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:
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; | |
}; |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
Can I know to files that need to be updated ? |
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
Checklist:
PR Checklist