-
Notifications
You must be signed in to change notification settings - Fork 42
Unsticky inline styles #83
Conversation
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)
There was a problem hiding this 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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"; | ||
} |
There was a problem hiding this comment.
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 👍
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 |
@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", | ||
]); | ||
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
I don't know, I would really prefer that the invisible markers become
visible again. If I type `some cod` and realize the `e` is missing, I would
have to go before the `d`, type `de` and then remove the ending `d`.
If instead backspacing deletes the invisible ` character, it would be
obvious how to fix the text.
…On Thu, May 24, 2018 at 2:24 PM Max Stoiber ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/__test__/plugin.test.js
<#83 (comment)>
:
> +
+ currentSelectionState = currentSelectionState.merge({
+ focusOffset: 5,
+ anchorOffset: 5,
+ });
+
+ expect(subject()).toBe("handled");
+ expect(store.setEditorState).toHaveBeenCalled();
+ newEditorState = store.setEditorState.mock.calls[0][0];
+ const block = newEditorState.getCurrentContent().getLastBlock();
+ const length = block.getLength();
+ expect(block.getInlineStyleAt(length - 1).toJS()).toEqual([]);
+ expect(block.getInlineStyleAt(length - 2).toJS()).toEqual([
+ "BOLD",
+ ]);
+ });
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?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#83 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADWliqDpDxGuEiuVLic3Q-keKD0JYlhks5t1qZogaJpZM4ULvcP>
.
|
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); |
There was a problem hiding this comment.
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
Great catch, done |
How about adding a right-hand border on the current range, and allowing the
cursor to be to the left or to the right of the border, even though the
border is not an actual character? Is that possible? Then you can easily
choose to add to the end or not…
…On Thu, May 24, 2018 at 3:39 PM Max Stoiber ***@***.***> wrote:
Great catch, done
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#83 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADWlpvZffCOrLsOzuHOK9mZoMZ4HAynks5t1rf1gaJpZM4ULvcP>
.
|
Probably possible somehow, but again a lot more work and doesn't really have an impact on this change 😉 |
Will do in a follow-up PR with a new test harness
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!