Comments (2)
Also, if you apply a change of direction to the selected text close to the Void Element - Chrome removes the span nodes and after any changes (Ctrl+z for example) the editor crashes
output1.mov
from slate.
btw, I have a raw version of the hook that fixes this problem, you can also save a new direction locally and change it in the editor if desired
const config = { attributes: true, childList: true, subtree: true };
function isElementNode(node: Node | null): node is Element {
return !!node && node.nodeType === Node.ELEMENT_NODE;
}
export function useChangingDirection(editor: SlateEditor) {
useLayoutEffect(() => {
const textbox = ReactEditor.toDOMNode(editor, editor);
const callback: MutationCallback = (mutationsList) => {
const changedDirection = mutationsList.some(mutation => {
const { type, attributeName, target } = mutation;
if (type === "attributes" && target.nodeName === "DIV") {
if (attributeName === "style"
&& isElementNode(target)
) {
const styleAttribute = target.getAttribute("style");
return styleAttribute && styleAttribute.includes("direction");
}
return attributeName === "dir";
}
return false;
});
if (changedDirection) {
const childListMutations = mutationsList
.filter(mutation => mutation.type === "childList")
.reverse();
childListMutations.forEach(currentMutation => {
currentMutation.addedNodes.forEach(node => {
node.parentNode?.removeChild(node);
});
currentMutation.removedNodes.forEach(node => {
currentMutation.target.insertBefore(node, currentMutation.nextSibling);
});
});
}
};
const observer = new MutationObserver(callback);
observer.observe(textbox, config);
return () => observer.disconnect();
}, [editor]);
}
from slate.
Related Issues (20)
- Issue with Grammarly Integration - Undo Function Groups Multiple Edits
- How do I support solidjs? Can you implement a slate-solid? HOT 2
- Memory leak in EDITOR_TO_FORCE_RENDER
- Auto format Bug
- Cannot add text after creating an image in official Slate image example
- Unable to create custom hyperscript shorthands? ([email protected]) HOT 1
- Unable to consecutively delete Approved components. No response after deleting one and pressing Backspace.
- Segmentation fault when launching slade on (arch) linux
- onInput not fired when typing at the start of a contenteditable HOT 4
- Implementing line-breaking logic for Block formatted nodes HOT 2
- Why is initialValue required by slate-react's Slate component?
- how to clear history
- Text input goes backwards after adding a soft break in Chrome HOT 3
- examples are not 100% type safe HOT 3
- Copy from Slate rich text ignores empty lines when pasting in word
- Cost effective lodash HOT 1
- Cursor navigation issue
- Select all content and paste the content copied from other editors. The block node cannot be deleted.
- cursor not as expected when delete a inline badge
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slate.