question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Allow range selections on top-level decorator nodes

See original GitHub issue

Description

I’m investigating Lexical as an alternative to mobiledoc-kit as the underlying framework that powers our editor at Ghost. One of the key usability features of our editor is cards entering a “selected” state via the keyboard (equivalent of a card would be a top-level decorator node).

Here’s a minimal example of our most basic card interaction with a HR card:

https://user-images.githubusercontent.com/415/186399138-6404166d-bfb1-4d03-a688-5c40ee4af7b5.mp4

In mobiledoc-kit such selections are achievable because every card has a ‌ character before and after the card’s DOM element which can receive a cursor position. We can use the equivalent of an update listener to watch for the cursor being in one of those positions/ranges so we can trigger both cursor normalisation (it’s always moved to the trailing zwnj so it’s easier to handle delete/backspace keyboard events) and to put the card component into a selected state.

As far as I can tell such behaviour isn’t possible in Lexical because there is nowhere for the cursor to be positioned on/around a decorator.

Alternative solutions

Not sure, maybe there are already hooks that could allow such behaviour?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
kevinansfieldcommented, Oct 11, 2022

Not yet, it’s towards the end of our short term roadmap for the next few weeks. I’ll be sure to share what we come up with and any pain points we hit when we get there.

1reaction
kevinansfieldcommented, Oct 26, 2022

@DaniGuardiola I was noodling on our up/down arrow behaviour a bit this evening and ended up with this https://github.com/TryGhost/Koenig/pull/390. Probably not 100% yet but initial testing shows it working for our use-cases. I’ll add some tests tomorrow and merge then it will be testable on our demo at https://koenig.ghost.org

One odd thing I’ve come across is the built-in Up/Down key handling when there’s a node selection seems to skip a node and puts the caret in an unexpected position.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference manual - ProseMirror
This module defines types for classical text selections (of which cursors are a special case) and node selections, where a specific document node...
Read more >
Enterprise Grade Features: Master Detail - AG Grid
Master / Detail allows you to nest grids inside grids. The top level grid is referred to as the 'master grid'. The nested...
Read more >
javascript get id of "commonAncestorContainer" - Stack Overflow
Regarding the parameter to getRangeAt() , it is specifying the index of the selection range to return, and it's only really relevant to...
Read more >
Decoration updates breaks selection · Issue #893 - GitHub
This change in the ranges of text breaks Slate's onSelect logic. Indeed, onSelect receives on the one hand the native selection ranges ......
Read more >
Behavior trees for AI: How they work - Game Developer
It's possible some of the more specific decorator node types I detail here ... This functionality is key to the power of behaviour...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found