mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-19 16:33:36 +03:00
Improve diff display for edited messages
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
63484ac353
commit
4595638cdb
2 changed files with 10 additions and 6 deletions
|
@ -1,6 +1,5 @@
|
|||
using Boyfriend.Data;
|
||||
using Boyfriend.Services.Data;
|
||||
using DiffPlex;
|
||||
using DiffPlex.DiffBuilder;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||
|
@ -189,7 +188,7 @@ public class MessageEditedResponder : IResponder<IMessageUpdate> {
|
|||
var currentUserResult = await _userApi.GetCurrentUserAsync(ct);
|
||||
if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult);
|
||||
|
||||
var diff = new SideBySideDiffBuilder(Differ.Instance).BuildDiffModel(message.Content, newContent, true, true);
|
||||
var diff = InlineDiffBuilder.Diff(message.Content, newContent);
|
||||
|
||||
Messages.Culture = guildConfiguration.GetCulture();
|
||||
|
||||
|
|
|
@ -122,11 +122,16 @@ public static class Extensions {
|
|||
return WebUtility.UrlEncode(s).Replace('+', ' ');
|
||||
}
|
||||
|
||||
public static string AsMarkdown(this SideBySideDiffModel model) {
|
||||
public static string AsMarkdown(this DiffPaneModel model) {
|
||||
var builder = new StringBuilder();
|
||||
foreach (var line in model.OldText.Lines.Where(piece => !string.IsNullOrWhiteSpace(piece.Text)))
|
||||
builder.Append("-- ").AppendLine(line.Text);
|
||||
foreach (var line in model.NewText.Lines) builder.Append("++ ").AppendLine(line.Text);
|
||||
foreach (var line in model.Lines) {
|
||||
if (line.Type is ChangeType.Deleted)
|
||||
builder.Append("-- ");
|
||||
if (line.Type is ChangeType.Inserted)
|
||||
builder.Append("++ ");
|
||||
if (line.Type is not ChangeType.Imaginary)
|
||||
builder.AppendLine(line.Text);
|
||||
}
|
||||
|
||||
return Markdown.BlockCode(builder.ToString().SanitizeForBlockCode(), "diff");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue