diff --git a/docs/PRODUCT.md b/docs/PRODUCT.md index ffde71e..7318f0f 100644 --- a/docs/PRODUCT.md +++ b/docs/PRODUCT.md @@ -2,7 +2,7 @@ Build a Windows counterpart to [Darin Kelkhoff's markdownViewr](https://github.com/darinkelkhoff/markdownViewr), using the KofTwentyTwo AppKit foundations and standards. The agreed display name is MarkdownViewr, repository MarkdownViewr.Windows, and permanent application ID markdownviewr-windows. -The first reader implementation opens Markdown with a Windows picker or literal launch argument, renders sanitized GFM and supports bounded local images, manual reload and automatic saves with relative scroll preservation. The original 20 document themes and persistent palette selection are implemented. Hosted reader/live-reload/theme selection and both installed update channels passed on 77dd04d. Editable custom themes, color/code-font/CSS controls and restoration are implemented; their dialog/browser acceptance passed in CI 38102867556. Frontmatter, resizable outline/depth/jump/section controls and literal source visibility/reload/physical resize passed CI 38106991467: 34 native/UI and published tests, 33 per installed channel, no skips. Paired browser/source find, repeated local-fragment reveal and configured editor launch passed CI 38110726381: 41 native/published tests and 40 per installed channel, no skips. Vim navigation is implemented with 239 core tests/100% lines; its new physical-key acceptance remains pending. The full feature list below remains the target; the first reader is not a completed port. +The first reader implementation opens Markdown with a Windows picker or literal launch argument, renders sanitized GFM and supports bounded local images, manual reload and automatic saves with relative scroll preservation. The original 20 document themes and persistent palette selection are implemented. Hosted reader/live-reload/theme selection and both installed update channels passed on 77dd04d. Editable custom themes, color/code-font/CSS controls and restoration are implemented; their dialog/browser acceptance passed in CI 38102867556. Frontmatter, resizable outline/depth/jump/section controls and literal source visibility/reload/physical resize passed CI 38106991467: 34 native/UI and published tests, 33 per installed channel, no skips. Paired browser/source find, repeated local-fragment reveal and configured editor launch passed CI 38110726381: 41 native/published tests and 40 per installed channel, no skips. Vim navigation passed CI 38112298176: 44 native/published tests and 43 per installed channel, zero skips. Parser-derived source positions are implemented with 255 core tests/100% lines; source heading/scroll/collapse UI synchronization remains pending. The full feature list below remains the target; the first reader is not a completed port. ## Reference and feature scope diff --git a/docs/SESSION-STATE.md b/docs/SESSION-STATE.md index 36aaa52..d114a0b 100644 --- a/docs/SESSION-STATE.md +++ b/docs/SESSION-STATE.md @@ -330,3 +330,21 @@ Raw line lookup is indexed rather than rescanning all lines for each heading. snapshot and public renderer policy remain unchanged. Full scroll/heading/collapse source UI remains unimplemented, not replaced by this foundation. No GUI input, Azure attempt, merge/tag/release or claim of production signing. + +## Verified vim channels and indexed source line ends + +6bf125d / CI 38112298176 is fully SUCCESS. Retained TRX proves native/published +44/44 and installed stable/dev 43/43 each, zero failures/skips. Evidence retained +in artifacts/vim-verified-installed-38112298176, native and installed job logs. +Four payload gates verify 536 files per payload; update probes apply/restart both +channels. Fixtures remain synthetic/unsigned and do not prove production signing. +All exact prior producers are terminal before this source increment's push. + +Local signed source-provenance a0d8fe7 has a further tested indexed-line-end fix: +255 core tests/100% lines and zero-warning build/format pass. A 300-heading raw +single-line regression verifies distinct offsets with one shared line end. Global +line ends are indexed once; per-heading lookup is logarithmic. This avoids a +quadratic full-remainder scan for adversarial long raw HTML lines. The source +snapshot remains immutable; no new capability/dependency is introduced. Update +PRODUCT/TODO with actual vim proof; source synchronization UI stays pending and +full scope remains active. No local GUI input, Azure attempt, merge/tag/release. diff --git a/docs/TODO.md b/docs/TODO.md index 041606f..1ba7a25 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -24,7 +24,7 @@ - [x] Implement paired native browser/source find with bounded literal terms, shared counts, wraparound and reload guards (issue #10). - [x] Verify paired find and repeated local-fragment reveal on 5a9af63: 41 native/published and 40 per installed channel, zero skips. - [x] Implement all required vim reading/find/heading commands, timed prefixes and native focus/modifier guards (issue #10). -- [ ] Verify physical vim browser viewport, collapsed-heading and query-typing acceptance in native/published/installed builds. +- [x] Verify physical vim viewport, collapsed-heading and query-typing acceptance on 6bf125d: CI 38112298176, 44 native/published and 43 per installed channel, zero skips. - [x] Map sanitized surviving headings to original parser-derived source offsets (Setext/fences/raw HTML/frontmatter/duplicates); source UI synchronization remains pending. - [ ] Add synchronized source headings/scroll/collapse (issue #10); audit find/source collapse parity against the pinned reference. - [x] Implement and core-test hidden/metadata/Markdown frontmatter modes, with persisted native controls and attribution. diff --git a/src/MarkdownViewr.Windows.Core/Documents/DocumentSourceMap.cs b/src/MarkdownViewr.Windows.Core/Documents/DocumentSourceMap.cs index b67ff82..2ffe5b0 100644 --- a/src/MarkdownViewr.Windows.Core/Documents/DocumentSourceMap.cs +++ b/src/MarkdownViewr.Windows.Core/Documents/DocumentSourceMap.cs @@ -18,7 +18,7 @@ namespace MarkdownViewr.Windows.Core.Documents; /// Carries parser provenance through sanitation using a fresh private attribute removed before presentation. internal sealed class DocumentSourceMap { - private readonly string _source; + private readonly int[] _lineEnds; private readonly Dictionary _positions = new(StringComparer.Ordinal); @@ -27,7 +27,15 @@ internal sealed class DocumentSourceMap public DocumentSourceMap(string source) { ArgumentNullException.ThrowIfNull(source); - _source = source; + var ends = new List(); + int start = 0; + while(source.IndexOf('\n', start) is int end && end >= 0) + { + ends.Add(end); + start = end + 1; + } + ends.Add(source.Length); + _lineEnds = ends.ToArray(); AttributeName = "data-mv-source-" + Guid.NewGuid().ToString("N"); } @@ -86,8 +94,8 @@ internal sealed class DocumentSourceMap /// Raw heading markup stays on its original source line; the canonical snapshot is never rewritten. private int EndOfLine(int start) { - int end = _source.IndexOf('\n', start); - return end >= 0 ? end : _source.Length; + int index = Array.BinarySearch(_lineEnds, start); + return _lineEnds[index >= 0 ? index : ~index]; } diff --git a/tests/MarkdownViewr.Windows.Core.Tests/DocumentSourceHeadingTests.cs b/tests/MarkdownViewr.Windows.Core.Tests/DocumentSourceHeadingTests.cs index 157f904..f5d20f1 100644 --- a/tests/MarkdownViewr.Windows.Core.Tests/DocumentSourceHeadingTests.cs +++ b/tests/MarkdownViewr.Windows.Core.Tests/DocumentSourceHeadingTests.cs @@ -101,6 +101,23 @@ public sealed class DocumentSourceHeadingTests + /// Many raw headings on one line share one bounded line end without rescanning its entire remaining text per heading. + [Fact] + public void Create_ManyRawHeadingsOnOneLine_PreservesDistinctOffsets() + { + string source = string.Concat(Enumerable.Repeat("

Same

", 300)); + var outline = new DocumentOutline(source); + Assert.Equal(300, outline.SourceHeadings.Count); + for(int index = 0; index < outline.SourceHeadings.Count; index++) + { + Assert.Equal(index * "

Same

".Length, outline.SourceHeadings[index].Start); + Assert.Equal(source.Length, outline.SourceHeadings[index].End); + } + Assert.DoesNotContain("data-mv-source-", outline.Html, StringComparison.OrdinalIgnoreCase); + } + + + /// A mapped render still rejects null, oversized content and corrupt frontmatter modes before use. [Fact] public void Create_InvalidInput_PreservesRenderingLimits()