Repository navigation
Better tab handling - #3770
Better tab handling#3770
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@acywatson This is the sibling pull request I mentioned in #3769. It also contains e2es I don't understand. The first run had two failures that succeed on the second run. The second run had two new claimed failures:
On the third run, only I can continue poking at it, but I'm really not sure what to make of this. I noticed that in GitHub actions, most current pull requests have at least one failing (or cautionary) test. I feel as if there is a piece of this picture I don't understand, and I don't know how to proceed as a result. Basically, I'm confused. Can you help? -j |
|
|
||
| // In these cases, we can fix the problem by manually inserting the | ||
| // newly typed character where we know it should have been. | ||
| const hasTabCharacter = textContent.includes('\t'); |
There was a problem hiding this comment.
Isn't tab always at the start?
There was a problem hiding this comment.
Isn't tab always at the start?
Oh! Well, I wasn't sure.
I think I probably used .includes because I know it will always find the tab while .startsWith or text[0]...may not?
Your approach is smarter. I'm happy to try it. I just always worry about being too smart with code. Every time I get smart with code, I regret it. Well, I regret it in life, too. But, I don't usually have to worry about that.
There was a problem hiding this comment.
I know what it is.
If you have a tab at the start of a line, move the anchor point to offset 0, then type, you'll get text before the tab. The tab basically gets pushed right or left. I guess I figured using .includes was more resilient to all these unknown scenarios.
There was a problem hiding this comment.
Makes sense! We definitely want to gate this to only code highlight nodes then, otherwise we're adding overhead to all other text inputs, which is every keypress.
| let textContent = getAnchorTextFromDOM(anchorNode); | ||
| const node = $getNearestNodeFromDOMNode(anchorNode); | ||
| if (textContent !== null && $isTextNode(node)) { | ||
| // The newly typed character may be missing from the DOM's textContent |
There was a problem hiding this comment.
I wonder if there's some way we can contain this heuristic to only code highlight nodes? Maybe if we introduce a new method on TextNode called canContainTabs(): boolean which is false by default and then implement it on CodeHighlightNode to return true. Then we can only validate this use case here and avoid applying it too all text insertions?
There was a problem hiding this comment.
I wonder if there's some way we can contain this heuristic to only code highlight nodes? Maybe if we introduce a new method on TextNode called
canContainTabs(): booleanwhich isfalseby default and then implement it on CodeHighlightNode to return true. Then we can only validate this use case here and avoid applying it too all text insertions?
I like what you're saying. These helper methods are a good idea.
I would've been afraid to be so specific with core on my own, though.
To be clear, this problem comes up when you contain highlight nodes in lines/divs, which is what I'm doing. I'm pretty committed to offering this LinedCodeNode up once done, which it nearly is. Maybe others will use it, too.
You don't really see this problem arise right now in the official code package because it doesn't contain code in lines. In essence, Lexical has side stepped it.
I'm using my own HighlightNode (LinedCodeTextNode), which has some specialized behavior over the official one. I'd be happy to add canContainTabs() to mine and target this code to check for it.
Offhand, that...seems like it'd work — and ward against unexpected bugs.
Would that be enough?
There was a problem hiding this comment.
The entire code node right now sucks (what we have). It should have been lined to begin with, with a div around each line to prevent wrapping and keep line numbers consistent. So anything you've done in this area would be advantageous and I'd love to bring it back into core.
There was a problem hiding this comment.
The entire code node right now sucks (what we have). It should have been lined to begin with, with a div around each line to prevent wrapping and keep line numbers consistent. So anything you've done in this area would be advantageous and I'd love to bring it back into core.
That's motivating, thanks. I'll shift canContainTabs into place and pull it into this PR.
| // newly typed character where we know it should have been. | ||
| const hasTabCharacter = textContent.includes('\t'); | ||
|
|
||
| if (data && hasTabCharacter) { |
There was a problem hiding this comment.
better to define data, as what if the value is "0"?
There was a problem hiding this comment.
I just suddenly realized what you meant.
I'll add data.length > 0 to the condition. I think that's what you mean? I'll push the change after the tests finish. Last time I pushed a commit in the middle of running tests, GitHub swallowed it.
This pull request fixes a problem with the use of the hidden tab character ('\t').
In some scenarios, new characters can't be inserted when it's present.
Here's a brief description of the new functionality from a new comment in
$updateSelectedTextFromDOM:Here's an edited version of the details I left on Discord:
This LinedCodeNode-related pull request is sibling to:
#3769
#3695
#3731
#3695
#3693