From a33a86bba9783a1a4759960daecbb54e3cde0c83 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Wed, 30 Oct 2024 14:40:16 +0100 Subject: [PATCH] Include matched prefix as part of the display options. --- pkg/web_app/lib/src/widget/completion/suggest.dart | 5 +++++ .../test/widget/completion/suggest_test.dart | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/web_app/lib/src/widget/completion/suggest.dart b/pkg/web_app/lib/src/widget/completion/suggest.dart index 254efdd9b8..232bd4aef9 100644 --- a/pkg/web_app/lib/src/widget/completion/suggest.dart +++ b/pkg/web_app/lib/src/widget/completion/suggest.dart @@ -109,10 +109,15 @@ class Suggestion { final suggestions = completion.options.map((option) { final overlap = _lcs(prefix, option); var html = option; + // highlight the overlapping part of the text if (overlap.isNotEmpty) { html = html.replaceAll( overlap, '$overlap'); } + // include matched prefix as part of the display option + if (completion.terminal) { + html = '$match$html'; + } final score = (option.startsWith(word) ? math.pow(overlap.length, 3) : 0) + math.pow(overlap.length, 2) + (option.startsWith(overlap) ? overlap.length : 0) + diff --git a/pkg/web_app/test/widget/completion/suggest_test.dart b/pkg/web_app/test/widget/completion/suggest_test.dart index af4d2fcb25..8edb4b7e91 100644 --- a/pkg/web_app/test/widget/completion/suggest_test.dart +++ b/pkg/web_app/test/widget/completion/suggest_test.dart @@ -68,14 +68,14 @@ void main() { 'start': 0, 'end': 5, 'value': 'is:flutter-favorite ', - 'html': 'flutter-favorite', + 'html': 'is:flutter-favorite', 'score': 4.125, }, { 'start': 0, 'end': 5, 'value': 'is:unlisted ', - 'html': 'unlisted', + 'html': 'is:unlisted', 'score': 1.125, }, { @@ -83,35 +83,35 @@ void main() { 'end': 5, 'value': 'is:dart3-compatible ', 'html': - 'dart3-compatible', + 'is:dart3-compatible', 'score': 1.0625, }, { 'start': 0, 'end': 5, 'value': 'is:legacy ', - 'html': 'legacy', + 'html': 'is:legacy', 'score': 0.0, }, { 'start': 0, 'end': 5, 'value': 'is:null-safe ', - 'html': 'null-safe', + 'html': 'is:null-safe', 'score': 0.0, }, { 'start': 0, 'end': 5, 'value': 'is:plugin ', - 'html': 'plugin', + 'html': 'is:plugin', 'score': 0.0 }, { 'start': 0, 'end': 5, 'value': 'is:wasm-ready ', - 'html': 'wasm-ready', + 'html': 'is:wasm-ready', 'score': 0.0, }, ]);