youssefreda9 commited on
Commit
d91d104
·
1 Parent(s): 7488d0f

Add 'Apply to editor' for summary panel (replaces original text with summary)

Browse files
Files changed (1) hide show
  1. src/index.html +37 -0
src/index.html CHANGED
@@ -885,6 +885,7 @@
885
  <h3 class="text-lg font-bold summary-card__title">الملخص</h3>
886
  <div class="flex items-center gap-2">
887
  <button onclick="copySummary()" class="btn-ghost" type="button">نسخ</button>
 
888
  <div class="doc-dropdown" style="display:inline-block;">
889
  <button id="summary-export-trigger" class="btn-ghost" type="button" aria-haspopup="true" aria-expanded="false">تصدير ▾</button>
890
  <div id="summary-export-menu" class="doc-dropdown__menu" role="menu">
@@ -1909,6 +1910,9 @@
1909
  // Slider moves but label stays fixed as متوسط
1910
  }
1911
 
 
 
 
1912
  async function generateSummary(event) {
1913
  var customInput = document.getElementById('summary-custom-input');
1914
  let text = customInput ? customInput.value.trim() : '';
@@ -1919,6 +1923,7 @@
1919
  document.getElementById('summary-preview').classList.add('show');
1920
  return;
1921
  }
 
1922
 
1923
  const lengthValue = document.getElementById('summary-length').value;
1924
  const isFullText = false;
@@ -1982,6 +1987,9 @@
1982
  if (typeof updateSummaryStats === 'function') {
1983
  updateSummaryStats(summaryContent);
1984
  }
 
 
 
1985
  } else {
1986
  throw new Error(data.error || 'لم يتم توليد ملخص');
1987
  }
@@ -2026,6 +2034,35 @@
2026
  });
2027
  }
2028
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2029
  function exportSummaryAsTxt() {
2030
  exportSummaryAs('txt');
2031
  }
 
885
  <h3 class="text-lg font-bold summary-card__title">الملخص</h3>
886
  <div class="flex items-center gap-2">
887
  <button onclick="copySummary()" class="btn-ghost" type="button">نسخ</button>
888
+ <button id="summary-apply-btn" onclick="applySummaryToEditor()" class="quran-apply-btn" type="button" style="display:none;">تطبيق في المحرر ✓</button>
889
  <div class="doc-dropdown" style="display:inline-block;">
890
  <button id="summary-export-trigger" class="btn-ghost" type="button" aria-haspopup="true" aria-expanded="false">تصدير ▾</button>
891
  <div id="summary-export-menu" class="doc-dropdown__menu" role="menu">
 
1910
  // Slider moves but label stays fixed as متوسط
1911
  }
1912
 
1913
+ let _summaryInput = '';
1914
+ let _summaryResult = '';
1915
+
1916
  async function generateSummary(event) {
1917
  var customInput = document.getElementById('summary-custom-input');
1918
  let text = customInput ? customInput.value.trim() : '';
 
1923
  document.getElementById('summary-preview').classList.add('show');
1924
  return;
1925
  }
1926
+ _summaryInput = text;
1927
 
1928
  const lengthValue = document.getElementById('summary-length').value;
1929
  const isFullText = false;
 
1987
  if (typeof updateSummaryStats === 'function') {
1988
  updateSummaryStats(summaryContent);
1989
  }
1990
+ _summaryResult = summaryContent;
1991
+ var applyBtn = document.getElementById('summary-apply-btn');
1992
+ if (applyBtn) applyBtn.style.display = '';
1993
  } else {
1994
  throw new Error(data.error || 'لم يتم توليد ملخص');
1995
  }
 
2034
  });
2035
  }
2036
 
2037
+ function applySummaryToEditor() {
2038
+ if (!_summaryResult) return;
2039
+ var editor = document.getElementById('editor-container');
2040
+ if (!editor) return;
2041
+ if (typeof pushUndoState === 'function') pushUndoState();
2042
+ var esc = function(t) { return t.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); };
2043
+ // Try to replace original text in editor
2044
+ if (_summaryInput) {
2045
+ var plain = editor.textContent || '';
2046
+ var idx = plain.indexOf(_summaryInput);
2047
+ if (idx !== -1) {
2048
+ var before = plain.substring(0, idx);
2049
+ var after = plain.substring(idx + _summaryInput.length);
2050
+ editor.innerHTML = esc(before) + esc(_summaryResult) + esc(after);
2051
+ editor.focus();
2052
+ editor.dispatchEvent(new Event('input', { bubbles: true }));
2053
+ switchTab('write');
2054
+ if (typeof showToast === 'function') showToast('✓ تم استبدال النص بالملخص');
2055
+ return;
2056
+ }
2057
+ }
2058
+ // Fallback: append summary
2059
+ var existing = editor.innerHTML;
2060
+ editor.innerHTML = existing + (existing ? '<br>' : '') + esc(_summaryResult);
2061
+ editor.dispatchEvent(new Event('input', { bubbles: true }));
2062
+ switchTab('write');
2063
+ if (typeof showToast === 'function') showToast('✓ تم إضافة الملخص في المحرر');
2064
+ }
2065
+
2066
  function exportSummaryAsTxt() {
2067
  exportSummaryAs('txt');
2068
  }