Repository navigation
feat(editor): hide a decoration's range or show a view in its columns - #2519
Open
im-apratap wants to merge 1 commit into
Open
im-apratap wants to merge 1 commit into
im-apratap wants to merge 1 commit into
Conversation
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.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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/editorcould 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.Hiddendraws 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.Replacekeeps 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.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.gomerges the ranges, gives aReplaceprecedence over aHiddenone for the columns both cover, and clips them to the line.Not in this change
display.layoutabout decorations and is worth its own change.Verification
go tool nsgo check -target linux— vetted forlinux_arm64andlinux_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) andTestHiddenDecorationAcrossLinesKeepsTheBreaks(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