Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Read `design/engineering/implementation-guide.md` before writing a component: fi
## Non-negotiable rules

- Controls derive from Avalonia base types; only public Avalonia APIs are used. No AtomUI code or packages, and none of its source is consulted (clean room; design/decisions/0031-replace-atomui.md).
- Class names have no prefix; flat namespace `TKCode.Arc`; xmlns `https://github.com/AIDotNet/TKCode.Arc`. `TKCode.Arc.Mobile` is the exception: namespace `TKCode.Arc.Mobile`, xmlns `https://github.com/AIDotNet/TKCode.Arc.Mobile` (prefix `arcm`), and a few of its types share a desktop name (`Button`, `ButtonVariant`, `Checkbox`, `Dialog`, `RadioCard`, `RadioCardOption`, `RadioCards`, `Switch`, `Toast`; pinned by `MobileClassNameTests`, #152). New Mobile types do not reuse desktop names; a C# file that imports both namespaces aliases one side (`using MobileButton = TKCode.Arc.Mobile.Button;`).
- Class names have no prefix; flat namespace `TKCode.Arc`; xmlns `https://github.com/AIDotNet/TKCode.Arc`. `TKCode.Arc.Mobile` is the exception: namespace `TKCode.Arc.Mobile`, xmlns `https://github.com/AIDotNet/TKCode.Arc.Mobile` (prefix `arcm`), and a few of its types share a desktop name (`Button`, `ButtonVariant`, `Checkbox`, `Dialog`, `RadioCard`, `RadioCardOption`, `RadioCards`, `SegmentedItem`, `Switch`, `Toast`; pinned by `MobileClassNameTests`, #152). New Mobile types do not reuse desktop names; a C# file that imports both namespaces aliases one side (`using MobileButton = TKCode.Arc.Mobile.Button;`).
- `TKCode.Arc.Terminal` is a standalone terminal library published with Arc (#150, ADR 0052): it depends on Avalonia alone, keeps its `TKCode.Terminal.*` namespaces, needs no `UseArc` entry, and takes its colors from the terminal core's palette (the host sets it), so the token, theme and registration rules below do not apply to it. Its default font starts with Geist Mono.
- The `TKCode.Arc.StreamMark*` packages are standalone libraries published with Arc, like Terminal: they depend on Avalonia (plus Markdig, TextMate, Mermaider / Svg.Skia, the RaTeX native library) and never on Foundation, Core or the controls, keep their `StreamMark.*` namespaces, need no `UseArc` entry, and take their look from the `Md.*` resources a host maps (Arc's `Markdown` maps them onto tokens), so the token, theme and registration rules below do not apply to them. They keep StreamMark's stricter gate: trimming and AOT warnings are errors (build/ProjectDefaults.props). They follow the rest: braces, no reflection, PublicAPI files, CHANGELOG, the deprecation rule.
- Every public control has a `[ControlDesignToken]` `<Control>Token` in the same namespace with at least one property (ARCF003). Its identity (class name minus `Token`, or `[ControlDesignToken(Identity = "...")]`) is unique across all Arc packages, Mobile included (Mobile uses `MobileButton`, `MobileSwitch`, ...; design/engineering/reserved-token-names.md). Token property types are limited to those in foundation.md section 3.4 (ARCF001).
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ NuGet packages published with each release: `TKCode.Arc`, `TKCode.Arc.Core`, `TK
Also, as previews that follow the main version: `TKCode.Arc.Graphics3D`, `TKCode.Arc.Graphics3D.WebGpu`, `TKCode.Arc.Graphics3D.Controls` and
`TKCode.Arc.Graphics3D.Browser` (from 1.2.0-preview.3).

## Unreleased

### Added

- `CodeEditor` (`TKCode.Arc.Editor.Controls`): the cursor and selection API a host needs to drive the editor from code (#228), named after Monaco's `ICodeEditor`, with positions and selections as the public `TextPosition` / `TextSelection` / `TextRange` (1-based line and column in UTF-16 code units):
- `GetPosition()`, `GetSelection()`, `GetSelections()`, `SetPosition(...)`, `SetSelection(...)`, `SetSelections(...)`;
- `RevealLine`, `RevealPosition` and `RevealRange`, each also as `...InCenter` and `...InCenterIfOutsideViewport` (`RevealRangeAtTop` for ranges);
- the `CursorPositionChanged` and `CursorSelectionChanged` events, with `CodeEditorCursorPositionChangedEventArgs` / `CodeEditorCursorSelectionChangedEventArgs` (new position or selection, the old selections, `Source` such as `keyboard`, `mouse` or `api`, and a `CodeEditorCursorChangeReason`).
- `CodeEditor` (`TKCode.Arc.Editor.Controls`): undo and redo from code (#233): `CanUndo` and `CanRedo` (read-only Avalonia properties, as on `RichTextEditor`), `Undo()` and `Redo()` (they return whether a step ran), `PushUndoStop()` to end the current undo step, and the `UndoRedoStateChanged` event.
- `CodeEditor` (`TKCode.Arc.Editor.Controls`): `ShowFind()`, `ShowFindReplace()` and `CloseFind()` open and close the built-in find and find-and-replace widget from code (#233).
- `ToggleGroup` and `SegmentedControl` (`TKCode.Arc`): `SelectedItemBackground` and `SelectedItemForeground` brush properties set the fill behind the selected option (the gliding fill, or each pressed option's fill in multiple mode; the segmented pill) and its text and icon color, per instance or from a style, for backgrounds where the default selected look is hard to tell from the other options. Null (cleared) keeps the theme's colors (#227).
- `SegmentedItem` (`TKCode.Arc`) is now public (it was internal), so that XAML styles and Rider's checks can address `arc|SegmentedItem` (#231). It has a token of its own, `SegmentedItemToken` (identity `SegmentedControlItem`, because `TKCode.Arc.Mobile` already has a `SegmentedItem` token). `TKCode.Arc.Mobile` also has a `SegmentedItem` in its own namespace; a C# file that imports both namespaces aliases one side.
- `ArcWindow` / `TitleBar` / `WindowCaptionButtons` (`TKCode.Arc`): `CaptionButtonVariant` (`Round` | `Rectangle`, #230) picks the shape of the drawn caption buttons. `Round` is the default and the look is unchanged; `Rectangle` draws Windows-style flat buttons that are as tall as the title bar, 46 wide (`WindowCaptionButtonsToken.RectangleButtonWidth`), touch each other and the window's right edge (`TitleBarToken.RectangleButtonsPadding`), with square corners, and the close button turns solid danger under the pointer. Inherited, so setting it on the `ArcWindow` is enough; it applies only while the bar draws the buttons (`CaptionButtons` `Drawn`, or `Auto` outside macOS). New token entries: `WindowCaptionButtonsTokenKind.RectangleButtonWidth` and `RectangleCloseHoverForeground`, `TitleBarTokenKind.RectangleButtonsPadding`.

## 1.3.3-preview.2 - 2026-12-01

A patch preview fixing spurious `HoverCard` openings, with no public API changes. Install it with `--version 1.3.3-preview.2` (or `--prerelease`).
Expand Down
75 changes: 62 additions & 13 deletions src/TKCode.Arc.Editor.Controls/CodeEditor/CodeEditor.Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,77 @@ namespace TKCode.Arc;

public sealed partial class CodeEditor
{
/// <summary>The primary cursor's model position, or null without a view model (upstream's getPosition).</summary>
internal TextPosition? GetPosition() => ViewModel?.GetPosition();
/// <summary>
/// The primary cursor's position in the document (1-based line and column, UTF-16 code units), or null while the
/// editor has no view yet (upstream's getPosition).
/// </summary>
public TextPosition? GetPosition() => ViewModel?.GetPosition();

/// <summary>The primary selection (upstream's getSelection).</summary>
internal TextSelection? GetSelection() => ViewModel?.GetSelection();
/// <summary>The primary selection, or null while the editor has no view yet (upstream's getSelection).</summary>
public TextSelection? GetSelection() => ViewModel?.GetSelection();

/// <summary>Every selection, the primary first (upstream's getSelections).</summary>
internal IReadOnlyList<TextSelection> GetSelections() => ViewModel?.GetSelections() ?? [];
/// <summary>Every selection, the primary first; empty while the editor has no view yet (upstream's getSelections).</summary>
public IReadOnlyList<TextSelection> GetSelections() => ViewModel?.GetSelections() ?? [];

/// <summary>Moves the cursor to a model position, selecting nothing (upstream's setPosition).</summary>
internal void SetPosition(TextPosition position, string source = "api") =>
/// <summary>
/// Moves the cursor to a position, selecting nothing; the position is clamped into the document and the cursor
/// is revealed (upstream's setPosition). <paramref name="source"/> tells listeners where the change came from.
/// </summary>
public void SetPosition(TextPosition position, string source = "api") =>
SetSelections([new TextSelection(position.LineNumber, position.Column, position.LineNumber, position.Column)], source);

/// <summary>Sets the primary selection, removing the others (upstream's setSelection).</summary>
internal void SetSelection(TextSelection selection, string source = "api") => SetSelections([selection], source);
/// <summary>
/// Sets the primary selection, removing the other cursors (upstream's setSelection). <paramref name="source"/>
/// tells listeners where the change came from.
/// </summary>
public void SetSelection(TextSelection selection, string source = "api") => SetSelections([selection], source);

/// <summary>
/// Sets one or more selections, the first being the primary; an empty list changes nothing (upstream's
/// setSelections). <paramref name="source"/> tells listeners where the change came from.
/// </summary>
public void SetSelections(IReadOnlyList<TextSelection> selections, string source = "api") =>
SetSelections(selections, source, CursorChangeReason.NotSet);

/// <summary>Sets the selections (upstream's setSelections).</summary>
internal void SetSelections(IReadOnlyList<TextSelection> selections, string source = "api", CursorChangeReason reason = CursorChangeReason.NotSet) =>
internal void SetSelections(IReadOnlyList<TextSelection> selections, string source, CursorChangeReason reason) =>
ViewModel?.SetSelections(source, selections, reason);

/// <summary>Scrolls a line into view with the least scrolling (upstream's revealLine); the cursor does not move.</summary>
public void RevealLine(int lineNumber) => RevealLine(lineNumber, VerticalRevealType.Simple, ScrollType.Smooth);

/// <summary>Scrolls a line into the center of the view (upstream's revealLineInCenter).</summary>
public void RevealLineInCenter(int lineNumber) => RevealLine(lineNumber, VerticalRevealType.Center, ScrollType.Smooth);

/// <summary>Scrolls a line into the center of the view unless it is already visible (upstream's revealLineInCenterIfOutsideViewport).</summary>
public void RevealLineInCenterIfOutsideViewport(int lineNumber) =>
RevealLine(lineNumber, VerticalRevealType.CenterIfOutsideViewport, ScrollType.Smooth);

/// <summary>Scrolls a position into view with the least scrolling, also horizontally (upstream's revealPosition); the cursor does not move.</summary>
public void RevealPosition(TextPosition position) => RevealRange(new TextRange(position), VerticalRevealType.Simple, ScrollType.Smooth);

/// <summary>Scrolls a position into the center of the view (upstream's revealPositionInCenter).</summary>
public void RevealPositionInCenter(TextPosition position) => RevealRange(new TextRange(position), VerticalRevealType.Center, ScrollType.Smooth);

/// <summary>Scrolls a position into the center of the view unless it is already visible (upstream's revealPositionInCenterIfOutsideViewport).</summary>
public void RevealPositionInCenterIfOutsideViewport(TextPosition position) =>
RevealRange(new TextRange(position), VerticalRevealType.CenterIfOutsideViewport, ScrollType.Smooth);

/// <summary>Scrolls a range into view with the least scrolling (upstream's revealRange); the cursor does not move.</summary>
public void RevealRange(TextRange range) => RevealRange(range, VerticalRevealType.Simple, ScrollType.Smooth, revealHorizontal: true);

/// <summary>Scrolls a range into the center of the view (upstream's revealRangeInCenter).</summary>
public void RevealRangeInCenter(TextRange range) => RevealRange(range, VerticalRevealType.Center, ScrollType.Smooth, revealHorizontal: true);

/// <summary>Scrolls a range into the center of the view unless it is already visible (upstream's revealRangeInCenterIfOutsideViewport).</summary>
public void RevealRangeInCenterIfOutsideViewport(TextRange range) =>
RevealRange(range, VerticalRevealType.CenterIfOutsideViewport, ScrollType.Smooth, revealHorizontal: true);

/// <summary>Scrolls a range to the top of the view (upstream's revealRangeAtTop).</summary>
public void RevealRangeAtTop(TextRange range) => RevealRange(range, VerticalRevealType.Top, ScrollType.Smooth, revealHorizontal: true);

/// <summary>Scrolls a model range into view (upstream's revealRange and its InCenter / AtTop variants).</summary>
internal void RevealRange(TextRange range, VerticalRevealType verticalType = VerticalRevealType.Simple, ScrollType scrollType = ScrollType.Smooth, bool revealHorizontal = true)
internal void RevealRange(TextRange range, VerticalRevealType verticalType, ScrollType scrollType = ScrollType.Smooth, bool revealHorizontal = true)
{
if (ViewModel is not { } viewModel)
{
Expand All @@ -47,7 +96,7 @@ internal void RevealRange(TextRange range, VerticalRevealType verticalType = Ver
}

/// <summary>Scrolls a model line into view (upstream's revealLine).</summary>
internal void RevealLine(int lineNumber, VerticalRevealType verticalType = VerticalRevealType.Simple, ScrollType scrollType = ScrollType.Smooth) =>
internal void RevealLine(int lineNumber, VerticalRevealType verticalType, ScrollType scrollType = ScrollType.Smooth) =>
RevealRange(new TextRange(lineNumber, 1, lineNumber, 1), verticalType, scrollType, revealHorizontal: false);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ void ICoreCommandsCodeEditor.ExecuteCommands(string? source, IReadOnlyList<EditC
T IServicesAccessor.Get<T>() =>
this as T ?? throw new InvalidOperationException($"[invokeFunction] unknown service '{typeof(T).Name}'");

/// <summary>Adds an undo stop (upstream's pushUndoStop); false in a read-only editor.</summary>
internal bool PushUndoStop()
/// <summary>
/// Ends the current undo step, so that the edits after it undo separately from the ones before (upstream's
/// pushUndoStop); false in a read-only editor.
/// </summary>
public bool PushUndoStop()
{
if (IsReadOnly)
{
Expand Down
58 changes: 58 additions & 0 deletions src/TKCode.Arc.Editor.Controls/CodeEditor/CodeEditor.FindApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// The find and replace widget as method calls (upstream's trigger("actions.find"), trigger("editor.action.startFindReplace")
// and the find controller's closeFindWidget).

using TKCode.Arc.Editor.Contrib.Find;

namespace TKCode.Arc;

public sealed partial class CodeEditor
{
/// <summary>
/// Shows the find widget and focuses its search box, as Ctrl+F (Cmd+F) does: the search box is filled from the
/// selection when the options say so. Returns false when the editor cannot show it yet (it has not been
/// attached to a window).
/// </summary>
public bool ShowFind()
{
if (FindController.Get(this) is not { } controller)
{
return false;
}

Finish(FindActions.StartFind(controller));
return true;
}

/// <summary>
/// Shows the find widget with its replace row and focuses the search box, as Ctrl+H (Cmd+Alt+F) does. Returns
/// false when the editor is read-only or cannot show the widget yet (it has not been attached to a window).
/// </summary>
public bool ShowFindReplace()
{
if (FindController.Get(this) is not { } controller)
{
return false;
}

var started = FindActions.StartFindReplace(controller);
return started.IsCompleted ? started.GetAwaiter().GetResult() : !IsReadOnly;
}

/// <summary>Hides the find widget and puts the focus back into the text, as Escape does. Does nothing when it is not shown.</summary>
public void CloseFind()
{
if (FindController.Get(this) is { } controller && controller.State.IsRevealed)
{
controller.CloseFindWidget();
}
}

// find starts synchronously unless the clipboard has to be read; a fault of a start that goes on later is not lost
private static void Finish(Task task)
{
if (task.IsCompleted)
{
task.GetAwaiter().GetResult();
}
}
}
40 changes: 40 additions & 0 deletions src/TKCode.Arc.Editor.Controls/CodeEditor/CodeEditor.History.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Undo and redo as method calls (upstream's trigger("undo") / the model's undo and redo behind the core commands).

namespace TKCode.Arc;

public sealed partial class CodeEditor
{
/// <summary>
/// Undoes the last edit step, as Ctrl+Z does: the text and the cursors go back to before it. Returns false, and
/// changes nothing, when there is nothing to undo or the editor is read-only.
/// </summary>
public bool Undo() => RunHistoryStep(redo: false);

/// <summary>
/// Redoes the last undone edit step, as Ctrl+Y does. Returns false, and changes nothing, when there is nothing to
/// redo or the editor is read-only.
/// </summary>
public bool Redo() => RunHistoryStep(redo: true);

private bool RunHistoryStep(bool redo)
{
if (IsReadOnly || !(redo ? Model.CanRedo() : Model.CanUndo()))
{
return false;
}

var step = redo ? Model.Redo() : Model.Undo();
if (step.IsCompleted)
{
// the model's undo stack runs synchronously: no prompts here, so there is no way to be cancelled
step.GetAwaiter().GetResult();
}
else
{
_ = step.AsTask();
}

UpdateUndoRedoState();
return true;
}
}
Loading
Loading