From 854148d67b19683c7796e122f9fae695fb63e5b1 Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Tue, 7 Jan 2025 07:44:38 +0800 Subject: [PATCH 1/3] Feat: Enhance autocomplete, support case-insensitive --- example/pubspec.lock | 20 ++++++-------------- lib/src/code_autocomplete.dart | 22 ++++++++++++++++++---- pubspec.yaml | 5 ++++- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index e943eb8..07a2e6c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -66,18 +66,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.15.0" path: dependency: transitive description: @@ -92,7 +92,7 @@ packages: path: ".." relative: true source: path - version: "0.4.0" + version: "0.6.0" re_highlight: dependency: "direct main" description: @@ -122,14 +122,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: - dependency: transitive - description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 - url: "https://pub.dev" - source: hosted - version: "0.3.0" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" + dart: ">=3.3.0-0 <4.0.0" flutter: ">=1.17.0" diff --git a/lib/src/code_autocomplete.dart b/lib/src/code_autocomplete.dart index 4e924c6..a496faa 100644 --- a/lib/src/code_autocomplete.dart +++ b/lib/src/code_autocomplete.dart @@ -6,8 +6,17 @@ part of re_editor; abstract class CodePrompt { const CodePrompt({ - required this.word + required this.word, + this.caseSensitive = true, }); + + /// Whether the prompt is case sensitive. + /// + /// e.g. + /// - when false, user input is 'str', the prompt word 'String' will be displayed to user. + /// - when true, user input is 'str', the prompt word 'String' will not be displayed to user. + /// default to true + final bool caseSensitive; /// Content associated with user input. /// @@ -29,7 +38,8 @@ abstract class CodePrompt { class CodeKeywordPrompt extends CodePrompt { const CodeKeywordPrompt({ - required super.word + required super.word, + super.caseSensitive = true, }); @override @@ -37,7 +47,10 @@ class CodeKeywordPrompt extends CodePrompt { @override bool match(String input) { - return word != input && word.startsWith(input); + return word != input && + (caseSensitive + ? word.startsWith(input) + : word.toLowerCase().startsWith(input.toLowerCase())); } @override @@ -201,7 +214,8 @@ class CodeAutocompleteEditingValue { } CodeAutocompleteResult get autocomplete { - final CodeAutocompleteResult result = prompts[index].autocomplete; + final selectedPrompt = prompts[index]; + final CodeAutocompleteResult result = selectedPrompt.autocomplete; if (result.word.isEmpty) { return result; } diff --git a/pubspec.yaml b/pubspec.yaml index 422bd91..071d0fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,10 @@ environment: dependencies: flutter: sdk: flutter - re_highlight: ^0.0.3 + re_highlight: + git: + url: https://github.com/CorvusYe/antlr-highlight + ref: a64b1162a5765f184a12d4bbb004137b7be50fe4 isolate_manager: ^4.1.5+1 dev_dependencies: From c741f0c73d871c0057240a394bd96b29a2b96033 Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Tue, 7 Jan 2025 09:58:32 +0800 Subject: [PATCH 2/3] Feat: Enhance autocomplete, support case-insensitive --- lib/src/code_autocomplete.dart | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/src/code_autocomplete.dart b/lib/src/code_autocomplete.dart index a496faa..ce963af 100644 --- a/lib/src/code_autocomplete.dart +++ b/lib/src/code_autocomplete.dart @@ -30,7 +30,12 @@ abstract class CodePrompt { CodeAutocompleteResult get autocomplete; /// Check whether the input meets this prompt condition. - bool match(String input); + bool match(String input) { + return word != input && + (caseSensitive + ? word.startsWith(input) + : word.toLowerCase().startsWith(input.toLowerCase())); + } } @@ -45,14 +50,6 @@ class CodeKeywordPrompt extends CodePrompt { @override CodeAutocompleteResult get autocomplete => CodeAutocompleteResult.fromWord(word); - @override - bool match(String input) { - return word != input && - (caseSensitive - ? word.startsWith(input) - : word.toLowerCase().startsWith(input.toLowerCase())); - } - @override bool operator ==(Object other) { if (identical(this, other)) { @@ -75,6 +72,7 @@ class CodeFieldPrompt extends CodePrompt { const CodeFieldPrompt({ required super.word, required this.type, + super.caseSensitive = true, this.customAutocomplete, }); @@ -87,11 +85,6 @@ class CodeFieldPrompt extends CodePrompt { @override CodeAutocompleteResult get autocomplete => customAutocomplete ?? CodeAutocompleteResult.fromWord(word); - @override - bool match(String input) { - return word != input && word.startsWith(input); - } - @override bool operator ==(Object other) { if (identical(this, other)) { @@ -111,6 +104,7 @@ class CodeFunctionPrompt extends CodePrompt { const CodeFunctionPrompt({ required super.word, + super.caseSensitive = true, required this.type, this.parameters = const {}, this.optionalParameters = const {}, @@ -132,11 +126,6 @@ class CodeFunctionPrompt extends CodePrompt { @override CodeAutocompleteResult get autocomplete => customAutocomplete ?? CodeAutocompleteResult.fromWord('$word(${parameters.keys.join(', ')})'); - @override - bool match(String input) { - return word != input && word.startsWith(input); - } - @override bool operator ==(Object other) { if (identical(this, other)) { From 1fe0c30fd2534deb39a35e2ce2a0f2e0a7ba2cf3 Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Tue, 7 Jan 2025 10:14:37 +0800 Subject: [PATCH 3/3] ignore: rollback modifications to re_highlight dependency --- pubspec.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 071d0fb..422bd91 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,10 +10,7 @@ environment: dependencies: flutter: sdk: flutter - re_highlight: - git: - url: https://github.com/CorvusYe/antlr-highlight - ref: a64b1162a5765f184a12d4bbb004137b7be50fe4 + re_highlight: ^0.0.3 isolate_manager: ^4.1.5+1 dev_dependencies: