@flozy/editor 3.7.9 → 3.8.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -163,20 +163,24 @@ export const isMarkBtnActive = (editor, format) => {
|
|
163
163
|
}
|
164
164
|
};
|
165
165
|
export const getSelectedElementStyle = (styleProperty, editor) => {
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
166
|
+
try {
|
167
|
+
if (!editor.selection) {
|
168
|
+
return "";
|
169
|
+
}
|
170
|
+
if (Range.isCollapsed(editor.selection)) {
|
171
|
+
return "";
|
172
|
+
}
|
173
|
+
const domRange = ReactEditor.toDOMRange(editor, editor.selection);
|
174
|
+
const selectedDomNode = domRange.commonAncestorContainer;
|
174
175
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
// If it's a text node, get its parent element
|
177
|
+
const selectedElement = selectedDomNode.nodeType === 3 ? selectedDomNode.parentElement : selectedDomNode;
|
178
|
+
if (selectedElement) {
|
179
|
+
const computedStyle = window.getComputedStyle(selectedElement);
|
180
|
+
return computedStyle.getPropertyValue(styleProperty) || "";
|
181
|
+
}
|
182
|
+
} catch (err) {
|
183
|
+
console.log(err);
|
180
184
|
}
|
181
185
|
};
|
182
186
|
export const isBlockActive = (editor, format) => {
|