-
Notifications
You must be signed in to change notification settings - Fork 88
Issue192 paired symbols, issue199 yaml support #231
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
Open
Malarg
wants to merge
12
commits into
main
Choose a base branch
from
issue192_paired_symbols
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f927042
issue 192 paired symbols code modifier
Malarg 4293fc0
yaml folding added
Malarg d8521ae
issue192 tests done
Malarg 0e561b4
fixed tests
Malarg b82fe42
formatting fixed
Malarg 24cc670
issue192 paired symbols -> insertion
Malarg ef71caf
merge from main
Malarg 27e6156
issue 192 created default code modifier
Malarg 4756920
insertion constructor replaced with static const variables
Malarg da174e2
fixed autocompleter error for iOS
Malarg 523b72c
tests fix
Malarg 962aae2
commend added
Malarg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import 'package:flutter/services.dart'; | ||
|
|
||
| import '../code_field/editor_params.dart'; | ||
| import 'code_modifier.dart'; | ||
|
|
||
| class InsertionCodeModifier extends CodeModifier { | ||
| final String openChar; | ||
| final String closeString; | ||
|
|
||
| const InsertionCodeModifier({ | ||
| required this.openChar, | ||
| required this.closeString, | ||
| }) : super(openChar); | ||
|
|
||
| const InsertionCodeModifier.backticks() | ||
| : this(openChar: '`', closeString: '`'); | ||
|
|
||
| const InsertionCodeModifier.braces() : this(openChar: '{', closeString: '}'); | ||
|
|
||
| const InsertionCodeModifier.brackets() | ||
| : this(openChar: '[', closeString: ']'); | ||
|
|
||
| const InsertionCodeModifier.doubleQuotes() | ||
| : this(openChar: '"', closeString: '"'); | ||
|
|
||
| const InsertionCodeModifier.parentheses() | ||
| : this(openChar: '(', closeString: ')'); | ||
|
|
||
| const InsertionCodeModifier.singleQuotes() | ||
| : this(openChar: '\'', closeString: '\''); | ||
|
|
||
| @override | ||
| TextEditingValue? updateString( | ||
| String text, | ||
| TextSelection sel, | ||
| EditorParams params, | ||
| ) { | ||
| final replaced = replace(text, sel.start, sel.end, '$openChar$closeString'); | ||
|
|
||
| return replaced.copyWith( | ||
| selection: TextSelection( | ||
| baseOffset: replaced.selection.baseOffset - closeString.length, | ||
| extentOffset: replaced.selection.extentOffset - closeString.length, | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need two tests:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_code_editor/flutter_code_editor.dart'; | ||
| import 'package:flutter_code_editor/src/code_modifiers/insertion.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void main() { | ||
| test('Insertion modifier test', () { | ||
| const examples = [ | ||
| // | ||
| _Example( | ||
| 'Add close char at the start of the string', | ||
| initialValue: TextEditingValue( | ||
| text: 'dict', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 0), | ||
| ), | ||
| expected: TextEditingValue( | ||
| text: '{}dict', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 1), | ||
| ), | ||
| inputChar: '{', | ||
| ), | ||
|
|
||
| _Example( | ||
| 'Add close char in the middle of the string', | ||
| initialValue: TextEditingValue( | ||
| text: 'print', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 3), | ||
| ), | ||
| expected: TextEditingValue( | ||
| text: 'pri()nt', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 4), | ||
| ), | ||
| inputChar: '(', | ||
| ), | ||
|
|
||
| _Example( | ||
| 'Add close char at the end of the string', | ||
| initialValue: TextEditingValue( | ||
| text: 'print', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 5), | ||
| ), | ||
| expected: TextEditingValue( | ||
| text: 'print[]', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 6), | ||
| ), | ||
| inputChar: '[', | ||
| ), | ||
|
|
||
| _Example( | ||
| 'Add close with several close chars', | ||
| initialValue: TextEditingValue( | ||
| text: 'string', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 6), | ||
| ), | ||
| expected: TextEditingValue( | ||
| text: 'string123', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 7), | ||
| ), | ||
| inputChar: '1', | ||
| insertedString: '23', | ||
| ), | ||
|
|
||
| _Example( | ||
| 'Add close char before same close char', | ||
| initialValue: TextEditingValue( | ||
| text: 'string)', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 6), | ||
| ), | ||
| expected: TextEditingValue( | ||
| text: 'string())', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 7), | ||
| ), | ||
| inputChar: '(', | ||
| ), | ||
|
|
||
| _Example( | ||
| 'Empty initial string', | ||
| initialValue: TextEditingValue( | ||
| // ignore: avoid_redundant_argument_values | ||
| text: '', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 0), | ||
| ), | ||
| expected: TextEditingValue( | ||
| text: '()', | ||
| // \ cursor | ||
| selection: TextSelection.collapsed(offset: 1), | ||
| ), | ||
| inputChar: '(', | ||
| ), | ||
| ]; | ||
|
|
||
| for (final example in examples) { | ||
| final additionalModifier = example.insertedString != null | ||
| ? InsertionCodeModifier( | ||
| openChar: example.inputChar, | ||
| closeString: example.insertedString!, | ||
| ) | ||
| : null; | ||
|
|
||
| if (additionalModifier != null && | ||
| CodeController.defaultCodeModifiers.any( | ||
| (e) => | ||
| e is InsertionCodeModifier && e.openChar == example.inputChar, | ||
| )) { | ||
| fail('Modifier for ${example.inputChar} already exists'); | ||
| } | ||
|
|
||
| late CodeController controller; | ||
|
|
||
| if (additionalModifier == null) { | ||
| controller = CodeController(); | ||
| } else { | ||
| controller = CodeController( | ||
| modifiers: CodeController.defaultCodeModifiers + [additionalModifier], | ||
| ); | ||
| } | ||
|
|
||
| controller.value = example.initialValue; | ||
|
|
||
| controller.value = _addCharToSelectedPosition( | ||
| controller.value, | ||
| example.inputChar, | ||
| ); | ||
|
|
||
| expect( | ||
| controller.value, | ||
| example.expected, | ||
| reason: example.name, | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| TextEditingValue _addCharToSelectedPosition( | ||
| TextEditingValue value, | ||
| String char, | ||
| ) { | ||
| final selection = value.selection; | ||
| final text = value.text; | ||
|
|
||
| final newText = text.substring(0, selection.start) + | ||
| char + | ||
| text.substring(selection.start); | ||
|
|
||
| return TextEditingValue( | ||
| text: newText, | ||
| selection: TextSelection.collapsed( | ||
| offset: selection.start + char.length, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| class _Example { | ||
| final String name; | ||
| final TextEditingValue initialValue; | ||
| final TextEditingValue expected; | ||
| final String inputChar; | ||
| final String? insertedString; | ||
|
|
||
| const _Example( | ||
| this.name, { | ||
| required this.initialValue, | ||
| required this.expected, | ||
| required this.inputChar, | ||
| this.insertedString, | ||
| }); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.