fix(PostIt): disable links without a reader context
Prevent the Markdown viewer's default browser handler from activating when the blog reader has no view model, while keeping reader links bound to PostIt after context changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
dc4412b9e8
commit
b90f15333d
6 changed files with 21 additions and 17 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -20,16 +20,6 @@
|
||||||
|
|
||||||
* L'administration est maintenant restreinte aux emails configurés dans les paramétres applicatifs de Yavsc.Org (`appsettings-org.json`)
|
* L'administration est maintenant restreinte aux emails configurés dans les paramétres applicatifs de Yavsc.Org (`appsettings-org.json`)
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
* [PostIt] Correction du rendu des images incorporées dans les billets :
|
|
||||||
le résolveur fournit désormais un flux mémoire repositionnable, à son
|
|
||||||
début, pour éviter l'échec du décodage des images issues d'un flux HTTP.
|
|
||||||
* [PostIt] Suppression des erreurs de binding au démarrage du lecteur
|
|
||||||
lorsqu'aucun billet n'est sélectionné ; la commande des liens est
|
|
||||||
raccordée lors du changement de contexte. Les échecs HTTP des images
|
|
||||||
sont désormais journalisés avec leur URL dans la catégorie `BlogImages`.
|
|
||||||
|
|
||||||
## [1.0.8-rc25] - unstable
|
## [1.0.8-rc25] - unstable
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
BIN
contrib/blog-edit.png
Normal file
BIN
contrib/blog-edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
BIN
contrib/blog-view.png
Normal file
BIN
contrib/blog-view.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
|
|
@ -130,7 +130,8 @@ public class BlogReaderTests
|
||||||
var page = new BlogsPage();
|
var page = new BlogsPage();
|
||||||
var reader = page.FindControl<MarkdownScrollViewer>("ArticleReader")!;
|
var reader = page.FindControl<MarkdownScrollViewer>("ArticleReader")!;
|
||||||
var engine = Assert.IsAssignableFrom<IMarkdownEngine2>(reader.Engine);
|
var engine = Assert.IsAssignableFrom<IMarkdownEngine2>(reader.Engine);
|
||||||
Assert.Null(engine.HyperlinkCommand);
|
Assert.NotNull(engine.HyperlinkCommand);
|
||||||
|
Assert.False(engine.HyperlinkCommand.CanExecute("https://example.test/"));
|
||||||
page.DataContext = vm;
|
page.DataContext = vm;
|
||||||
var nav = new NavigationPage();
|
var nav = new NavigationPage();
|
||||||
await nav.PushAsync(page);
|
await nav.PushAsync(page);
|
||||||
|
|
@ -152,7 +153,8 @@ public class BlogReaderTests
|
||||||
Dispatcher.UIThread.RunJobs();
|
Dispatcher.UIThread.RunJobs();
|
||||||
Assert.Empty(vm.ReaderTitle);
|
Assert.Empty(vm.ReaderTitle);
|
||||||
Assert.Null(vm.ReaderDateModified);
|
Assert.Null(vm.ReaderDateModified);
|
||||||
Assert.Null(engine.HyperlinkCommand);
|
Assert.NotNull(engine.HyperlinkCommand);
|
||||||
|
Assert.False(engine.HyperlinkCommand.CanExecute("https://example.test/"));
|
||||||
Assert.DoesNotContain(sink.Entries, entry => entry.Area == LogArea.Binding);
|
Assert.DoesNotContain(sink.Entries, entry => entry.Area == LogArea.Binding);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,32 @@ using Avalonia.Controls;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Markdown.Avalonia;
|
using Markdown.Avalonia;
|
||||||
|
|
||||||
namespace PostIt.Views.Blogs;
|
namespace PostIt.Views.Blogs;
|
||||||
|
|
||||||
public partial class BlogsPage : ContentPage
|
public partial class BlogsPage : ContentPage
|
||||||
{
|
{
|
||||||
|
private static readonly RelayCommand<string?> DisabledLinkCommand =
|
||||||
|
new(static _ => { }, static _ => false);
|
||||||
|
|
||||||
public BlogsPage()
|
public BlogsPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContextChanged += (_, _) =>
|
DataContextChanged += (_, _) => UpdateHyperlinkCommand();
|
||||||
|
UpdateHyperlinkCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateHyperlinkCommand()
|
||||||
|
{
|
||||||
|
if (ArticleReader.Engine is IMarkdownEngine2 engine)
|
||||||
{
|
{
|
||||||
if (ArticleReader.Engine is IMarkdownEngine2 engine)
|
if (DataContext is ViewModels.BlogsViewModel vm)
|
||||||
engine.HyperlinkCommand = (DataContext as ViewModels.BlogsViewModel)?.OpenResourceCommand;
|
engine.HyperlinkCommand = vm.OpenResourceCommand;
|
||||||
};
|
else
|
||||||
|
engine.HyperlinkCommand = DisabledLinkCommand;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override async void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue