improved Uri display formatting
This commit is contained in:
@@ -47,18 +47,11 @@ extension UriX on Uri {
|
||||
return '';
|
||||
}
|
||||
|
||||
final segments = pathSegments.join('/');
|
||||
final buffer = StringBuffer();
|
||||
|
||||
if (path.startsWith('/')) {
|
||||
buffer.write('/');
|
||||
try {
|
||||
return Uri.decodeComponent(path);
|
||||
} on FormatException {
|
||||
return path;
|
||||
}
|
||||
buffer.write(segments);
|
||||
if (path.length > 1 && path.endsWith('/')) {
|
||||
buffer.write('/');
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
String get displayString {
|
||||
@@ -94,6 +87,10 @@ extension UriStringX on String {
|
||||
if (uri == null || uri.toString() != this) {
|
||||
return this;
|
||||
}
|
||||
return uri.displayString;
|
||||
try {
|
||||
return uri.displayString;
|
||||
} on FormatException {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -21,6 +21,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/extensions/uri.dart';
|
||||
import 'package:weblibre/features/geckoview/features/contextmenu/domain/converters/hit_result_converter.dart';
|
||||
|
||||
extension HitResultJson on HitResult {
|
||||
@@ -82,14 +83,15 @@ extension HitResultX on HitResult {
|
||||
const maxTitleLength = 2500;
|
||||
|
||||
return switch (this) {
|
||||
UnknownHitResult(src: final src) => src,
|
||||
ImageSrcHitResult(uri: final uri) => uri,
|
||||
ImageHitResult(src: final src, title: final title) =>
|
||||
title.isEmpty ? (src.length > maxTitleLength ? 'image' : src) : title!,
|
||||
UnknownHitResult(src: final src) => src.uriDisplayString,
|
||||
ImageSrcHitResult(uri: final uri) => uri.uriDisplayString,
|
||||
ImageHitResult(src: final src, title: final title) => title.isEmpty
|
||||
? (src.length > maxTitleLength ? 'image' : src.uriDisplayString)
|
||||
: title!,
|
||||
VideoHitResult(src: final src, title: final title) =>
|
||||
(title.isEmpty) ? src : title!,
|
||||
(title.isEmpty) ? src.uriDisplayString : title!,
|
||||
AudioHitResult(src: final src, title: final title) =>
|
||||
(title.isEmpty) ? src : title!,
|
||||
(title.isEmpty) ? src.uriDisplayString : title!,
|
||||
_ => 'about:blank',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user