NOT-OMEGA commited on
Commit
d65f4c3
·
verified ·
1 Parent(s): 84452a8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +28 -13
index.html CHANGED
@@ -185,7 +185,7 @@
185
  }
186
 
187
  .r-cursor { position: absolute; pointer-events: none; will-change: left, top; }
188
- .r-cursor-caret { width: 2px; height: 20px; border-radius: 1px; animation: caret-blink 1.1s ease-in-out infinite; }
189
 
190
  @keyframes caret-blink {
191
  0%, 45%, 100% { opacity: 1; }
@@ -735,17 +735,31 @@
735
  function getMirror() {
736
  if (!mirrorEl) {
737
  mirrorEl = document.createElement('div');
738
- const s = window.getComputedStyle(editor);
739
- Object.assign(mirrorEl.style, {
740
- position: 'fixed', top: '-9999px', left: '-9999px', visibility: 'hidden',
741
- fontFamily: s.fontFamily, fontSize: s.fontSize, fontWeight: s.fontWeight,
742
- lineHeight: s.lineHeight, letterSpacing: s.letterSpacing,
743
- whiteSpace: 'pre-wrap', wordWrap: 'break-word', overflowWrap: 'break-word',
744
- padding: s.padding, width: editor.clientWidth + 'px', boxSizing: 'border-box',
745
- });
746
  document.body.appendChild(mirrorEl);
747
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  mirrorEl.style.width = editor.clientWidth + 'px';
 
749
  return mirrorEl;
750
  }
751
 
@@ -758,18 +772,19 @@
758
  function getCharCoords(charIndex) {
759
  const mirror = getMirror();
760
  const text = editor.value.slice(0, charIndex);
761
- mirror.innerHTML = '';
762
- mirror.appendChild(document.createTextNode(text));
763
  const span = document.createElement('span');
764
  span.textContent = '\u200b';
765
  mirror.appendChild(span);
 
766
  const editorRect = editor.getBoundingClientRect();
767
  const pageRect = document.getElementById('page').getBoundingClientRect();
768
  const spanRect = span.getBoundingClientRect();
769
  const mirrorRect = mirror.getBoundingClientRect();
 
770
  return {
771
- x: spanRect.left - mirrorRect.left + (editorRect.left - pageRect.left),
772
- y: spanRect.top - mirrorRect.top + (editorRect.top - pageRect.top),
773
  };
774
  }
775
 
 
185
  }
186
 
187
  .r-cursor { position: absolute; pointer-events: none; will-change: left, top; }
188
+ .r-cursor-caret { width: 2px; height: 22px; border-radius: 1px; transform: translateY(4px); animation: caret-blink 1.1s ease-in-out infinite; }
189
 
190
  @keyframes caret-blink {
191
  0%, 45%, 100% { opacity: 1; }
 
735
  function getMirror() {
736
  if (!mirrorEl) {
737
  mirrorEl = document.createElement('div');
 
 
 
 
 
 
 
 
738
  document.body.appendChild(mirrorEl);
739
  }
740
+ const s = window.getComputedStyle(editor);
741
+ const props = [
742
+ 'fontFamily', 'fontSize', 'fontWeight', 'fontStyle', 'fontVariant',
743
+ 'lineHeight', 'letterSpacing', 'wordSpacing', 'textIndent', 'whiteSpace',
744
+ 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
745
+ 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth',
746
+ 'boxSizing', 'tabSize', 'textAlign', 'textTransform', 'wordBreak', 'overflowWrap'
747
+ ];
748
+
749
+ mirrorEl.style.position = 'fixed';
750
+ mirrorEl.style.top = '-9999px';
751
+ mirrorEl.style.left = '-9999px';
752
+ mirrorEl.style.visibility = 'hidden';
753
+ mirrorEl.style.overflow = 'hidden';
754
+ mirrorEl.style.whiteSpace = 'pre-wrap';
755
+ mirrorEl.style.wordWrap = 'break-word';
756
+ mirrorEl.style.overflowWrap = 'break-word';
757
+
758
+ for (const p of props) {
759
+ mirrorEl.style[p] = s[p];
760
+ }
761
  mirrorEl.style.width = editor.clientWidth + 'px';
762
+
763
  return mirrorEl;
764
  }
765
 
 
772
  function getCharCoords(charIndex) {
773
  const mirror = getMirror();
774
  const text = editor.value.slice(0, charIndex);
775
+ mirror.textContent = text;
 
776
  const span = document.createElement('span');
777
  span.textContent = '\u200b';
778
  mirror.appendChild(span);
779
+
780
  const editorRect = editor.getBoundingClientRect();
781
  const pageRect = document.getElementById('page').getBoundingClientRect();
782
  const spanRect = span.getBoundingClientRect();
783
  const mirrorRect = mirror.getBoundingClientRect();
784
+
785
  return {
786
+ x: spanRect.left - mirrorRect.left + (editorRect.left - pageRect.left) - editor.scrollLeft,
787
+ y: spanRect.top - mirrorRect.top + (editorRect.top - pageRect.top) - editor.scrollTop,
788
  };
789
  }
790