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.

prevent focusing void inline nodes

See original GitHub issue

is it possible to prevent focusing void inline nodes and make them act like characters? i.e. only allow the cursor the be on either side of the node, not “on” it.

I tried to create a rule for this, but couldn’t quite figure out how to check if a node has focus:

{
  match: node => node.kind === 'inline' && node.isVoid,
  validate: node => // how to check if the node has focus here?,
  normalize: (transform, node) => // move cursor to either side
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
maxjvhcommented, May 30, 2017

for anyone interested, managed to solve this eventually with a plugin like this:

class SkipVoidNodesPlugin {
  direction = '';
  onKeyDown(event, keyData, state) {
    if (keyData.key === 'left') {
      this.direction = 'Previous';
    } else if (keyData.key === 'right') {
      this.direction = 'Next';
    } else {
      this.direction = '';
    }
  }
  onBeforeChange(state) {
    if (this.direction !== '') {
      const focusedNode = state.focusInline || state.focusText;
      if (focusedNode.isVoid) {
        return state.transform()[`collapseToEndOf${this.direction}Text`]().apply();
      }
    }
  }
}
0reactions
ara4ncommented, May 12, 2018

for those looking at this today, the bad news is that onBeforeChange, Transform and State have gone. the good news seems to be that the same trick works if you do it in onChange with Change, with something like this:

    onChange = (change: Change) => {
        let value = change.value;
        if (this.direction !== '') {
            const focusedNode = value.focusInline || value.focusText;
            if (focusedNode.isVoid) {
                change = change[`collapseToEndOf${ this.direction }Text`]();
                value = change.value;
            }
        }
        // ...
        this.setState({
            value,
        });
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Normalizing - Slate
All Element nodes must contain at least one Text descendant — even Void Elements. ... Block nodes can only contain other blocks, or...
Read more >
focus-within - CSS: Cascading Style Sheets - MDN Web Docs
The :focus-within CSS pseudo-class matches an element if the element or any of its descendants are focused. In other words, it represents an ......
Read more >
How do you clear the focus in javascript? - Stack Overflow
It just satisfies the type checker. Wrap it in if(document.activeElement instanceof HTMLElement) to avoid crashing on non-HTML DOM nodes. – Raine Revere.
Read more >
How to use the slate.Inline.create function in slate - Snyk
insertInline (inline) // Normalize the keys in the block nodes to match what is sent to gradient const inlinePath = editor.value.selection.focus.path const ...
Read more >
Schema – Tiptap Editor
Since paragraph is in the group of block nodes ( group: 'block' ) our document can only contain paragraphs. Our paragraphs allow zero...
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