Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Unsticky inline styles #83

Merged
merged 3 commits into from
May 24, 2018
Merged

Unsticky inline styles #83

merged 3 commits into from
May 24, 2018

Conversation

mxstbr
Copy link

@mxstbr mxstbr commented May 24, 2018

This "unstickies" inline styles, so that when you type bold text, backspace to the ending edge of the bold text and start typing again the bold doesn't "stick" to the text, only when typing within it. This feels much better than before.

Recorded demo:
Live demo: https://public-mffnxzocik.now.sh

/cc @brianlovin @wmertens this should be a fix for the issues you were having!

This "unstickies" inline styles, so that when you type *bold* text,
backspace to the ending edge of the bold text and start typing again
the bold doesn't "stick" to the text, only when typing within it. This
feels much better than before.

Recorded demo: ![](https://i.imgur.com/gWSLp06.gif)
Copy link

@juliankrispel juliankrispel left a comment

Choose a reason for hiding this comment

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

Niiiiiiiiiiiice! Just one comment and maybe some unit tests?

src/index.js Outdated
const content = editorState.getCurrentContent();
const block = content.getBlockForKey(selection.getStartKey());
const entity = block.getEntityAt(startOffset);
if (entity !== null) return editorState;

Choose a reason for hiding this comment

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

It'd be nice if you could also add a check for an inline entity

Copy link
Author

Choose a reason for hiding this comment

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

How do I do that?

Choose a reason for hiding this comment

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

hold on actually you're already doing that with block.getEntityAt - my bad :D

if (editorState !== unsticky) {
setEditorState(unsticky);
return "handled";
}

Choose a reason for hiding this comment

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

would be nice to add a bunch of unit tests for this 👍

@mxstbr mxstbr dismissed juliankrispel’s stale review May 24, 2018 08:37

Unit test added in latest commit!

@thibaudcolas
Copy link

thibaudcolas commented May 24, 2018

This looks pretty cool! Do you use it in an editor that also has normal keyboard shortcuts or toolbar buttons for inline styles? While for Markdown shortcuts I think it makes perfect sense, I wonder how end users like it if they trigger bold with the usual Ctrl + B, or a button.

@mxstbr
Copy link
Author

mxstbr commented May 24, 2018

@thibaudcolas yes, this is just a small piece in our overall editing experience—we're also working on adding an inline toolbar to trigger those inline styles.

expect(block.getInlineStyleAt(length - 2).toJS()).toEqual([
"BOLD",
]);
});

Choose a reason for hiding this comment

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

I'd also add some unit tests for when stickiness doesn't apply: like when you're in an entity for example 👍 just to make sure it doesn't break in future

Copy link
Author

Choose a reason for hiding this comment

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

I tried for like an hour to write another test, but it always has the wrong content state (text: altered!!) and I don't know where it's coming from or how to fix it 😢 Any clues?

@wmertens
Copy link

wmertens commented May 24, 2018 via email

@mxstbr
Copy link
Author

mxstbr commented May 24, 2018

If instead backspacing deletes the invisible ` character, it would be obvious how to fix the text.

It's not invisible though, it's not there anymore—so it's not as simple as just removing that! I totally see why pressing backspace at the end removing the inline styling would be nice, will see if we can tackle that in the future sometime, doesn't contradict this change though!

src/index.js Outdated
const startOffset = selection.getStartOffset();
const content = editorState.getCurrentContent();
const block = content.getBlockForKey(selection.getStartKey());
const entity = block.getEntityAt(startOffset);

Choose a reason for hiding this comment

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

this needs to be startOffset - 1 btw, just as below

@mxstbr
Copy link
Author

mxstbr commented May 24, 2018

Great catch, done

@wmertens
Copy link

wmertens commented May 24, 2018 via email

@mxstbr
Copy link
Author

mxstbr commented May 24, 2018

Probably possible somehow, but again a lot more work and doesn't really have an impact on this change 😉

@mxstbr mxstbr dismissed juliankrispel’s stale review May 24, 2018 16:36

Will do in a follow-up PR with a new test harness

@mxstbr mxstbr merged commit 65fee79 into master May 24, 2018
@mxstbr mxstbr deleted the unsticky branch May 24, 2018 16:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants