Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sticky editor menu #977

Merged
merged 12 commits into from
Feb 20, 2025
Merged

Sticky editor menu #977

merged 12 commits into from
Feb 20, 2025

Conversation

allisonking
Copy link
Contributor

@allisonking allisonking commented Feb 13, 2025

Issue(s) Resolved

Closes #937
Closes #941
Closes #942

High-level Explanation of PR

Adds a menu bar to the context editor which can stick to the top of an editor. The editor needs to have a max-height and overflow: scroll for the stickiness to kick in.

Test Plan

  1. Run pnpm run storybook in packages/context-editor and play with the editor!

Or, to see it in the app:

  1. Add a rich text field to a form
  2. Add enough content to the rich text field so that the max height kicks in and a scroll bar appears.
  3. The menu should stay sticky

Screenshots (if applicable)

demo of bold/italic commands

Screen.Recording.2025-02-19.at.10.25.22.AM.mov

it's sticky!

Screen.Recording.2025-02-19.at.10.30.00.AM.mov

Notes

I based the bold and italic input rules off of the inline code one in legacy:
https://github.com/pubpub/pubpub/blob/4e39976b74a7204cb5703f2b5e5b2cf7f2ce3233/client/components/Editor/plugins/inputRules.ts#L45-L57

including the space at the end to trigger the rule. I thought the space was unnecessary at first, but I think in this case where the editor is applying rules as soon as the user types, it's necessary for *italic* vs **bold**, otherwise **bold** can never trigger. (It works for things like this GH editor because you have to navigate to the preview view which can then figure out you mean to bold instead of seeing **bold* and immediately making it '*bold'

@allisonking allisonking force-pushed the aking/937/sticky-menu branch from 28034dd to 68c803f Compare February 18, 2025 21:15
suggestData,
setSuggestData
),
new Plugin({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's easier to include this plugin here rather than in basePlugins since this one needs access to pluginViewFactory which we get from the hook

import type { MarkType } from "prosemirror-model";
import type { EditorState } from "prosemirror-state";

export const markIsActive = (markType: MarkType, editorState: EditorState) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

took this from legacy

@allisonking allisonking marked this pull request as ready for review February 19, 2025 15:53
@allisonking allisonking requested review from tefkah and 3mcd February 19, 2025 15:53
Copy link
Member

@3mcd 3mcd left a comment

Choose a reason for hiding this comment

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

Clean and straightforward. Great work!

@allisonking allisonking merged commit 744be29 into main Feb 20, 2025
6 checks passed
@allisonking allisonking deleted the aking/937/sticky-menu branch February 20, 2025 22:21
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.

Italics button/support Bold button/support Sticky Menu Bar
2 participants