Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
clean and log ops
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Sep 15, 2024
1 parent 27de386 commit ee90fad
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
const editor_lines = editor.querySelector('.editor-lines');

const handleBlur = () => {
// Remove active class when editor loses focus
editor_code.querySelectorAll('.line').forEach(line => line.classList.remove('active'));
editor_lines.querySelectorAll('li').forEach(li => li.classList.remove('active'));
};
Expand All @@ -98,6 +97,7 @@

editor_code.querySelectorAll('.line').forEach(line => line.classList.remove('active'));
editor_lines.querySelectorAll('li').forEach(li => li.classList.remove('active'));

if (activeLine) {
activeLine.classList.add('active');

Expand All @@ -113,6 +113,7 @@

lines.forEach((_, index) => {
const lineItem = document.createElement('li');

lineItem.textContent = index + 1;
editor_lines.appendChild(lineItem);
});
Expand All @@ -121,6 +122,7 @@
const getLeadingSpaces = (lineElement) => {
const lineText = lineElement.textContent;
const leadingSpaces = lineText.match(/^\s*/)[0].length;

return leadingSpaces;
};

Expand Down Expand Up @@ -178,11 +180,11 @@
scrollIntoViewIfNeeded(newLine);

const newRange = document.createRange();
newRange.setStart(newLine, 1);
newRange.setEnd(newLine, 1);
// newRange.setStart(newLine, 1);
// newRange.setEnd(newLine, 1);
// or?
// newRange.setStart(newLine, 0);
// newRange.setEnd(newLine, 0);
newRange.setStart(newLine, 0);
newRange.setEnd(newLine, 0);

const newSelection = window.getSelection();
newSelection.removeAllRanges();
Expand All @@ -195,12 +197,16 @@

if (event.key === 'Enter') {
event.preventDefault();

handleKeyLine();

updateLineNumbers();
}
else if (event.key === 'Tab') {
event.preventDefault();

handleKeyTab();

// updateLineNumbers();
}
};
Expand All @@ -217,6 +223,7 @@

const opsReg = `(${ops.join('|')})`;
const opsRegex = new RegExp(opsReg, 'g');
console.log(opsReg, opsRegex);
code = code.replace(opsRegex, '<span class=operator>$&</span>');

return code;
Expand Down Expand Up @@ -250,6 +257,13 @@

const handleFocus = () => {
updateLineNumbers();

const selection = window.getSelection();
const activeLine = selection.anchorNode.closest('.line');

if (activeLine) {
activeLine.classList.add('active');
}
};

editor_code.addEventListener('paste', handlePaste);
Expand All @@ -259,7 +273,6 @@
editor_code.addEventListener('keydown', handleKey);
editor_code.addEventListener('input', splitLines);


editor_code.innerHTML = '<div class="line"><br></div>';
editor_code.focus();

Expand Down

0 comments on commit ee90fad

Please sign in to comment.