youssefreda9 commited on
Commit
9985456
·
1 Parent(s): d188337

fix: apply replaces text properly + translation shows ref + bigger font

Browse files
Files changed (1) hide show
  1. src/index.html +25 -11
src/index.html CHANGED
@@ -1278,10 +1278,19 @@
1278
  return;
1279
  }
1280
 
1281
- // Parse translation text (remove brackets)
1282
  const seg = data.matched_segment || '';
 
1283
  const transText = seg.replace(/\s*\[[^\]]+\]\s*$/, '').replace(/^\(/, '').replace(/\)$/, '');
 
 
1284
  textEl.textContent = transText;
 
 
 
 
 
 
1285
 
1286
  } catch (err) {
1287
  textEl.innerHTML = '<span class="text-secondary">حدث خطأ في الترجمة</span>';
@@ -1298,19 +1307,23 @@
1298
  if (typeof showToast === 'function') showToast('لا يوجد نص للتطبيق');
1299
  return;
1300
  }
1301
- // Restore selection and replace
 
 
 
 
 
 
 
1302
  const sel = window.getSelection();
1303
  sel.removeAllRanges();
1304
  sel.addRange(_quranSavedRange);
1305
- _quranSavedRange.deleteContents();
1306
- _quranSavedRange.insertNode(document.createTextNode(_quranVerseClean));
1307
- sel.removeAllRanges();
1308
- // Close modal
1309
- closeQuranModal();
1310
  if (typeof showToast === 'function') showToast('✓ تم تطبيق النص القرآني المدقق');
1311
- // Trigger editor update
1312
- const editor = document.getElementById('editor');
1313
- if (editor) editor.dispatchEvent(new Event('input', { bubbles: true }));
1314
  }
1315
 
1316
 
@@ -1721,7 +1734,8 @@
1721
  </select>
1722
  </div>
1723
  <div id="quran-translation-result" class="is-hidden p-4 rounded-xl" style="background:rgba(6,182,212,0.06); border:1px solid rgba(6,182,212,0.15);">
1724
- <p id="quran-translation-text" class="text-base" style="line-height:1.9; color:var(--color-text-primary);"></p>
 
1725
  </div>
1726
  </div>
1727
  </div>
 
1278
  return;
1279
  }
1280
 
1281
+ // Parse translation: "(text (ayah)) [SurahName: ayah]"
1282
  const seg = data.matched_segment || '';
1283
+ const refMatch = seg.match(/\[([^\]]+)\]/);
1284
  const transText = seg.replace(/\s*\[[^\]]+\]\s*$/, '').replace(/^\(/, '').replace(/\)$/, '');
1285
+ const transRef = refMatch ? refMatch[1] : '';
1286
+
1287
  textEl.textContent = transText;
1288
+ // Show reference in translated language
1289
+ const refEl = document.getElementById('quran-translation-ref');
1290
+ if (refEl) {
1291
+ refEl.textContent = transRef ? '[' + transRef + ']' : '';
1292
+ refEl.style.display = transRef ? '' : 'none';
1293
+ }
1294
 
1295
  } catch (err) {
1296
  textEl.innerHTML = '<span class="text-secondary">حدث خطأ في الترجمة</span>';
 
1307
  if (typeof showToast === 'function') showToast('لا يوجد نص للتطبيق');
1308
  return;
1309
  }
1310
+ const editor = document.getElementById('editor');
1311
+ if (!editor) return;
1312
+
1313
+ // Close modal first so editor can get focus
1314
+ closeQuranModal();
1315
+
1316
+ // Focus editor and restore selection
1317
+ editor.focus();
1318
  const sel = window.getSelection();
1319
  sel.removeAllRanges();
1320
  sel.addRange(_quranSavedRange);
1321
+
1322
+ // Use execCommand for proper replacement (supports undo)
1323
+ document.execCommand('insertText', false, _quranVerseClean);
1324
+
 
1325
  if (typeof showToast === 'function') showToast('✓ تم تطبيق النص القرآني المدقق');
1326
+ editor.dispatchEvent(new Event('input', { bubbles: true }));
 
 
1327
  }
1328
 
1329
 
 
1734
  </select>
1735
  </div>
1736
  <div id="quran-translation-result" class="is-hidden p-4 rounded-xl" style="background:rgba(6,182,212,0.06); border:1px solid rgba(6,182,212,0.15);">
1737
+ <p id="quran-translation-text" style="font-size:20px; line-height:2; color:var(--color-text-primary); text-align:center;"></p>
1738
+ <p id="quran-translation-ref" class="quran-reference" style="display:none;"></p>
1739
  </div>
1740
  </div>
1741
  </div>