Skip to content
Merged
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,34 @@ and a release's notes are its section. The procedure is in [`docs/RELEASING.md`]
own, as the Roleplay layout puts it, had no tab to close it by. The draft is kept, and *Dock the composer* brings it
back.

### Changed

- The mouse wheel and PgUp/PgDn now scroll the output 10 lines at a time, in the window and the terminal alike. F7 ▸
Scrollback has *lines per wheel notch* and *lines per page key* to change that; 0 page-key lines scrolls a whole page,
as PgUp used to.

### Fixed

- In the window, scrolled-back or frozen text no longer drops a row when the pane splits. A blank row used to appear
above the history, so the text jumped down as the band opened.
- Dragging a pane's scrollbar in the window no longer opens the scrolled-back band under the pointer. The band used to
appear mid-drag, which moved the scrollbar away from the pointer and redrew the pane on every movement. The pane now
splits when the scrollbar is let go, and the scrollbar stays exactly where it was when it does.
- A pane's scrollbar in the window now runs the whole height of the pane while it is scrolled back. It used to stop at
the scrolled-back band, which was drawn over it, so the bar looked shorter than the pane it scrolls.
- The scrolled-back band in the window is the same height at every text size. It used to be two rows of text tall, so it
was thin with a small font and thick with a large one.
- Reading a few lines back from the newest output no longer jumps further back when a busy pane drops its oldest
lines. A reader closer to the bottom than the lines dropped was moved up by the difference.
- Esc in the docked composer goes back to the tab you came from. It used to leave the keyboard on the composer's own
pane, so the command line was your character's main window's even when you had been reading Chat.
- Closing the docked composer (Ctrl+W or the new button) puts the keyboard focus straight back on the command line, so
a paste lands there.

- A character whose name has a space, connected as `"first last"` on a MUSH, gets a session log again. The quotes
went into the log's file name, which Windows refuses, so no log was written. World and character names are now made
safe for Windows, Linux and macOS before they name a file: quotes and control characters are dropped, `< > : / \ | ? *`
become `_`, and a name like `CON` is changed so Windows will take it. A name that needed none of this names the same
file as before.

