el-text-editor 0.0.78 → 0.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1175,24 +1175,58 @@ class ElTextEditorComponent {
|
|
1175
1175
|
inputElement.click();
|
1176
1176
|
}
|
1177
1177
|
}
|
1178
|
+
// setTextColor(event: any) {
|
1179
|
+
// if (this.savedSelection) {
|
1180
|
+
// const color = event.target.value;
|
1181
|
+
// this.selectedTextColor = color;
|
1182
|
+
// // Restore the saved selection
|
1183
|
+
// const selection = window.getSelection();
|
1184
|
+
// if (selection) {
|
1185
|
+
// selection.removeAllRanges();
|
1186
|
+
// selection.addRange(this.savedSelection);
|
1187
|
+
// // Apply the color using a span
|
1188
|
+
// const range = this.savedSelection;
|
1189
|
+
// const span = document.createElement('span');
|
1190
|
+
// span.style.color = color;
|
1191
|
+
// span.textContent = range.toString();
|
1192
|
+
// // Replace the selected text with the styled span
|
1193
|
+
// range.deleteContents();
|
1194
|
+
// range.insertNode(span);
|
1195
|
+
// // Clear the saved selection
|
1196
|
+
// this.savedSelection = null;
|
1197
|
+
// }
|
1198
|
+
// }
|
1199
|
+
// }
|
1178
1200
|
setTextColor(event) {
|
1179
1201
|
if (this.savedSelection) {
|
1180
1202
|
const color = event.target.value;
|
1181
1203
|
this.selectedTextColor = color;
|
1182
1204
|
// Restore the saved selection
|
1183
1205
|
const selection = window.getSelection();
|
1184
|
-
if (selection) {
|
1185
|
-
selection.removeAllRanges();
|
1186
|
-
selection.addRange(this.savedSelection);
|
1187
|
-
// Apply the color using a span
|
1206
|
+
if (selection && selection.rangeCount > 0) {
|
1188
1207
|
const range = this.savedSelection;
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1208
|
+
selection.removeAllRanges();
|
1209
|
+
selection.addRange(range);
|
1210
|
+
// Get selected elements
|
1211
|
+
const selectedContent = range.cloneContents();
|
1212
|
+
const elements = Array.from(selectedContent.querySelectorAll("*")); // ✅ Explicitly cast to HTMLElement[]
|
1213
|
+
// Apply color to each element without modifying structure
|
1214
|
+
elements.forEach((el) => {
|
1215
|
+
el.style.color = color;
|
1216
|
+
});
|
1217
|
+
// Apply color to the top-level text nodes (without wrapping them)
|
1218
|
+
Array.from(selectedContent.childNodes).forEach((node) => {
|
1219
|
+
if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim() !== "") {
|
1220
|
+
const parent = range.commonAncestorContainer.parentElement;
|
1221
|
+
if (parent) {
|
1222
|
+
parent.style.color = color;
|
1223
|
+
}
|
1224
|
+
}
|
1225
|
+
});
|
1226
|
+
// Replace selected content
|
1193
1227
|
range.deleteContents();
|
1194
|
-
range.insertNode(
|
1195
|
-
// Clear
|
1228
|
+
range.insertNode(selectedContent);
|
1229
|
+
// Clear saved selection
|
1196
1230
|
this.savedSelection = null;
|
1197
1231
|
}
|
1198
1232
|
}
|