youssefreda9 commited on
Commit
993d144
·
1 Parent(s): 158da8f

fix: Lists now work with pre-wrap editor - formatList() temporarily switches white-space to normal - Executes insertUnorderedList/insertOrderedList - Restores pre-wrap via requestAnimationFrame - Buttons now call formatList() instead of execFormat()

Browse files
Files changed (2) hide show
  1. src/index.html +2 -2
  2. src/js/format.js +15 -0
src/index.html CHANGED
@@ -588,10 +588,10 @@
588
  <div class="fmt-divider"></div>
589
  <!-- Item 9: Lists -->
590
  <div class="fmt-group">
591
- <button class="fmt-btn" onclick="execFormat('insertUnorderedList')" type="button" title="قائمة نقطية">
592
  <svg width="16" height="16" fill="currentColor" viewBox="0 0 24 24"><path d="M4 6h2v2H4V6zm4 0h12v2H8V6zM4 11h2v2H4v-2zm4 0h12v2H8v-2zm-4 5h2v2H4v-2zm4 0h12v2H8v-2z"/></svg>
593
  </button>
594
- <button class="fmt-btn" onclick="execFormat('insertOrderedList')" type="button" title="قائمة مرقمة">
595
  <svg width="16" height="16" fill="currentColor" viewBox="0 0 24 24"><path d="M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"/></svg>
596
  </button>
597
  </div>
 
588
  <div class="fmt-divider"></div>
589
  <!-- Item 9: Lists -->
590
  <div class="fmt-group">
591
+ <button class="fmt-btn" onclick="formatList('insertUnorderedList')" type="button" title="قائمة نقطية">
592
  <svg width="16" height="16" fill="currentColor" viewBox="0 0 24 24"><path d="M4 6h2v2H4V6zm4 0h12v2H8V6zM4 11h2v2H4v-2zm4 0h12v2H8v-2zm-4 5h2v2H4v-2zm4 0h12v2H8v-2z"/></svg>
593
  </button>
594
+ <button class="fmt-btn" onclick="formatList('insertOrderedList')" type="button" title="قائمة مرقمة">
595
  <svg width="16" height="16" fill="currentColor" viewBox="0 0 24 24"><path d="M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"/></svg>
596
  </button>
597
  </div>
src/js/format.js CHANGED
@@ -38,6 +38,21 @@ function formatAlignRight() { execFormat('justifyRight'); }
38
  function formatAlignCenter() { execFormat('justifyCenter'); }
39
  function formatAlignLeft() { execFormat('justifyLeft'); }
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  /* ── Font family ── */
42
  function formatFont(fontName) {
43
  execFormat('fontName', fontName);
 
38
  function formatAlignCenter() { execFormat('justifyCenter'); }
39
  function formatAlignLeft() { execFormat('justifyLeft'); }
40
 
41
+ /* ── Lists (need temporary white-space switch for pre-wrap editors) ── */
42
+ function formatList(command) {
43
+ const editor = getEditorElement();
44
+ if (!editor) return;
45
+ // pre-wrap blocks list creation, temporarily switch to normal
46
+ editor.style.whiteSpace = 'normal';
47
+ document.execCommand(command, false, null);
48
+ // Restore pre-wrap after browser processes the command
49
+ requestAnimationFrame(() => {
50
+ editor.style.whiteSpace = '';
51
+ });
52
+ editor.focus();
53
+ updateFormatState();
54
+ }
55
+
56
  /* ── Font family ── */
57
  function formatFont(fontName) {
58
  execFormat('fontName', fontName);