Closed ctbarna closed 7 years ago
@ianstormtaylor just wondering if you had thoughts on this and issues like it (selecting text and applying transforms via keydown often applies the transform to the previous selection, for another example). It feels like a core stability issue with how selections work, wanted to know if you have an idea of what's going on or if these issues are undiagnosed.
Hey @erquhart I haven't looked into what is causing this, but if you do I'd love to know and then happy to discuss it with you.
Yep, I'll probably have to as our implementation moves forward, definitely intend to contribute. I was more fishing for "it's probably x" from you as the architect, having the most intimate knowledge of the codebase, that's all.
In the case of this specific issue, I'd guess that the "operations" aren't expressing their inverses properly, resulting in a bad undo. But it sounds like you're talking about a different case?
Some of the selection bugginess seemed to maybe share the same cause, so I was trying to determine if there's a centralized ticket or effort for that cause, but it doesn't sound like there's a single underlying issue. Just learned, for example, about trackpad dragging having a 300ms timeout enforced at the OS level for Mac, which botches quick select/backspace maneuvers.
I'll probably revisit this once we get through our initial implementation.
Adding this as it's probably related (botched undo operation with marked text), brought up by another developer in Slack:
Expected: previously bold text should be bold, and non-bold text should not be bold Actual: all text is bold
How hard is it to fix this?
Hard to say, you'd need to debug history around marked node operations, specifically for undo since redo appears to be okay.
In Transforms.removeMarkAtRange,
adding the following logic seems to solve the problem:
const ranges = text.getRanges()
let rangeIndex = 0
ranges.forEach(range => {
const {marks, text} = range
const rangeLength = text.length
if (marks.has(mark)) {
const start = Math.max(index, rangeIndex)
const end = Math.min(index + length, rangeIndex + rangeLength)
if (start < end) {
transform.removeMarkByKey(key, start, end - start, mark, { normalize })
}
}
rangeIndex += rangeLength
})
Do you want to request a feature or report a bug?
Feel free to close this report if it's a duplicate – I searched "undo" but nothing seemed to quite fit. I am not currently developing with Slate.js but discovered a reproducible bug in the example editor.
What's the current behavior?
Tested in Chrome 58 on Mac
cmd-z
.Current behavior: The re-done text is "mu ch"
What's the expected behavior?
The editor should restore text to the original state: "ch text, mu"