Skip to content

feat(editor): hide a decoration's range or show a view in its columns - #2519

Open
im-apratap wants to merge 1 commit into
nsgo-dev:mainfrom
im-apratap:feat/editor-shapes
Open

im-apratap wants to merge 1 commit into
nsgo-dev:mainfrom
im-apratap:feat/editor-shapes

Conversation

@im-apratap

Copy link
Copy Markdown

Items 1 and 2 of #2409: "Hide a range (the ** around bold text) while the caret is off its lines" and "Replace a range with a view in the line: a link's label, a checkbox for - [ ], a rendered formula".

The problem

base/editor could style a range (Style, LineStyle, Token), but an app could not change what the range shows. A Markdown editor with a live preview therefore cannot hide a link's [[/]] or draw a checkbox in place of [ ], though the editor already lays its text out in fixed columns and draws its own layers.

What changes

  • Decoration.Hidden draws none of the range's characters and takes their columns out of the line, so the text after them moves left. The text keeps its offsets: keys, selections, copying, search and the highlighting all still see the characters. A range across lines hides each line's part and keeps the breaks.
  • Decoration.Replace keeps the range's columns and draws the view it gives in a box that wide and as tall as the line, over the rows (shapes.go). The view takes its own presses, so a checkbox or a link button works; the text after it stays exactly where it was, so no caret or selection moves.
  • The rows skip both kinds of range's glyphs; xOf, posAt, the selection, match, bracket, link and caret boxes and the whitespace marks measure the columns a line shows (shownCols, byteAtShownCol), so carets and presses land on the character under the pointer, and a press inside collapsed text lands at its start.
  • shapes.go merges the ranges, gives a Replace precedence over a Hidden one for the columns both cover, and clips them to the line.

Not in this change

  • Item 3, a view between lines (a table, an image), and item 4, a line's own height and font size, remain.
  • No gallery Markdown sample: the demo still shows the editor's existing decorations. I can add one if you would rather review the feature there.
  • With soft wrap, rows still break at the text's own columns, so a hidden range can leave a short row; the document says so. Making wrap measure shown columns means teaching display.layout about decorations and is worth its own change.

Verification

  • go tool nsgo check -target linux — vetted for linux_arm64 and linux_x64.
  • go tool nsgo test ./base/editor — 27 passed, including three new tests: TestHiddenDecorationCollapsesItsColumns (the last character moves four columns, a press puts the caret before it, typing at the end keeps the offsets and the markers hidden after the edit), TestReplacedDecorationShowsItsViewInTheRange (the view shows, the range's glyphs do not, the word after it keeps its x, and a press reaches the view) and TestHiddenDecorationAcrossLinesKeepsTheBreaks (the lines keep their rows).
  • go tool nsgo test ./ui/editor — 3 passed.
  • go tool nsgo test -run 'TestEditor$' ./examples/gallery — 1 passed.
  • go run ./tools/changelog check — valid.

🤖 Generated with Codebuff

A Decoration can now draw none of its range's characters, collapsing their
columns, or draw a view in the columns the text took, so a Markdown live
preview hides the ** around bold text and shows checkboxes and link labels.
The editor measures shown columns for carets, selection boxes, presses and
whitespace marks, so the text's offsets, keys and copying are unchanged.
@github-actions github-actions Bot added size/L enhancement New feature or request documentation Improvements or additions to documentation base labels Nov 26, 2026

This branch has not been deployed

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

Labels

base documentation Improvements or additions to documentation enhancement New feature or request size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant