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

Add helper for text color extention #1799

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Anenth
Copy link

@Anenth Anenth commented Jul 25, 2022

Description

Added a helper to get the color from the current selection

Checklist

  • I have read the contributing document.
  • My code follows the code style of this project and pnpm fix completed successfully.
  • I have updated the documentation where necessary.
  • New code is unit tested and all current tests pass when running pnpm test.

Screenshots

@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2022

⚠️ No Changeset found

Latest commit: 4d04910

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator

@whawker whawker left a comment

Choose a reason for hiding this comment

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

Thanks so much for the contribution @Anenth!

Sorry my review is so late, my normal job has been taking up all my time recently

* Get the color for the selection
*/
@helper()
getTextColorForSelection(selection?: Selection): Helper<string> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should default to the current selection here, I believe

import { Selection } from '@remirror/core';
Suggested change
getTextColorForSelection(selection?: Selection): Helper<string> {
getTextColorForSelection(selection: Selection = this.store.getState().selection): Helper<string> {

*/
@helper()
getTextColorForSelection(selection?: Selection): Helper<string> {
if (!selection) return this.options.defaultColor;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect we need to check we have a text selection here?

import { isTextSelection } from '@remirror/core';
Suggested change
if (!selection) return this.options.defaultColor;
if (!isTextSelection(selection) || selection.empty) {
return this.options.defaultColor;
}

getTextColorForSelection(selection?: Selection): Helper<string> {
if (!selection) return this.options.defaultColor;

const state = this.store.getState();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem to be used?


const state = this.store.getState();
const textMarkInfo = getMarkRange(selection.$from, this.type);
if (!textMarkInfo) return this.options.defaultColor;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Formatting is a bit off here, suspect this would be fixed by running pnpm fix

Suggested change
if (!textMarkInfo) return this.options.defaultColor;
if (!textMarkInfo) {
return this.options.defaultColor;
}

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.

None yet

2 participants