fix(app): keep diff typography and colours native to the host
This commit is contained in:
@@ -113,7 +113,7 @@ class _FileRow extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mono = monospaceText(DefaultTextStyle.of(context).style);
|
||||
final mono = nativeDiffText(DefaultTextStyle.of(context).style);
|
||||
final cupertino = usesCupertino(context);
|
||||
final leading = Icon(_kindIcon(context, file.kind));
|
||||
final title = Text(file.path, style: mono);
|
||||
|
||||
@@ -6,12 +6,6 @@ import '../domain/unified_patch.dart';
|
||||
/// Which form of a recorded patch the viewer is showing.
|
||||
enum DiffForm { rendered, raw }
|
||||
|
||||
/// The bundled code face (`assets/fonts/RobotoMono.ttf`, SIL OFL 1.1). Flutter
|
||||
/// web cannot resolve a system monospace family, so the app carries one and
|
||||
/// every target renders patch text the same way. The fallbacks are only for
|
||||
/// hosts that cannot load the asset.
|
||||
const codeFontFamily = 'RobotoMono';
|
||||
|
||||
/// The app's established platform switch: Material for Android/desktop/web,
|
||||
/// Cupertino for iOS and macOS. Feature widgets stay portable across all three
|
||||
/// targets instead of hard-coding one control set.
|
||||
@@ -20,38 +14,29 @@ bool usesCupertino(BuildContext context) {
|
||||
return platform == TargetPlatform.iOS || platform == TargetPlatform.macOS;
|
||||
}
|
||||
|
||||
/// The app's code face for patch text. The size, weight and text scaler come
|
||||
/// from the caller's theme style, so code follows the operator's text size.
|
||||
TextStyle monospaceText(TextStyle base) => base.copyWith(
|
||||
fontFamily: codeFontFamily,
|
||||
fontFamilyFallback: const ['Menlo', 'Consolas', 'Courier New', 'monospace'],
|
||||
);
|
||||
/// Patch text inherits the host's typography, including its font and scaler.
|
||||
/// A diff is not an exception to the native-defaults requirement.
|
||||
TextStyle nativeDiffText(TextStyle base) => base;
|
||||
|
||||
/// The distinguishable success/removal colours shared by the stat line and the
|
||||
/// diff rows. A theme-aware green/red pair, never two shades of the same hue:
|
||||
/// the light Material containers alone made additions and removals read alike.
|
||||
/// Native semantic colours, never a bespoke diff palette. The recorded +/-
|
||||
/// markers carry meaning independently of colour. No background tint is added.
|
||||
({Color text, Color? background}) diffLineColors(
|
||||
BuildContext context,
|
||||
ChangeLineKind kind,
|
||||
) {
|
||||
final dark = usesCupertino(context)
|
||||
? CupertinoTheme.of(context).brightness == Brightness.dark
|
||||
: Theme.of(context).brightness == Brightness.dark;
|
||||
return switch (kind) {
|
||||
ChangeLineKind.add =>
|
||||
dark
|
||||
? (text: const Color(0xFF7FE0A8), background: const Color(0x297FE0A8))
|
||||
: (
|
||||
text: const Color(0xFF116B33),
|
||||
background: const Color(0xFFE3F3E7),
|
||||
),
|
||||
ChangeLineKind.remove =>
|
||||
dark
|
||||
? (text: const Color(0xFFFF9E9E), background: const Color(0x29FF9E9E))
|
||||
: (
|
||||
text: const Color(0xFFB3261E),
|
||||
background: const Color(0xFFFBE7E5),
|
||||
),
|
||||
ChangeLineKind.add => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.primary,
|
||||
background: null,
|
||||
),
|
||||
ChangeLineKind.remove => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.destructiveRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error,
|
||||
background: null,
|
||||
),
|
||||
ChangeLineKind.context => (text: labelColor(context), background: null),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
final file = widget.file;
|
||||
final cupertino = usesCupertino(context);
|
||||
final base = DefaultTextStyle.of(context).style;
|
||||
final mono = monospaceText(base);
|
||||
final mono = nativeDiffText(base);
|
||||
final stat = changeStat(file.added, file.removed);
|
||||
final tags = changeEntryTags(file);
|
||||
return ConstrainedBox(
|
||||
|
||||
@@ -17,7 +17,7 @@ class PatchView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final parsed = file.parsedPatch;
|
||||
final base = monospaceText(DefaultTextStyle.of(context).style);
|
||||
final base = nativeDiffText(DefaultTextStyle.of(context).style);
|
||||
final stat = changeStat(parsed.added, parsed.removed);
|
||||
return Semantics(
|
||||
container: true,
|
||||
@@ -106,7 +106,7 @@ class _HunkView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final base = monospaceText(DefaultTextStyle.of(context).style);
|
||||
final base = nativeDiffText(DefaultTextStyle.of(context).style);
|
||||
final width = gutterWidth(hunk);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
|
||||
Reference in New Issue
Block a user