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.
@@ -1179,24 +1179,59 @@ class ElTextEditorComponent {
1179
1179
  inputElement.click();
1180
1180
  }
1181
1181
  }
1182
+ // setTextColor(event: any) {
1183
+ // if (this.savedSelection) {
1184
+ // const color = event.target.value;
1185
+ // this.selectedTextColor = color;
1186
+ // // Restore the saved selection
1187
+ // const selection = window.getSelection();
1188
+ // if (selection) {
1189
+ // selection.removeAllRanges();
1190
+ // selection.addRange(this.savedSelection);
1191
+ // // Apply the color using a span
1192
+ // const range = this.savedSelection;
1193
+ // const span = document.createElement('span');
1194
+ // span.style.color = color;
1195
+ // span.textContent = range.toString();
1196
+ // // Replace the selected text with the styled span
1197
+ // range.deleteContents();
1198
+ // range.insertNode(span);
1199
+ // // Clear the saved selection
1200
+ // this.savedSelection = null;
1201
+ // }
1202
+ // }
1203
+ // }
1182
1204
  setTextColor(event) {
1183
1205
  if (this.savedSelection) {
1184
1206
  const color = event.target.value;
1185
1207
  this.selectedTextColor = color;
1186
1208
  // Restore the saved selection
1187
1209
  const selection = window.getSelection();
1188
- if (selection) {
1189
- selection.removeAllRanges();
1190
- selection.addRange(this.savedSelection);
1191
- // Apply the color using a span
1210
+ if (selection && selection.rangeCount > 0) {
1192
1211
  const range = this.savedSelection;
1193
- const span = document.createElement('span');
1194
- span.style.color = color;
1195
- span.textContent = range.toString();
1196
- // Replace the selected text with the styled span
1212
+ selection.removeAllRanges();
1213
+ selection.addRange(range);
1214
+ // Get selected elements
1215
+ const selectedContent = range.cloneContents();
1216
+ const elements = Array.from(selectedContent.querySelectorAll("*")); // ✅ Explicitly cast to HTMLElement[]
1217
+ // Apply color to each element without modifying structure
1218
+ elements.forEach((el) => {
1219
+ el.style.color = color;
1220
+ });
1221
+ // Apply color to the top-level text nodes (without wrapping them)
1222
+ Array.from(selectedContent.childNodes).forEach((node) => {
1223
+ var _a;
1224
+ if (node.nodeType === Node.TEXT_NODE && ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== "") {
1225
+ const parent = range.commonAncestorContainer.parentElement;
1226
+ if (parent) {
1227
+ parent.style.color = color;
1228
+ }
1229
+ }
1230
+ });
1231
+ // Replace selected content
1197
1232
  range.deleteContents();
1198
- range.insertNode(span);
1199
- // Clear the saved selection
1233
+ range.insertNode(selectedContent);
1234
+ // Clear saved selection
1200
1235
  this.savedSelection = null;
1201
1236
  }
1202
1237
  }