Repository navigation
Conversation
TextareaState can now hold text decoration collections, like EditorState: create_decorations_collection, with ranges that follow edits. The renderer already composed decoration layers for every mode; ordinary multi-line text had no extras to hold them. Inline tokens keep working beside them, which EditorState cannot offer. TextDecorationCollection takes the mode as a type parameter, defaulting to EditorMode, so existing code is unchanged.
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.
Description
TextareaState(ordinary multi-line text) can now hold text decoration collections, the same APIEditorStatealready has:create_decorations_collection, with ranges that follow edits.The renderer already composes decoration layers for every mode (the non-code-editor branch in
element.rscallsextras.decoration_layers()), butTextareaMode's extras were(), so there was nowhere to put them. Switching toEditorStateto get decorations is not an option for inputs that use inline tokens, whichEditorModedoes not support.Use case: light Markdown highlighting in a chat composer (bold, italic, code spans, quieter syntax characters) that also shows pasted text as inline tokens.
What changed:
TextareaModegetsTextareaExtras { decorations: DecorationCollections }, withreset_annotations/adjust_annotationsdoing whatEditorMode's do for text decorations.TextDecorationCollectiontakes the owning mode as a type parameter, defaulting toEditorMode. Its methods andcreate_decorations_collectionare implemented forEditorModeandTextareaModeby one macro, following thetoken_api!pattern ininline_tokens.rs. Most of the diff indecorations.rsis the existing methods moving into that macro unchanged (re-indented).test_textarea_decorations_follow_typing(mirrorstest_editor_decorations_follow_typing) andtest_textarea_decorations_beside_inline_tokens.Checked:
cargo test -p gpui-base --lib(1338 passed),cargo clippy -p gpui-base -p gpui-component --locked -- --deny warnings,cargo fmt --check,cargo check -p gpui-component-story.Screenshot
A Textarea with inline-token support, highlighted through the new API:
[screenshot]
Public API
gpui_base::input(re-exported fromgpui_component::input):InputBaseState<TextareaMode>::create_decorations_collection(&mut self, decorations: Vec<TextDecoration>, cx: &mut Context<Self>) -> TextDecorationCollection<TextareaMode>— new: text decorations for multi-line text (TextareaState).pub struct TextDecorationCollection<M: InputModeKind = EditorMode>— gains the mode type parameter;set,append,clearandget_rangesexist forEditorModeandTextareaMode.pub struct TextareaExtras— new:TextareaMode's extras, holding its decorations.Breaking Changes
<TextareaMode as InputModeKind>::Extrasis nowTextareaExtrasinstead of(). Code namingTextDecorationCollectionwithout a parameter keeps compiling (it defaults toEditorMode).