- A world connected with no character (`/connect host`, a `telnet://` link, Browse worlds) can be closed again. Its tab
was the client's main window, which only closed once a character was deleted, so ⌃W, ⌃B x and the tab's × did
nothing. Closing it now ends that connection. Its world's row in the sidebar reads *no character* and opens it again,
Expand Down
24 changes: 19 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,25 @@ fallbacks) for inline images/maps.
passed (`TheHistoryIsAVisibleStepOffEveryPaneAndNeverPastTheReadingPlane`, all three themes). The
history viewport is wrapped in a grid wearing it (`_scrollHistorySurfaces`, re-coloured in `RefreshPaneFocus`); the
tail keeps the pane's plane. Where the host keeps a gutter, `PaintScrollHistoryGutters` paints the blank gutter and
pad-row cells beside it after the frame, and the window's overlay scrollbar runs beside the history alone.
- **The window's band is two rows** (`ScrollBandRows`: 2 under `HostChrome.Tabs`, else 1; the second row is blank band),
published across the gutter with `ScrollBandOverlay.Inset`, so `ScrollBandView` lines its words up with the output
and keeps its button as far from the right edge — the mockup's 40 px band with a real button. Still `rows`, not the
mockup's `lines`: a buffer index is not a viewport row.
pad-row cells beside it after the frame.
- **The window's scrollbar measures a split pane as if it were whole** (`ScrollbarViewportRows`: the track is the pane,
the viewport the rows it had before it split), so the split opening or closing moves the thumb not at all; the history
cannot scroll further down than that before `MeetsTail` closes the split. **A held thumb holds the split**
(`PaneScrollbar.Held`, `HoldScrollbar`, `_scrollbarHeld`): while the window's thumb is dragged `SyncScrollSplit` opens
and closes nothing, and catches up on release. A split opened mid-drag rebuilt the pane under the pointer and moved
the track (reported).
**The bars are drawn over the native views** (`ScrollbarLayer`, in `DesktopLayer` above the pane views; `TerminalView`
draws them itself only with no layer), so the band does not hide the track's foot, and the band's button keeps clear of
the bar's press zone (`ScrollBandView.ClearRight`, from `TerminalView.ScrollbarZones`). Once a split's history viewport
is arranged its height is read live (`SplitHistoryRows`), so a resize while split keeps the bar and `MeetsTail` agreed.
- **The window's band is 40 px at every text size** (`ScrollBandView.BandHeight`): the client gives it whole rows
(`ScrollBandRows` reads `IPointerPresenter.ScrollBandRows`, the window's `ScrollBandView.RowsFor(cell, interface
scale)`; 2 where nothing measured, 1 in the cells), and the view draws the band at the foot of them with what is left
above in the history's plane, read off the cell over it. Published across the gutter with `ScrollBandOverlay.Inset`,
so `ScrollBandView` lines its words up with the output and keeps its button as far from the right edge. Still `rows`,
not the mockup's `lines`: a buffer index is not a viewport row.
- **The wheel and the page keys move F7's lines** (`TextSettings.WheelLines`/`PageLines`, 10 each; `PageLines` 0 is a
page less two rows of overlap), in both hosts: the window's wheel arrives as notches through the same driver path.
- **Inside the pane rectangle, so NAWS never moves**: the band and the tail are rows of the tab's content;
`PaneOutputRects` is unchanged (`ScrollingBackSplitsThePane…` pins it).
- **A split pane is not "scrolled back" for the workspace** (`SetScrolledBack(…, !AutoScroll && !split)`):
Expand Down
30 changes: 29 additions & 1 deletion src/SharpMUTerm.Avalonia/DesktopLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal sealed partial class DesktopLayer : Canvas
private readonly Dictionary<string, NativeTabStrip> _strips = new(StringComparer.Ordinal);
private readonly Dictionary<string, ScrollBandView> _bands = new(StringComparer.Ordinal);
private readonly SeamRules _seams = new();
private readonly ScrollbarLayer _scrollbars;
private (SharpMUTerm.Core.Theming.Theme Theme, NativeTokens Tokens)? _paneTokens;
private int _noticeAboveRow;

Expand Down Expand Up @@ -85,6 +86,11 @@ public DesktopLayer(TerminalView view, HostChrome chrome)

// The runs of the native views' rules into the divider cells beside them: over the cells, under nothing it touches.
Children.Add(_seams);

// The panes' overlay scrollbars over every native view laid on a pane (a scrolled-back band lies over its foot).
_scrollbars = new ScrollbarLayer(view);
view.ScrollbarLayer = _scrollbars;
Children.Add(_scrollbars);
_pointer.StatusChanged += () => Dispatcher.UIThread.Post(Sync);

// A dragged tab's hint over the panels; the toasts still over it.
Expand Down Expand Up @@ -266,13 +272,22 @@ private void SyncCovered()
/// <summary>The native views' rules carried on to the pane dividers' hairlines beside them. Internal for tests.</summary>
internal SeamRules Seams => _seams;

/// <summary>Where the panes' scrollbars are drawn. Internal for tests.</summary>
internal ScrollbarLayer Scrollbars => _scrollbars;

/// <summary>
/// Runs each full-width rule a native view over a pane draws (<see cref="IEdgeRules"/>) on through the half divider
/// cell between the view's edge and the divider's hairline (<see cref="TerminalView.VerticalHairlines"/>), so a tab
/// strip's foot, a panel's heading and a strip's seams meet the hairline rather than stopping half a cell short.
/// </summary>
private void SyncSeams(Size cell)
{
var at = CellOrigin;
SetLeft(_scrollbars, at.X);
SetTop(_scrollbars, at.Y);
_scrollbars.Width = Math.Max(0, _view.Bounds.Width);
_scrollbars.Height = Math.Max(0, _view.Bounds.Height);

SetLeft(_seams, 0);
SetTop(_seams, 0);
_seams.Width = Math.Max(0, Bounds.Width);
Expand Down Expand Up @@ -323,9 +338,22 @@ private void SyncPaneChrome(Size cell)
}

Sync(_bands, bands.Select(b => (b.Model.WindowId, b.Row)), () => new ScrollBandView(), origin, cell);
var frame = _view.Driver.Frame;
var zones = _view.ScrollbarZones();
foreach (var band in bands)
{
_bands[band.Model.WindowId].Show(band, tokens, said!.Interactive);
// What of its rows the band leaves is the history's: read the plane off the cell just above it.
var view = _bands[band.Model.WindowId];
var x = Math.Clamp(band.Row.X, 0, Math.Max(0, frame.Width - 1));
view.Above = band.Row.Y > 0 && band.Row.Y - 1 < frame.Height && frame.Width > 0
? Colour(_view.Renderer.Background(frame[x, band.Row.Y - 1]))
: null;
// The pane's scrollbar runs on under the band, at its right edge: the button keeps clear of where a press is the bar's.
var outerRight = GetLeft(view) + NativeScale.Extent(view).Width;
view.ClearRight = zones.TryGetValue(band.Model.WindowId, out var zone)
? Math.Max(0, outerRight - (origin.X + zone.Left)) / Math.Max(0.1, NativeScale.Of(view))
: 0;
view.Show(band, tokens, said!.Interactive);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/SharpMUTerm.Avalonia/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public MainWindow(WindowOptions options, IClassicDesktopStyleApplicationLifetime
_driver.Settings.Scales = scales;
_driver.Floating.Scales = scales;
_driver.Pointer.PanelScale = () => scales().Panels;
_driver.Pointer.InterfaceScale = () => scales().Interface;

// The edge Avalonia would have drawn round a BorderOnly window on X11, drawn here (DecorationsFor): a hairline,
// only while the window is an ordinary window with no frame of its own.
Expand Down
61 changes: 53 additions & 8 deletions src/SharpMUTerm.Avalonia/PaneChromeViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,47 @@ public IEnumerable<EdgeRule> EdgeRules(Size size)
yield break;
}

yield return new EdgeRule(NativeTokens.HorizontalRule(this, 0, 0, size.Width), Tokens.Rule);
var top = BandTop(size.Height);
yield return new EdgeRule(NativeTokens.HorizontalRule(this, top, 0, size.Width), Tokens.Rule);
yield return new EdgeRule(NativeTokens.HorizontalRule(this, size.Height - NativeTokens.DevicePixel(this), 0, size.Width), Tokens.Rule);
}

/// <summary>
/// The band's height in logical pixels: the mockups' 40, at every font size. The client gives it whole rows
/// (<see cref="RowsFor"/>); the part of a row it does not need is drawn above it in the history's plane.
/// </summary>
internal const double BandHeight = 40;

/// <summary>The rows a band of <see cref="BandHeight"/> needs at a cell <paramref name="cellHeight"/> tall, drawn at <paramref name="scale"/>.</summary>
internal static int RowsFor(double cellHeight, double scale) =>
cellHeight <= 0 ? 2 : Math.Max(1, (int)Math.Ceiling((BandHeight * Math.Max(0.1, scale) / cellHeight) - 0.001));

/// <summary>Where the band begins in a view <paramref name="height"/> tall: at its foot, under what of the rows it leaves.</summary>
private static double BandTop(double height) => Math.Max(0, Math.Round(height - BandHeight));

/// <summary>
/// How much of the band's right end, in its own pixels, the pane's scrollbar takes: the button stays left of it, so a
/// press there is the bar's (the band passes every press but the button's on to the cells).
/// </summary>
internal double ClearRight
{
get => _clearRight;
set
{
if (Math.Abs(_clearRight - value) > 0.01)
{
_clearRight = value;
Lay();
InvalidateVisual();
}
}
}

private double _clearRight;

/// <summary>The plane the rows above the band are drawn in: the history's, read off the cells above. Internal for tests.</summary>
internal Color? Above { get; set; }

private Rect _button;
private bool _hover;
private bool _pressed;
Expand All @@ -538,7 +575,7 @@ public ScrollBandView()
internal Rect Button => _button;

/// <summary>The band's words and button: the mockups' 12 px over the output's 13.</summary>
private double Size => (double.IsNaN(Height) ? Bounds.Height : Height) >= 20 ? NativeTokens.Caption : NativeTokens.Small;
private double Size => Math.Min(BandHeight, double.IsNaN(Height) ? Bounds.Height : Height) >= 20 ? NativeTokens.Caption : NativeTokens.Small;

private string ButtonText => $"{ScrollBandModel.Action} {NativeKeys.Words(ScrollBandModel.ReturnKey)}";

Expand Down Expand Up @@ -577,9 +614,11 @@ private void Lay()
{
var width = double.IsNaN(Width) ? Bounds.Width : Width;
var height = double.IsNaN(Height) ? Bounds.Height : Height;
var top = BandTop(height);
var band = height - top;
var w = PanelText.Measure(ButtonText, Size, bold: true) + 20;
var h = Math.Max(4, Math.Min(height - 4, 24));
_button = new Rect(Math.Max(0, width - w - TextInset), Math.Round((height - h) / 2), w, h);
var h = Math.Max(4, Math.Min(band - 4, 24));
_button = new Rect(Math.Max(0, width - w - Math.Max(TextInset, ClearRight + 4)), top + Math.Round((band - h) / 2), w, h);
}

public bool HitTest(Point point) => Interactive && _button.Contains(point);
Expand Down Expand Up @@ -637,15 +676,21 @@ public override void Render(DrawingContext context)
return;
}

var bounds = new Rect(Bounds.Size);
var top = BandTop(Bounds.Height);
if (top > 0 && Above is { } above)
{
context.FillRectangle(new SolidColorBrush(above), new Rect(0, 0, Bounds.Width, top));
}

var bounds = new Rect(0, top, Bounds.Width, Bounds.Height - top);
var plane = Tokens.Raised;
context.FillRectangle(new SolidColorBrush(plane), bounds);
var rule = new SolidColorBrush(Tokens.Rule);
context.FillRectangle(rule, NativeTokens.HorizontalRule(this, 0, 0, bounds.Width));
context.FillRectangle(rule, NativeTokens.HorizontalRule(this, bounds.Height - NativeTokens.DevicePixel(this), 0, bounds.Width));
context.FillRectangle(rule, NativeTokens.HorizontalRule(this, top, 0, bounds.Width));
context.FillRectangle(rule, NativeTokens.HorizontalRule(this, Bounds.Height - NativeTokens.DevicePixel(this), 0, bounds.Width));

var size = Size;
var middle = bounds.Height / 2;
var middle = bounds.Y + (bounds.Height / 2);
var x = TextInset;
var room = _button.X - 12;
x += PanelText.Draw(context, band.Model.Lead(band.Count), x, middle, size, NativeTabStrip.Held(Tokens.Text, plane), true, room - x);
Expand Down
24 changes: 24 additions & 0 deletions src/SharpMUTerm.Avalonia/ScrollbarLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Avalonia.Controls;
using Avalonia.Media;

namespace SharpMUTerm.Avalonia;

/// <summary>
/// The panes' overlay scrollbars, drawn over the native views the window lays on a pane rather than under them. A pane
/// split by scrolling back has a native band over its foot (<see cref="ScrollBandView"/>); drawn in the cells' view, the
/// track stopped at the band, so the bar read as shorter than the pane it scrolls. It lies over the cells at the cells'
/// origin and takes no input: a press on a bar is still <see cref="TerminalView"/>'s, which the band lets through.
/// </summary>
internal sealed class ScrollbarLayer : Control
{
private readonly TerminalView _view;

public ScrollbarLayer(TerminalView view)
{
_view = view;
IsHitTestVisible = false;
Focusable = false;
}

public override void Render(DrawingContext context) => _view.DrawScrollbars(context);
}
Loading
Loading