Skip to content

extract reusable functions from plainTextView#27572

Open
daesunp wants to merge 5 commits into
microsoft:mainfrom
daesunp:refactor-plain-text-editor-view
Open

extract reusable functions from plainTextView#27572
daesunp wants to merge 5 commits into
microsoft:mainfrom
daesunp:refactor-plain-text-editor-view

Conversation

@daesunp

@daesunp daesunp commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

Extracts reusable functions from plainTextView for shared use in our example app, and boards.

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Hi! Thank you for opening this PR. Want me to review it?

Based on the diff (628 lines, 6 files), I've queued these reviewers:

  • Correctness — logic errors, race conditions, lifecycle issues
  • Security — vulnerabilities, secret exposure, injection
  • API Compatibility — breaking changes, release tags, type design
  • Performance — algorithmic regressions, memory leaks
  • Testing — coverage gaps, hollow tests

How this works

  • Adjust the reviewer set by ticking/unticking boxes above. Reviewer toggles alone don't trigger anything.

  • Tick Start review below to dispatch the review fleet.

  • After review finishes, tick Start review again to request another run — it auto-resets after each dispatch.

  • This comment updates as new commits land; your reviewer selections are preserved.

  • Start review

@daesunp daesunp marked this pull request as ready for review June 22, 2026 18:12
Copilot AI review requested due to automatic review settings June 22, 2026 18:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comment on lines +101 to +102
* React hook that two-way binds an (uncontrolled) text input to a
* {@link @fluidframework/tree#TextAsTree.Tree}, returning spreadable input props.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really what I'd been imagining. While the 2-way binding could be convenient for some cases, I'm not sure how universally applicable it will be. The caveats called out in the remarks below seem to support this concern.

My assumption is that we would just have a simple 1-way sync from tree -> string. This is simple, and I would think pretty generally applicable. I.e., something like:

Usage:

const { text, selection } = useTreeSynchronizedString(tree, initialSelection);

Implementation:

function useTreeSynchronizedString(tree: TextAsTree.Tree, initialSelection?: SelectionRange): {
	text: string,
	selection: SelectionRange | undefined
} : {
	// useEffect block that binds character-change listener and recomputes `text` and `selection` any time the text tree changes
	// I think this mostly just amounts to calling `applyTextOps` on any change
}

The app author is still responsible for providing the mapping in the other direction.

I think this would be a lot less complex. And an application author that wants to do something like what you've built below could easily use our code as reference / a starting place to create such a utility. But I worry that this code is simultaneously complex and may or may not be widely applicable.

What do you think? I am curious what led you to this larger scope - I could easily be missing something here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with a smaller scope, but kept expanding it to optimize for "ease of use" for the boards prototype, and ended up basically re-wrapping our existing example without noticing. Your suggestion makes a lot more sense, and I updated with your suggestions :)

@github-actions

Copy link
Copy Markdown
Contributor

Bundle size comparison

Base commit: 3adb358594a36333b40463a2f8be3abcb07c782c
Head commit: b1ee35a35661d7b5550b804560f1f814c27f8d8f

⚠️ Comparison unavailable.

The PR's CI build failed — fix the build and the comment will update once the next run succeeds.

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.

3 participants