-
Notifications
You must be signed in to change notification settings - Fork 4
Release v2.5.0 #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Release v2.5.0 #238
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d9c5a82
Merge pull request #228 from gui-cs/backmerge/v2.4.1
tig d0f71d1
refactor!: move all namespaces under Terminal.Gui.Editor (#231)
tig 3682df0
style: fix using-directive sort order after namespace rename
tig 2a6f1c7
feat(ted): highlight current editor line in Markdown preview
tig dffcf8b
refactor(ted): move SourceLineClickedEventArgs to its own file
tig cf22fb5
Merge pull request #232 from gui-cs/tig/move-namespaces-under-termina…
tig ac3839e
Add namespace-level XML documentation for all Terminal.Gui.Editor nam…
tig c505dab
fix(ted): use ViewportToScreen for highlight bar screen reads
tig a87dfac
style: fix ReSharper cleanup drift (var preference, trailing newlines)
tig e1b8fb3
Merge pull request #233 from gui-cs/tig/feature-markdown-preview-line…
tig 2156c67
Fix ReSharper code style: wrap long XML doc lines
tig 78cb85c
Fixes #235. Bug: CRLF newline requires two keypresses
BDisp b980078
Merge pull request #236 from BDisp/issue/235_crlf-newline
BDisp 123f814
Merge branch 'develop' into tig/add-namespace-documentation
tig 2484e20
style: fix ReSharper cleanup alignment in NamespaceDoc.cs
tig c033cb3
Merge pull request #234 from gui-cs/tig/add-namespace-documentation
tig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
benchmarks/Terminal.Gui.Editor.Benchmarks/DocumentAccessBenchmarks.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
benchmarks/Terminal.Gui.Editor.Benchmarks/ScrollingBenchmarks.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
benchmarks/Terminal.Gui.Editor.Benchmarks/VisualLineBuildBenchmarks.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| using System.Drawing; | ||
| using Terminal.Gui.Drawing; | ||
| using Terminal.Gui.Input; | ||
| using Terminal.Gui.ViewBase; | ||
| using Terminal.Gui.Views; | ||
| using Attribute = Terminal.Gui.Drawing.Attribute; | ||
| using Color = Terminal.Gui.Drawing.Color; | ||
|
|
||
| namespace Ted; | ||
|
|
||
| /// <summary> | ||
| /// A <see cref="Markdown" /> subclass that highlights the rendered line(s) corresponding to a | ||
| /// source line in the editor and raises <see cref="SourceLineClicked" /> when the user clicks | ||
| /// in the preview, enabling click-to-navigate back to the editor. | ||
| /// </summary> | ||
| internal sealed class MarkdownPreview : Markdown | ||
| { | ||
| private int _highlightSourceLine = -1; | ||
| private int _totalSourceLines; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the 0-based source line number to highlight in the preview. | ||
| /// Set to -1 to clear the highlight. | ||
| /// </summary> | ||
| public int HighlightSourceLine | ||
| { | ||
| get => _highlightSourceLine; | ||
| set | ||
| { | ||
| if (_highlightSourceLine == value) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| _highlightSourceLine = value; | ||
| SetNeedsDraw (); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the total number of source lines in the document. | ||
| /// Used for proportional mapping between source lines and rendered lines. | ||
| /// </summary> | ||
| public int TotalSourceLines | ||
| { | ||
| get => _totalSourceLines; | ||
| set | ||
| { | ||
| if (_totalSourceLines == value) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| _totalSourceLines = value; | ||
| SetNeedsDraw (); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Raised when the user clicks in the preview. The event arg carries the estimated 0-based | ||
| /// source line number corresponding to the click position. | ||
| /// </summary> | ||
| public event EventHandler<SourceLineClickedEventArgs>? SourceLineClicked; | ||
|
|
||
| /// <summary> | ||
| /// Maps a 0-based source line number to the corresponding rendered line index using | ||
| /// proportional mapping. | ||
| /// </summary> | ||
| private int MapSourceToRendered (int sourceLine) | ||
| { | ||
| if (_totalSourceLines <= 1 || LineCount <= 0) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| return (int)((long)sourceLine * (LineCount - 1) / (_totalSourceLines - 1)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Maps a rendered line index back to an approximate 0-based source line number. | ||
| /// </summary> | ||
| private int MapRenderedToSource (int renderedLine) | ||
| { | ||
| if (LineCount <= 1 || _totalSourceLines <= 0) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| return (int)((long)renderedLine * (_totalSourceLines - 1) / (LineCount - 1)); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override bool OnDrawingContent (DrawContext? context) | ||
| { | ||
| var result = base.OnDrawingContent (context); | ||
|
|
||
| DrawHighlightBar (); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Paints a subtle background highlight on the rendered row corresponding to | ||
| /// <see cref="HighlightSourceLine" />. | ||
| /// </summary> | ||
| private void DrawHighlightBar () | ||
| { | ||
| if (_highlightSourceLine < 0 || _totalSourceLines <= 0 || LineCount <= 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var renderedLine = MapSourceToRendered (_highlightSourceLine); | ||
|
|
||
| // Check if the highlighted line is within the visible viewport. | ||
| var drawRow = renderedLine - Viewport.Y; | ||
|
|
||
| if (drawRow < 0 || drawRow >= Viewport.Height) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Compute a highlight attribute: shift the background slightly for contrast. | ||
| Attribute normalAttr = GetAttributeForRole (VisualRole.Normal); | ||
| Color highlightBg = normalAttr.Background.IsDarkColor () | ||
| ? normalAttr.Background.GetDimmerColor (0.25, false) | ||
| : normalAttr.Background.GetDimmerColor (0.15, true); | ||
|
|
||
| // Paint the highlight over the full viewport width by reading existing screen content | ||
| // and re-drawing with the highlight background. | ||
| Cell[,]? contents = ScreenContents; | ||
|
|
||
| if (contents is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Map the viewport-relative draw row to screen coordinates so we read the correct | ||
| // cells regardless of horizontal scroll position (Viewport.X). | ||
| Point screenOrigin = ViewportToScreen (new Point (0, drawRow)); | ||
| var screenRow = screenOrigin.Y; | ||
| var screenStartCol = screenOrigin.X; | ||
|
|
||
| for (var col = 0; col < Viewport.Width; col++) | ||
| { | ||
| var sc = screenStartCol + col; | ||
|
|
||
| if (screenRow < 0 || screenRow >= contents.GetLength (0) || sc < 0 || sc >= contents.GetLength (1)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| Cell cell = contents[screenRow, sc]; | ||
| var grapheme = string.IsNullOrEmpty (cell.Grapheme) ? " " : cell.Grapheme; | ||
|
|
||
| // Preserve the foreground color from the original cell but apply highlight background. | ||
| Attribute cellAttr = (cell.Attribute ?? normalAttr) with { Background = highlightBg }; | ||
| SetAttribute (cellAttr); | ||
| AddStr (col, drawRow, grapheme); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override bool OnMouseEvent (Mouse mouse) | ||
| { | ||
| if (mouse.Flags.HasFlag (MouseFlags.LeftButtonClicked) && mouse.Position is { } pos) | ||
| { | ||
| var contentRow = Viewport.Y + pos.Y; | ||
|
|
||
| if (contentRow >= 0 && contentRow < LineCount) | ||
| { | ||
| var sourceLine = MapRenderedToSource (contentRow); | ||
| SourceLineClicked?.Invoke (this, new SourceLineClickedEventArgs (sourceLine)); | ||
| } | ||
| } | ||
|
|
||
| return base.OnMouseEvent (mouse); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace Ted; | ||
|
|
||
| /// <summary>Event args for <see cref="MarkdownPreview.SourceLineClicked" />.</summary> | ||
| internal sealed class SourceLineClickedEventArgs : EventArgs | ||
| { | ||
| public SourceLineClickedEventArgs (int sourceLine) | ||
| { | ||
| SourceLine = sourceLine; | ||
| } | ||
|
|
||
| /// <summary>Gets the estimated 0-based source line number that was clicked.</summary> | ||
| public int SourceLine { get; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.