Skip to content

Implement print and preview for script and custom-function editors - #315

Draft
PawelTroka wants to merge 1 commit into
masterfrom
codex/editor-printing-20261030
Draft

PawelTroka wants to merge 1 commit into
masterfrom
codex/editor-printing-20261030

Conversation

@PawelTroka

@PawelTroka PawelTroka commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Problem

Fixes #79.

On base fe1aba49b5f9538355ffaaa3d1683f69a23d2d9c, open a script or custom function, edit its buffer, then use File → Print or File → Print preview. Both editor branches in those commands are empty, so neither action does anything. Chart printing already has a separate implementation.

Change

  • Route Print and Print preview to the currently active scripting/custom-functions editor, using the existing IPrinting contract. Preserve chart dispatch and the existing keyboard fallback in other views.
  • Capture the complete selected buffer before opening a dialog, including unsaved/untitled content. Printing never rereads or saves disk files, modifies selection, changes tabs or clears dirty state. Empty buffers submit no job.
  • Share one plain-text print document across Scintilla, AvalonEdit and TextEditor: measured wrapping, four-column tab stops, Unicode text-element boundaries, document-name headers and page numbers. A preview followed by a print pass starts from page 1 again.
  • Intersect user margins with the printer's actual printable area in physical page coordinates, then render relative to the user-margin origin. This accounts for asymmetric/fractional printer hard margins.
  • Bound width measurement to a prefix around one printable row instead of repeatedly measuring a very long source line in full. Reject unusable page dimensions rather than generating endless blank pages.
  • Validate printer settings and cancel/report explicit layout failures at document callbacks, including callbacks used asynchronously by native preview. Deduplicate a page error followed by a synchronous controller cleanup error, while allowing unexpected programming-state exceptions to propagate. Document platform prerequisites and native acceptance steps in the existing desktop document-safety guide.

This is whole-document plain-text printing. Syntax colors, selection-only printing, page ranges and a page-setup UI are outside this change.

Validation

Reviewed and uploaded tree: 2381ad38daad96f74140983025a9b5a7e5d8a625, identical to the tested local commit. Local host: Linux x64, SDK 10.0.403 (allowed by the repository's latestPatch policy).

Executed

Final affected-code rerun:

dotnet test Computator.NET.Engine.Tests/Computator.NET.Engine.Tests.csproj \
  --no-restore --filter 'FullyQualifiedName~CodePrintPaginationTests' \
  --logger 'trx;LogFileName=printing-final-focused.trx' \
  -m:1 -nodeReuse:false -p:UseSharedCompilation=false

29 passed, 0 failed, 0 skipped against the final production paginator, dedicated layout-error type and page-layout code. These cases cover line endings/blank lines, page continuation, measured widths, surrogate pairs/combining characters, tabs, long-line measurement bounds, invalid measurements/dimensions, progress guarantees and physical printer-margin geometry.

The full engine suite also passed 1,467 / 1,467, with no failures or skips, at preceding local commit 7c6f8d20a3f0d5a9c356e75cf78d9637c6247cda, using the same command without the filter or --no-restore. The final review then narrowed expected print errors to a dedicated exception type and added error-report deduplication; the 29 affected portable cases and both desktop builds were rerun on the final source. The 1,467 total is reported for that preceding run, not as a new full-suite execution after the review adjustment.

The 18 committed command-routing cases were additionally run in a temporary net10.0 harness linking the actual production PrintCommand/PrintPreviewCommand files and EditorPrintingCommandTests; only Windows UI shell/resource/interface dependencies were stubbed. Against the original commands: 6 failed / 12 passed, reproducing the missing editor actions. Against the fixed production files: 18 passed / 0 failed / 0 skipped. This verifies routing, not native dialog execution. The actual Windows Core test project also cross-built successfully below.

git diff --check passed.

Cross-built successfully; not executed natively

dotnet build Computator.NET.Core.Tests/Computator.NET.Core.Tests.csproj \
  -p:EnableWindowsTargeting=true -m:1 -nodeReuse:false -p:UseSharedCompilation=false

dotnet build Computator.NET.Desktop.Tests/Computator.NET.Desktop.Tests.csproj \
  --no-restore -p:EnableWindowsTargeting=true -m:1 -nodeReuse:false -p:UseSharedCompilation=false

dotnet build Computator.NET.Desktop/Computator.NET.Desktop.csproj \
  --no-restore -p:ComputatorMono=true -m:1 -nodeReuse:false -p:UseSharedCompilation=false

All three builds completed with 0 errors. The desktop/reduced Mono builds retain existing package compatibility, obsolete-member or unrelated-field/nullability warnings.

The 25 new native desktop cases compile against the real editors. They check selected/unsaved/untitled snapshots, unchanged selection/dirty flags/files, locked/deleted backing files, print-error preservation/deduplication, unexpected-error propagation, callback cancellation, pagination restart and the actual bitmap renderer. The renderer fixture attaches a first-page PNG when it executes on Windows. No native Windows test run, printer submission, screenshot or Mono GUI execution is claimed from this Linux host.

Before marking ready: run the repository's Windows Core/Desktop acceptance targets and the documented Print/Preview workflow with a configured PDF/native printer in both editor views for all three editor backends. Inspect wrapping, Unicode glyphs, page numbering and hard-margin alignment. Errors raised by native preview/print controller code outside document callbacks—for example device creation or EndPage/EndDoc during asynchronous preview, or the preview toolbar’s Print action—can still reach the application’s native error handler. Those paths, physical printer behavior and hard-margin alignment require Windows acceptance; the portable harness and cross-builds do not establish them. Actual visual captures are pending that native run.

Relationship to existing work

The issue, current implementation, open PRs and recent merged work were reviewed before this change. Existing #237 addresses chart preview, while open #310 addresses editor Find/Replace; neither implements editor printing. This PR is independently based on master, with no dependency on another new PR. It does not modify translation catalogs owned by #306.

Combined compatibility check — 2026-10-30

Also tested the final contributions in #311, #313, #314 and #315 together with the seven existing maintenance PRs (#304–#310), using the existing #312 candidate 189d28c0ec7acbf77d380f14f95ef450e7bfbd84 as the local integration base.

  • Complete combined Engine Release suite: 1,819 passed, zero failed/skipped.
  • Combined Python reference-authoring suite: 76 passed.
  • Windows-targeted Core.Tests and Desktop.Tests cross-builds: passed, zero errors, with existing warnings.
  • Deterministic reference check: passed, covering 1,251 articles and 1,351 completion items.

Eight shared paths required composition resolutions. These preserved all Euclid/ODE/polynomial aliases, completion and authoring registrations; Debye/unitary documentation; and Find/Replace/printing methods, test-source links and documentation entries. No feature behavior or numerical algorithm needed changing to combine the contributions. The independently published PRs remain based on master.

Combined local tree: 63225a973ea2883974a91ab26afcdc83d866e77b, SDK 10.0.403, Linux x64. The reference check used the authenticated master inventory plus current production reflection for changed entries through a portable UI shell. Native Windows tests, full native catalog execution and printer acceptance remain pending. The existing #312 PR was not changed by this local verification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add printing option to code editors

1 participant