์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿ› ๏ธ ๋‚˜๋งŒ์˜ ๋ฏธ๋‹ˆ IDE/์—๋””ํ„ฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๊ธฐ์†Œ์Šค์ฝ”๋“œ๋กœ ๋ฐฐ์šฐ๋Š” ํ…์ŠคํŠธ ์—๋””ํ„ฐ์˜ ๋ชจ๋“  ๊ฒƒ
๐Ÿ’ป ํ”„๋กœ๊ทธ๋žจ/์†Œ์Šค ยท ํ”„๋กœ๊ทธ๋žจ๊ฐœ๋ฐœ

๐Ÿ› ๏ธ ๋‚˜๋งŒ์˜ ๋ฏธ๋‹ˆ IDE/์—๋””ํ„ฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๊ธฐ
์†Œ์Šค์ฝ”๋“œ๋กœ ๋ฐฐ์šฐ๋Š” ํ…์ŠคํŠธ ์—๋””ํ„ฐ์˜ ๋ชจ๋“  ๊ฒƒ

โœจ ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ…๋ถ€ํ„ฐ ์ž๋™์™„์„ฑ๊นŒ์ง€ ์ง์ ‘ ๋งŒ๋“ค์–ด๋ณด์ž!
์•ผ ๊ทผ๋ฐ IDE ๋งŒ๋“œ๋Š” ๊ฑฐ ์—„์ฒญ ์–ด๋ ต์ง€ ์•Š์•„? ๐Ÿค”
ใ„ดใ„ด ํ•ต์‹ฌ ๊ธฐ๋Šฅ๋งŒ ๊ตฌํ˜„ํ•˜๋ฉด ์ƒ๊ฐ๋ณด๋‹ค ํ• ๋งŒํ•จ ใ…‹ใ…‹ ์˜ค๋Š˜ ๊ฐ™์ด ํŒŒ๋ณด์ž!
์˜ค ์ง„์งœ? ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ…์ด๋‚˜ ์ž๋™์™„์„ฑ ๊ฐ™์€ ๊ฑฐ๋„?
์‘์‘! ์†Œ์Šค์ฝ”๋“œ ์ง์ ‘ ๋ณด๋ฉด์„œ ํ•˜๋‚˜์”ฉ ๋œฏ์–ด๋ณผ ๊ฑฐ์ž„ ๐Ÿ”ฅ

IDE(ํ†ตํ•ฉ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ)๋‚˜ ์ฝ”๋“œ ์—๋””ํ„ฐ๋Š” ๊ฐœ๋ฐœ์ž๋“ค์ด ๋งค์ผ ์“ฐ๋Š” ํ•ต์‹ฌ ๋„๊ตฌ์ธ๋ฐ, ๋ง‰์ƒ "์ด๊ฑฐ ์–ด๋–ป๊ฒŒ ๋งŒ๋“ค์–ด?" ํ•˜๋ฉด ๋ง‰๋ง‰ํ•˜๊ฒŒ ๋А๊ปด์ง€๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์ฃ . ๊ทผ๋ฐ ์‚ฌ์‹ค ํ•ต์‹ฌ ๊ธฐ๋Šฅ๋“ค์„ ๋ถ„ํ•ดํ•ด์„œ ๋ณด๋ฉด ํ•˜๋‚˜ํ•˜๋‚˜๋Š” ๊ทธ๋ ‡๊ฒŒ ๋ณต์žกํ•˜์ง€ ์•Š์•„์š”! ์˜ค๋Š˜์€ ๊ฐ„๋‹จํ•œ IDE/์—๋””ํ„ฐ์˜ ์ฃผ์š” ๊ธฐ๋Šฅ๋“ค์„ ์‹ค์ œ ์†Œ์Šค์ฝ”๋“œ์™€ ํ•จ๊ป˜ ๋œฏ์–ด๋ณผ ๊ฑฐ์˜ˆ์š”. ๐ŸŽฏ

๐Ÿ› ๏ธ ๋ฏธ๋‹ˆ IDE์˜ ํ•ต์‹ฌ ๊ตฌ์„ฑ์š”์†Œ ๊ฐ ๊ธฐ๋Šฅ์„ ๋…๋ฆฝ ๋ชจ๋“ˆ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด ๊ด€๋ฆฌ๊ฐ€ ์‰ฌ์›Œ์š”! IDE ์ฝ”์–ด ์—”์ง„ ๐ŸŽจ ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ… โšก ์ž๋™์™„์„ฑ AutoComplete ๐Ÿ”ข ์ค„ ๋ฒˆํ˜ธ Line Numbers ๐Ÿ”— ๊ด„ํ˜ธ ๋งค์นญ Bracket Match ๐Ÿ” ๊ฒ€์ƒ‰ & ์น˜ํ™˜ (Find & Replace)

๐Ÿ“ 1. ๊ธฐ๋ณธ ์—๋””ํ„ฐ ๊ตฌ์กฐ ์žก๊ธฐ

์ผ๋‹จ ์—๋””ํ„ฐ์˜ ๋ผˆ๋Œ€๋ถ€ํ„ฐ ๋งŒ๋“ค์–ด์•ผ์ฃ ! HTML + CSS + JavaScript๋กœ ๊ธฐ๋ณธ ๊ตฌ์กฐ๋ฅผ ์žก๋Š” ๊ฒŒ ์ฒซ ๋ฒˆ์งธ ์Šคํ…์ด์—์š”. contenteditable ์†์„ฑ์ด๋‚˜ textarea๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋Š”๋ฐ, ๊ฐ๊ฐ ์žฅ๋‹จ์ ์ด ์žˆ์–ด์š”.

๐Ÿ’ก ๊ฟ€ํŒ! ๊ฐ„๋‹จํ•œ ์—๋””ํ„ฐ๋Š” textarea๋กœ ์‹œ์ž‘ํ•˜๊ณ , ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ…์ด ํ•„์š”ํ•˜๋ฉด contenteditable div๋กœ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋Š” ๊ฒŒ ๊ตญ๋ฃฐ์ž„ ใ…‹ใ…‹

1HTML ๊ธฐ๋ณธ ๊ตฌ์กฐ

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <title>๋ฏธ๋‹ˆ ์ฝ”๋“œ ์—๋””ํ„ฐ</title>
  <style>
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body { background: #1e1e1e; color: #d4d4d4; font-family: 'Consolas', monospace; }

    .editor-container {
      display: flex;
      height: 100vh;
      overflow: hidden;
    }

    /* ์‚ฌ์ด๋“œ๋ฐ” (ํŒŒ์ผ ํŠธ๋ฆฌ) */
    .sidebar {
      width: 220px;
      background: #252526;
      border-right: 1px solid #3c3c3c;
      padding: 10px;
      overflow-y: auto;
    }

    /* ๋ฉ”์ธ ์—๋””ํ„ฐ ์˜์—ญ */
    .editor-main {
      flex: 1;
      display: flex;
      flex-direction: column;
    }

    /* ํƒญ ๋ฐ” */
    .tab-bar {
      background: #2d2d2d;
      display: flex;
      border-bottom: 1px solid #3c3c3c;
      min-height: 35px;
    }

    .tab {
      padding: 8px 20px;
      cursor: pointer;
      border-right: 1px solid #3c3c3c;
      font-size: 13px;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .tab.active {
      background: #1e1e1e;
      border-top: 2px solid #007acc;
    }

    /* ์—๋””ํ„ฐ ๋ณธ์ฒด */
    .editor-body {
      flex: 1;
      display: flex;
      overflow: hidden;
    }

    /* ์ค„ ๋ฒˆํ˜ธ */
    .line-numbers {
      width: 50px;
      background: #1e1e1e;
      color: #858585;
      text-align: right;
      padding: 10px 8px;
      font-size: 14px;
      line-height: 1.6;
      user-select: none;
      overflow: hidden;
    }

    /* ์ฝ”๋“œ ์ž…๋ ฅ ์˜์—ญ */
    .code-area {
      flex: 1;
      background: #1e1e1e;
      color: #d4d4d4;
      border: none;
      outline: none;
      padding: 10px;
      font-size: 14px;
      line-height: 1.6;
      font-family: 'Consolas', monospace;
      resize: none;
      overflow: auto;
      tab-size: 2;
    }

    /* ์ƒํƒœ๋ฐ” */
    .status-bar {
      background: #007acc;
      color: #fff;
      padding: 3px 15px;
      font-size: 12px;
      display: flex;
      gap: 20px;
    }
  </style>
</head>
<body>
  <div class="editor-container">
    <div class="sidebar" id="sidebar">
      <div style="color:#ccc;font-size:12px;margin-bottom:8px;">๐Ÿ“ ํƒ์ƒ‰๊ธฐ</div>
      <!-- ํŒŒ์ผ ํŠธ๋ฆฌ๊ฐ€ ์—ฌ๊ธฐ์— ๋™์ ์œผ๋กœ ์ƒ์„ฑ๋จ -->
    </div>
    <div class="editor-main">
      <div class="tab-bar" id="tabBar"></div>
      <div class="editor-body">
        <div class="line-numbers" id="lineNumbers">1</div>
        <textarea class="code-area" id="codeArea"
          spellcheck="false"
          autocomplete="off"
          autocorrect="off"
          autocapitalize="off"></textarea>
      </div>
      <div class="status-bar">
        <span id="cursorPos">์ค„ 1, ์—ด 1</span>
        <span id="langMode">JavaScript</span>
        <span>UTF-8</span>
      </div>
    </div>
  </div>
</body>
</html>
โœ… ํฌ์ธํŠธ! spellcheck="false", autocomplete="off" ์ด๋Ÿฐ ์†์„ฑ๋“ค ๊ผญ ๋„ฃ์–ด์ค˜์•ผ ํ•ด์š”. ์•ˆ ๋„ฃ์œผ๋ฉด ์ฝ”๋“œ ์ž‘์„ฑํ•  ๋•Œ ์ž๊พธ ๋นจ๊ฐ„ ์ค„ ๋œจ๊ณ  ์ž๋™์ˆ˜์ • ๋˜๋Š” ๋ถˆ์ƒ์‚ฌ๊ฐ€... ๐Ÿ˜…

๐Ÿ”ข 2. ์ค„ ๋ฒˆํ˜ธ(Line Numbers) ๊ตฌํ˜„

์ค„ ๋ฒˆํ˜ธ๋Š” ์—๋””ํ„ฐ์˜ ๊ธฐ๋ณธ ์ค‘์˜ ๊ธฐ๋ณธ! ๊ทผ๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ์‹ ๊ฒฝ ์จ์•ผ ํ•  ๊ฒŒ ์žˆ์–ด์š”. ์Šคํฌ๋กค ๋™๊ธฐํ™”, ์ค„ ์ˆ˜ ์—…๋ฐ์ดํŠธ ๋“ฑ๋“ฑ... ๊ฐ™์ด ๊ตฌํ˜„ํ•ด๋ด์š” ใ…Žใ…Ž

// ์ค„ ๋ฒˆํ˜ธ ์—…๋ฐ์ดํŠธ ํ•จ์ˆ˜
function updateLineNumbers() {
  const codeArea = document.getElementById('codeArea');
  const lineNumbers = document.getElementById('lineNumbers');

  // ํ˜„์žฌ ์ฝ”๋“œ์˜ ์ค„ ์ˆ˜ ๊ณ„์‚ฐ
  const lines = codeArea.value.split('\n');
  const lineCount = lines.length;

  // ์ค„ ๋ฒˆํ˜ธ HTML ์ƒ์„ฑ
  let numbersHTML = '';
  for (let i = 1; i <= lineCount; i++) {
    numbersHTML += `<div class="line-num">${i}</div>`;
  }
  lineNumbers.innerHTML = numbersHTML;
}

// ์Šคํฌ๋กค ๋™๊ธฐํ™” (ํ•ต์‹ฌ!)
function syncScroll() {
  const codeArea = document.getElementById('codeArea');
  const lineNumbers = document.getElementById('lineNumbers');

  codeArea.addEventListener('scroll', () => {
    // ์ค„ ๋ฒˆํ˜ธ ์˜์—ญ์˜ ์Šคํฌ๋กค์„ ์ฝ”๋“œ ์˜์—ญ๊ณผ ๋™๊ธฐํ™”
    lineNumbers.scrollTop = codeArea.scrollTop;
  });
}

// ์ปค์„œ ์œ„์น˜ ํ‘œ์‹œ
function updateCursorPosition() {
  const codeArea = document.getElementById('codeArea');
  const cursorPos = document.getElementById('cursorPos');

  codeArea.addEventListener('keyup', () => {
    const text = codeArea.value;
    const selStart = codeArea.selectionStart;

    // ํ˜„์žฌ ์ปค์„œ๊นŒ์ง€์˜ ํ…์ŠคํŠธ์—์„œ ์ค„/์—ด ๊ณ„์‚ฐ
    const textBeforeCursor = text.substring(0, selStart);
    const lines = textBeforeCursor.split('\n');
    const currentLine = lines.length;
    const currentCol = lines[lines.length - 1].length + 1;

    cursorPos.textContent = `์ค„ ${currentLine}, ์—ด ${currentCol}`;
  });
}

// ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
document.addEventListener('DOMContentLoaded', () => {
  const codeArea = document.getElementById('codeArea');

  // ์ž…๋ ฅํ•  ๋•Œ๋งˆ๋‹ค ์ค„ ๋ฒˆํ˜ธ ์—…๋ฐ์ดํŠธ
  codeArea.addEventListener('input', updateLineNumbers);
  codeArea.addEventListener('keyup', updateLineNumbers);

  syncScroll();
  updateCursorPosition();
  updateLineNumbers(); // ์ดˆ๊ธฐ ์‹คํ–‰
});
๐Ÿ’ก ์„ฑ๋Šฅ ํŒ! ์ค„์ด ์ˆ˜์ฒœ ๊ฐœ ๋„˜์–ด๊ฐ€๋ฉด DOM ์—…๋ฐ์ดํŠธ๊ฐ€ ๋А๋ ค์งˆ ์ˆ˜ ์žˆ์–ด์š”. ์ด๋Ÿด ๋• ๊ฐ€์ƒ ์Šคํฌ๋กค๋ง(Virtual Scrolling) ๊ธฐ๋ฒ•์„ ์จ์•ผ ํ•˜๋Š”๋ฐ, ํ™”๋ฉด์— ๋ณด์ด๋Š” ์ค„๋งŒ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ์‹์ด์—์š”. ์‹ค์ œ VS Code๋„ ์ด ๋ฐฉ์‹ ์”€ ใ„ทใ„ท

๐ŸŽจ 3. ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ… ๊ตฌํ˜„

์ด๊ฒŒ ์—๋””ํ„ฐ์˜ ๊ฝƒ์ด์ฃ ! ๐ŸŒธ ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ…์€ ์ •๊ทœ์‹(RegEx)์„ ํ™œ์šฉํ•ด์„œ ํ‚ค์›Œ๋“œ, ๋ฌธ์ž์—ด, ์ฃผ์„ ๋“ฑ์„ ์ƒ‰๊น”๋กœ ๊ตฌ๋ถ„ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ด์—์š”. textarea๋งŒ์œผ๋กœ๋Š” ๊ตฌํ˜„์ด ์–ด๋ ต๊ณ , ์˜ค๋ฒ„๋ ˆ์ด ๋ฐฉ์‹์ด๋‚˜ contenteditable ๋ฐฉ์‹์„ ์จ์•ผ ํ•ด์š”.

1์˜ค๋ฒ„๋ ˆ์ด(Overlay) ๋ฐฉ์‹ - ๊ฐ€์žฅ ๋งŽ์ด ์“ฐ๋Š” ๋ฐฉ๋ฒ•

// JavaScript ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ… ํ† ํฌ๋‚˜์ด์ €
const JS_TOKENS = [
  // ์ฃผ์„ (๋จผ์ € ์ฒ˜๋ฆฌํ•ด์•ผ ํ•จ!)
  { type: 'comment', regex: /\/\/[^\n]*/g, color: '#6a9955' },
  { type: 'comment-block', regex: /\/\*[\s\S]*?\*\//g, color: '#6a9955' },
  // ๋ฌธ์ž์—ด
  { type: 'string', regex: /(["'`])(?:(?!\1)[^\\]|\\.)*\1/g, color: '#ce9178' },
  // ํ‚ค์›Œ๋“œ
  {
    type: 'keyword',
    regex: /\b(const|let|var|function|return|if|else|for|while|class|import|export|from|async|await|new|this|typeof|instanceof|null|undefined|true|false)\b/g,
    color: '#569cd6'
  },
  // ์ˆซ์ž
  { type: 'number', regex: /\b\d+(\.\d+)?\b/g, color: '#b5cea8' },
  // ํ•จ์ˆ˜๋ช…
  { type: 'function', regex: /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*(?=\()/g, color: '#dcdcaa' },
  // ๋‚ด์žฅ ๊ฐ์ฒด
  {
    type: 'builtin',
    regex: /\b(console|document|window|Array|Object|String|Number|Math|JSON|Promise|setTimeout|setInterval)\b/g,
    color: '#4ec9b0'
  }
];

// ํ•˜์ด๋ผ์ดํŒ… ์ ์šฉ ํ•จ์ˆ˜
function applyHighlighting(code) {
  // HTML ํŠน์ˆ˜๋ฌธ์ž ์ด์Šค์ผ€์ดํ”„ (XSS ๋ฐฉ์ง€!)
  let escaped = code
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;');

  // ํ† ํฐ ์œ„์น˜ ์ˆ˜์ง‘
  const tokens = [];

  JS_TOKENS.forEach(tokenDef => {
    let match;
    const regex = new RegExp(tokenDef.regex.source, 'g');
    while ((match = regex.exec(escaped)) !== null) {
      tokens.push({
        start: match.index,
        end: match.index + match[0].length,
        text: match[0],
        color: tokenDef.color,
        type: tokenDef.type
      });
    }
  });

  // ๊ฒน์น˜๋Š” ํ† ํฐ ์ œ๊ฑฐ (๋จผ์ € ๋ฐœ๊ฒฌ๋œ ๊ฒƒ ์šฐ์„ )
  tokens.sort((a, b) => a.start - b.start);
  const filtered = [];
  let lastEnd = 0;
  tokens.forEach(token => {
    if (token.start >= lastEnd) {
      filtered.push(token);
      lastEnd = token.end;
    }
  });

  // HTML ์ƒ์„ฑ
  let result = '';
  let pos = 0;
  filtered.forEach(token => {
    // ํ† ํฐ ์ด์ „ ์ผ๋ฐ˜ ํ…์ŠคํŠธ
    result += escaped.substring(pos, token.start);
    // ์ƒ‰์ƒ ์ ์šฉ๋œ ํ† ํฐ
    result += `<span style="color:${token.color}">${token.text}</span>`;
    pos = token.end;
  });
  result += escaped.substring(pos);

  return result;
}

// ์˜ค๋ฒ„๋ ˆ์ด ์—๋””ํ„ฐ ์„ค์ •
function setupOverlayEditor() {
  const textarea = document.getElementById('codeArea');
  const highlight = document.getElementById('highlightLayer');

  textarea.addEventListener('input', () => {
    // ํ•˜์ด๋ผ์ดํŒ… ๋ ˆ์ด์–ด ์—…๋ฐ์ดํŠธ
    highlight.innerHTML = applyHighlighting(textarea.value) + '\n';
    updateLineNumbers();
  });

  // ์Šคํฌ๋กค ๋™๊ธฐํ™”
  textarea.addEventListener('scroll', () => {
    highlight.scrollTop = textarea.scrollTop;
    highlight.scrollLeft = textarea.scrollLeft;
  });
}
โš ๏ธ ์ฃผ์˜! ์ •๊ทœ์‹ ๊ธฐ๋ฐ˜ ํ•˜์ด๋ผ์ดํŒ…์€ ๊ฐ„๋‹จํ•œ ์ผ€์ด์Šค์—” ์ž˜ ๋™์ž‘ํ•˜์ง€๋งŒ, ๋ณต์žกํ•œ ์ฝ”๋“œ์—์„œ ์˜ค์ž‘๋™ํ•  ์ˆ˜ ์žˆ์–ด์š”. ์‹ค์ œ ํ”„๋กœ๋•์…˜์—์„œ๋Š” Prism.js๋‚˜ highlight.js ๊ฐ™์€ ๊ฒ€์ฆ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ๋Š” ๊ฒŒ ํ›จ์”ฌ ๋‚˜์•„์š” ใ…‹ใ…‹
๐ŸŽจ ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ… ๋™์ž‘ ์›๋ฆฌ app.js 1 2 3 4 5 6 7 8 const greeting = "Hello, World!" ; // ์ธ์‚ฌ ํ•จ์ˆ˜ ์ •์˜ function sayHello (name) { const msg = `์•ˆ๋…•, ${"{name}"}!` ; console . log (msg); return msg; } sayHello ( "๊ฐœ๋ฐœ์ž" ); ํ‚ค์›Œ๋“œ ๋ฌธ์ž์—ด ์ฃผ์„ ํ•จ์ˆ˜๋ช… ๋‚ด์žฅ๊ฐ์ฒด

โšก 4. ์ž๋™์™„์„ฑ(AutoComplete) ๊ตฌํ˜„

์ž๋™์™„์„ฑ์€ ๊ฐœ๋ฐœ ์ƒ์‚ฐ์„ฑ์„ ์—„์ฒญ๋‚˜๊ฒŒ ์˜ฌ๋ ค์ฃผ๋Š” ๊ธฐ๋Šฅ์ด์—์š”! ๊ธฐ๋ณธ์ ์ธ ์›๋ฆฌ๋Š” ํ˜„์žฌ ์ž…๋ ฅ ์ค‘์ธ ๋‹จ์–ด๋ฅผ ๊ฐ์ง€ํ•˜๊ณ , ๋ฏธ๋ฆฌ ์ •์˜๋œ ๋‹จ์–ด ๋ชฉ๋ก์—์„œ ๋งค์นญ๋˜๋Š” ๊ฒƒ๋“ค์„ ๋“œ๋กญ๋‹ค์šด์œผ๋กœ ๋ณด์—ฌ์ฃผ๋Š” ๊ฑฐ์˜ˆ์š”.

// ์ž๋™์™„์„ฑ ์‹œ์Šคํ…œ ๊ตฌํ˜„
class AutoComplete {
  constructor(editor) {
    this.editor = editor;
    this.dropdown = null;
    this.selectedIndex = -1;

    // ์ž๋™์™„์„ฑ ๋‹จ์–ด ๋ชฉ๋ก (์‹ค์ œ๋กœ๋Š” ์–ธ์–ด๋ณ„๋กœ ๋” ๋ฐฉ๋Œ€ํ•จ)
    this.keywords = [
      'const', 'let', 'var', 'function', 'return', 'if', 'else',
      'for', 'while', 'class', 'import', 'export', 'async', 'await',
      'console', 'document', 'window', 'Array', 'Object', 'String',
      'Promise', 'setTimeout', 'addEventListener', 'querySelector',
      'getElementById', 'innerHTML', 'textContent', 'appendChild'
    ];

    this.init();
  }

  init() {
    // ๋“œ๋กญ๋‹ค์šด ์—˜๋ฆฌ๋จผํŠธ ์ƒ์„ฑ
    this.dropdown = document.createElement('div');
    this.dropdown.className = 'autocomplete-dropdown';
    this.dropdown.style.cssText = `
      position: absolute;
      background: #252526;
      border: 1px solid #454545;
      border-radius: 4px;
      max-height: 200px;
      overflow-y: auto;
      z-index: 1000;
      display: none;
      min-width: 180px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    `;
    document.body.appendChild(this.dropdown);

    // ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ๋“ฑ๋ก
    this.editor.addEventListener('input', (e) => this.handleInput(e));
    this.editor.addEventListener('keydown', (e) => this.handleKeydown(e));
    document.addEventListener('click', () => this.hide());
  }

  // ํ˜„์žฌ ์ปค์„œ ์œ„์น˜์˜ ๋‹จ์–ด ์ถ”์ถœ
  getCurrentWord() {
    const text = this.editor.value;
    const pos = this.editor.selectionStart;
    const textBefore = text.substring(0, pos);

    // ๋งˆ์ง€๋ง‰ ๋‹จ์–ด ์ถ”์ถœ (์˜๋ฌธ์ž, ์ˆซ์ž, _ ๋งŒ ํฌํ•จ)
    const match = textBefore.match(/[a-zA-Z_$][a-zA-Z0-9_$]*$/);
    return match ? match[0] : '';
  }

  // ๋งค์นญ ๋‹จ์–ด ๊ฒ€์ƒ‰
  getMatches(word) {
    if (word.length < 2) return []; // 2๊ธ€์ž ์ด์ƒ๋ถ€ํ„ฐ ๊ฒ€์ƒ‰
    const lower = word.toLowerCase();
    return this.keywords
      .filter(kw => kw.toLowerCase().startsWith(lower) && kw !== word)
      .slice(0, 10); // ์ตœ๋Œ€ 10๊ฐœ
  }

  // ์ž…๋ ฅ ์ฒ˜๋ฆฌ
  handleInput() {
    const word = this.getCurrentWord();
    const matches = this.getMatches(word);

    if (matches.length > 0) {
      this.show(matches, word);
    } else {
      this.hide();
    }
  }

  // ๋“œ๋กญ๋‹ค์šด ํ‘œ์‹œ
  show(matches, currentWord) {
    this.selectedIndex = -1;
    this.dropdown.innerHTML = '';

    matches.forEach((match, index) => {
      const item = document.createElement('div');
      item.style.cssText = `
        padding: 6px 12px;
        cursor: pointer;
        font-family: Consolas, monospace;
        font-size: 13px;
        color: #d4d4d4;
        display: flex;
        align-items: center;
        gap: 8px;
      `;

      // ๋งค์นญ ๋ถ€๋ถ„ ๋ณผ๋“œ ์ฒ˜๋ฆฌ
      const boldPart = match.substring(0, currentWord.length);
      const restPart = match.substring(currentWord.length);
      item.innerHTML = `
        <span style="color:#007acc;font-size:11px;">โšก</span>
        <span><strong style="color:#fff">${boldPart}</strong>${restPart}</span>
      `;

      item.addEventListener('mouseenter', () => {
        this.setSelected(index);
      });

      item.addEventListener('click', () => {
        this.applyCompletion(match, currentWord);
      });

      this.dropdown.appendChild(item);
    });

    // ์ปค์„œ ์œ„์น˜์— ๋“œ๋กญ๋‹ค์šด ํ‘œ์‹œ
    const coords = this.getCursorCoords();
    this.dropdown.style.left = coords.x + 'px';
    this.dropdown.style.top = (coords.y + 20) + 'px';
    this.dropdown.style.display = 'block';
  }

  // ํ‚ค๋ณด๋“œ ๋„ค๋น„๊ฒŒ์ด์…˜
  handleKeydown(e) {
    if (this.dropdown.style.display === 'none') return;

    const items = this.dropdown.querySelectorAll('div');

    if (e.key === 'ArrowDown') {
      e.preventDefault();
      this.setSelected(Math.min(this.selectedIndex + 1, items.length - 1));
    } else if (e.key === 'ArrowUp') {
      e.preventDefault();
      this.setSelected(Math.max(this.selectedIndex - 1, 0));
    } else if (e.key === 'Enter' || e.key === 'Tab') {
      if (this.selectedIndex >= 0) {
        e.preventDefault();
        const selectedText = items[this.selectedIndex]
          .querySelector('span:last-child').textContent;
        this.applyCompletion(selectedText, this.getCurrentWord());
      }
    } else if (e.key === 'Escape') {
      this.hide();
    }
  }

  // ์„ ํƒ ํ•ญ๋ชฉ ๋ณ€๊ฒฝ
  setSelected(index) {
    const items = this.dropdown.querySelectorAll('div');
    items.forEach((item, i) => {
      item.style.background = i === index ? '#094771' : 'transparent';
    });
    this.selectedIndex = index;
  }

  // ์ž๋™์™„์„ฑ ์ ์šฉ
  applyCompletion(completion, currentWord) {
    const pos = this.editor.selectionStart;
    const text = this.editor.value;
    const start = pos - currentWord.length;

    // ํ˜„์žฌ ๋‹จ์–ด๋ฅผ ์™„์„ฑ๋œ ๋‹จ์–ด๋กœ ๊ต์ฒด
    this.editor.value =
      text.substring(0, start) + completion + text.substring(pos);

    // ์ปค์„œ๋ฅผ ์™„์„ฑ๋œ ๋‹จ์–ด ๋์œผ๋กœ ์ด๋™
    const newPos = start + completion.length;
    this.editor.setSelectionRange(newPos, newPos);
    this.editor.focus();
    this.hide();
  }

  hide() {
    this.dropdown.style.display = 'none';
    this.selectedIndex = -1;
  }

  // ์ปค์„œ ์ขŒํ‘œ ๊ณ„์‚ฐ (๊ฐ„๋žตํ™” ๋ฒ„์ „)
  getCursorCoords() {
    const rect = this.editor.getBoundingClientRect();
    return {
      x: rect.left + 80,
      y: rect.top + 100
    };
  }
}

// ์‚ฌ์šฉ
const editor = document.getElementById('codeArea');
const ac = new AutoComplete(editor);

๐Ÿ” 5. ๊ฒ€์ƒ‰ & ์น˜ํ™˜(Find & Replace) ๊ตฌํ˜„

Ctrl+F ํ•˜๋ฉด ๋œจ๋Š” ๊ทธ ๊ธฐ๋Šฅ! ์—๋””ํ„ฐ์—์„œ ์—†์œผ๋ฉด ์ง„์งœ ๋ถˆํŽธํ•œ ๊ธฐ๋Šฅ ์ค‘ ํ•˜๋‚˜์ฃ . ์ •๊ทœ์‹ ๊ฒ€์ƒ‰๊นŒ์ง€ ์ง€์›ํ•˜๋ฉด ์™„์ „ ํ”„๋กœ ์—๋””ํ„ฐ ๋А๋‚Œ ๋‚˜์š” ใ…‹ใ…‹ใ…‹

// ๊ฒ€์ƒ‰ & ์น˜ํ™˜ ๋ชจ๋“ˆ
class FindReplace {
  constructor(editor) {
    this.editor = editor;
    this.matches = [];
    this.currentMatch = -1;
    this.createUI();
    this.bindShortcuts();
  }

  createUI() {
    const panel = document.createElement('div');
    panel.id = 'findPanel';
    panel.style.cssText = `
      position: fixed;
      top: 50px;
      right: 20px;
      background: #252526;
      border: 1px solid #454545;
      border-radius: 8px;
      padding: 12px;
      z-index: 2000;
      display: none;
      min-width: 320px;
      box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    `;

    panel.innerHTML = `
      <div style="display:flex;gap:8px;margin-bottom:8px;align-items:center;">
        <input id="findInput" placeholder="๊ฒ€์ƒ‰..." style="
          flex:1; background:#3c3c3c; border:1px solid #555;
          color:#d4d4d4; padding:5px 10px; border-radius:4px;
          font-size:13px; outline:none;
        ">
        <button id="findPrev" style="background:#3c3c3c;color:#ccc;border:1px solid #555;
          border-radius:4px;padding:5px 10px;cursor:pointer;">โ†‘</button>
        <button id="findNext" style="background:#3c3c3c;color:#ccc;border:1px solid #555;
          border-radius:4px;padding:5px 10px;cursor:pointer;">โ†“</button>
        <span id="matchCount" style="color:#858585;font-size:12px;min-width:60px;"></span>
        <button id="closeFind" style="background:transparent;color:#ccc;border:none;
          cursor:pointer;font-size:16px;">โœ•</button>
      </div>
      <div style="display:flex;gap:8px;align-items:center;">
        <input id="replaceInput" placeholder="์น˜ํ™˜..." style="
          flex:1; background:#3c3c3c; border:1px solid #555;
          color:#d4d4d4; padding:5px 10px; border-radius:4px;
          font-size:13px; outline:none;
        ">
        <button id="replaceOne" style="background:#007acc;color:#fff;border:none;
          border-radius:4px;padding:5px 12px;cursor:pointer;font-size:12px;">์น˜ํ™˜</button>
        <button id="replaceAll" style="background:#007acc;color:#fff;border:none;
          border-radius:4px;padding:5px 12px;cursor:pointer;font-size:12px;">๋ชจ๋‘ ์น˜ํ™˜</button>
      </div>
      <div style="margin-top:8px;display:flex;gap:12px;">
        <label style="color:#ccc;font-size:12px;cursor:pointer;">
          <input type="checkbox" id="caseSensitive"> ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„
        </label>
        <label style="color:#ccc;font-size:12px;cursor:pointer;">
          <input type="checkbox" id="useRegex"> ์ •๊ทœ์‹
        </label>
      </div>
    `;

    document.body.appendChild(panel);
    this.panel = panel;
    this.bindEvents();
  }

  bindEvents() {
    document.getElementById('findInput').addEventListener('input', () => this.search());
    document.getElementById('findNext').addEventListener('click', () => this.next());
    document.getElementById('findPrev').addEventListener('click', () => this.prev());
    document.getElementById('replaceOne').addEventListener('click', () => this.replaceOne());
    document.getElementById('replaceAll').addEventListener('click', () => this.replaceAll());
    document.getElementById('closeFind').addEventListener('click', () => this.hide());
    document.getElementById('caseSensitive').addEventListener('change', () => this.search());
    document.getElementById('useRegex').addEventListener('change', () => this.search());
  }

  bindShortcuts() {
    document.addEventListener('keydown', (e) => {
      if ((e.ctrlKey || e.metaKey) && e.key === 'f') {
        e.preventDefault();
        this.show();
      }
      if (e.key === 'Escape') this.hide();
    });
  }

  search() {
    const query = document.getElementById('findInput').value;
    const caseSensitive = document.getElementById('caseSensitive').checked;
    const useRegex = document.getElementById('useRegex').checked;
    const text = this.editor.value;

    this.matches = [];

    if (!query) {
      document.getElementById('matchCount').textContent = '';
      return;
    }

    try {
      let regex;
      if (useRegex) {
        regex = new RegExp(query, caseSensitive ? 'g' : 'gi');
      } else {
        // ํŠน์ˆ˜๋ฌธ์ž ์ด์Šค์ผ€์ดํ”„
        const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
        regex = new RegExp(escaped, caseSensitive ? 'g' : 'gi');
      }

      let match;
      while ((match = regex.exec(text)) !== null) {
        this.matches.push({ start: match.index, end: match.index + match[0].length });
      }

      const count = this.matches.length;
      document.getElementById('matchCount').textContent =
        count > 0 ? `${count}๊ฐœ ๋ฐœ๊ฒฌ` : '์—†์Œ';

      if (count > 0) {
        this.currentMatch = 0;
        this.highlight();
      }
    } catch (err) {
      document.getElementById('matchCount').textContent = '์ •๊ทœ์‹ ์˜ค๋ฅ˜';
    }
  }

  highlight() {
    if (this.matches.length === 0) return;
    const match = this.matches[this.currentMatch];
    this.editor.setSelectionRange(match.start, match.end);
    this.editor.focus();

    // ๋งค์น˜ ์œ„์น˜๋กœ ์Šคํฌ๋กค
    const lineHeight = 22;
    const textBefore = this.editor.value.substring(0, match.start);
    const lineNum = textBefore.split('\n').length;
    this.editor.scrollTop = (lineNum - 3) * lineHeight;

    document.getElementById('matchCount').textContent =
      `${this.currentMatch + 1} / ${this.matches.length}`;
  }

  next() {
    if (this.matches.length === 0) return;
    this.currentMatch = (this.currentMatch + 1) % this.matches.length;
    this.highlight();
  }

  prev() {
    if (this.matches.length === 0) return;
    this.currentMatch = (this.currentMatch - 1 + this.matches.length) % this.matches.length;
    this.highlight();
  }

  replaceOne() {
    if (this.matches.length === 0 || this.currentMatch < 0) return;
    const replaceWith = document.getElementById('replaceInput').value;
    const match = this.matches[this.currentMatch];
    const text = this.editor.value;
    this.editor.value =
      text.substring(0, match.start) + replaceWith + text.substring(match.end);
    this.search(); // ์žฌ๊ฒ€์ƒ‰
  }

  replaceAll() {
    const query = document.getElementById('findInput').value;
    const replaceWith = document.getElementById('replaceInput').value;
    if (!query) return;

    const caseSensitive = document.getElementById('caseSensitive').checked;
    const useRegex = document.getElementById('useRegex').checked;

    try {
      let regex;
      if (useRegex) {
        regex = new RegExp(query, caseSensitive ? 'g' : 'gi');
      } else {
        const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
        regex = new RegExp(escaped, caseSensitive ? 'g' : 'gi');
      }

      const count = (this.editor.value.match(regex) || []).length;
      this.editor.value = this.editor.value.replace(regex, replaceWith);
      alert(`${count}๊ฐœ ํ•ญ๋ชฉ์„ ์น˜ํ™˜ํ–ˆ์–ด์š”! โœ…`);
      this.search();
    } catch (err) {
      alert('์ •๊ทœ์‹ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์–ด์š”!');
    }
  }

  show() {
    this.panel.style.display = 'block';
    document.getElementById('findInput').focus();
  }

  hide() {
    this.panel.style.display = 'none';
    this.editor.focus();
  }
}

// ์‚ฌ์šฉ
const findReplace = new FindReplace(document.getElementById('codeArea'));

๐Ÿ”— 6. ๊ด„ํ˜ธ ๋งค์นญ & ์Šค๋งˆํŠธ ํƒญ ์ฒ˜๋ฆฌ

๊ด„ํ˜ธ ์ž๋™ ๋‹ซ๊ธฐ๋ž‘ ํƒญ ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ์—๋””ํ„ฐ UX์—์„œ ์—„์ฒญ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์ด์—์š”. ์ด๊ฑฐ ์—†์œผ๋ฉด ์ง„์งœ ๋ถˆํŽธํ•ด์„œ ๋ชป ์”€ ใ…‹ใ…‹ใ…‹

// ๊ด„ํ˜ธ ์ž๋™ ๋‹ซ๊ธฐ & ์Šค๋งˆํŠธ ์ž…๋ ฅ ์ฒ˜๋ฆฌ
class SmartInput {
  constructor(editor) {
    this.editor = editor;
    this.pairs = {
      '(': ')',
      '[': ']',
      '{': '}',
      '"': '"',
      "'": "'",
      '`': '`'
    };
    this.init();
  }

  init() {
    this.editor.addEventListener('keydown', (e) => this.handleKeydown(e));
  }

  handleKeydown(e) {
    const key = e.key;
    const pos = this.editor.selectionStart;
    const end = this.editor.selectionEnd;
    const text = this.editor.value;
    const charAfter = text[pos];

    // ํƒญ ํ‚ค ์ฒ˜๋ฆฌ (๋“ค์—ฌ์“ฐ๊ธฐ)
    if (key === 'Tab') {
      e.preventDefault();

      if (e.shiftKey) {
        // Shift+Tab: ๋‚ด์–ด์“ฐ๊ธฐ
        this.unindent(pos, end);
      } else if (pos !== end) {
        // ์„ ํƒ ์˜์—ญ ๋“ค์—ฌ์“ฐ๊ธฐ
        this.indentSelection(pos, end);
      } else {
        // ์ผ๋ฐ˜ ํƒญ (์ŠคํŽ˜์ด์Šค 2๊ฐœ ์‚ฝ์ž…)
        this.insertText('  ', pos);
      }
      return;
    }

    // ๊ด„ํ˜ธ ์ž๋™ ๋‹ซ๊ธฐ
    if (this.pairs[key]) {
      // ์„ ํƒ ์˜์—ญ์ด ์žˆ์œผ๋ฉด ๊ฐ์‹ธ๊ธฐ
      if (pos !== end) {
        e.preventDefault();
        const selected = text.substring(pos, end);
        const wrapped = key + selected + this.pairs[key];
        this.editor.value = text.substring(0, pos) + wrapped + text.substring(end);
        this.editor.setSelectionRange(pos + 1, end + 1);
        return;
      }

      // ๋‹ซ๋Š” ๊ด„ํ˜ธ ์Šคํ‚ต (์ด๋ฏธ ์žˆ์œผ๋ฉด)
      if (key === charAfter && Object.values(this.pairs).includes(key)) {
        e.preventDefault();
        this.editor.setSelectionRange(pos + 1, pos + 1);
        return;
      }

      // ์ž๋™ ๋‹ซ๊ธฐ ์‚ฝ์ž…
      e.preventDefault();
      const closing = this.pairs[key];
      this.editor.value = text.substring(0, pos) + key + closing + text.substring(pos);
      this.editor.setSelectionRange(pos + 1, pos + 1);
      return;
    }

    // Backspace: ๋นˆ ๊ด„ํ˜ธ ์Œ ์‚ญ์ œ
    if (key === 'Backspace') {
      const charBefore = text[pos - 1];
      if (charBefore && this.pairs[charBefore] === charAfter) {
        e.preventDefault();
        this.editor.value = text.substring(0, pos - 1) + text.substring(pos + 1);
        this.editor.setSelectionRange(pos - 1, pos - 1);
        return;
      }
    }

    // Enter: ์ž๋™ ๋“ค์—ฌ์“ฐ๊ธฐ
    if (key === 'Enter') {
      e.preventDefault();
      const textBefore = text.substring(0, pos);
      const currentLine = textBefore.split('\n').pop();
      const indent = currentLine.match(/^(\s*)/)[1];
      const charBefore = text[pos - 1];

      // ์—ฌ๋Š” ๊ด„ํ˜ธ ๋’ค Enter๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ ์ถ”๊ฐ€
      if (charBefore === '{' || charBefore === '[' || charBefore === '(') {
        const extraIndent = indent + '  ';
        const newText = '\n' + extraIndent + '\n' + indent;
        this.editor.value = text.substring(0, pos) + newText + text.substring(pos);
        this.editor.setSelectionRange(pos + extraIndent.length + 1, pos + extraIndent.length + 1);
      } else {
        // ์ผ๋ฐ˜ Enter: ํ˜„์žฌ ์ค„์˜ ๋“ค์—ฌ์“ฐ๊ธฐ ์œ ์ง€
        const newText = '\n' + indent;
        this.editor.value = text.substring(0, pos) + newText + text.substring(pos);
        this.editor.setSelectionRange(pos + indent.length + 1, pos + indent.length + 1);
      }
    }
  }

  insertText(str, pos) {
    const text = this.editor.value;
    this.editor.value = text.substring(0, pos) + str + text.substring(pos);
    this.editor.setSelectionRange(pos + str.length, pos + str.length);
  }

  indentSelection(start, end) {
    const text = this.editor.value;
    const lines = text.substring(start, end).split('\n');
    const indented = lines.map(line => '  ' + line).join('\n');
    this.editor.value = text.substring(0, start) + indented + text.substring(end);
    this.editor.setSelectionRange(start, start + indented.length);
  }

  unindent(start, end) {
    const text = this.editor.value;
    const lines = text.substring(start, end).split('\n');
    const unindented = lines.map(line => line.replace(/^  /, '')).join('\n');
    this.editor.value = text.substring(0, start) + unindented + text.substring(end);
    this.editor.setSelectionRange(start, start + unindented.length);
  }
}

const smartInput = new SmartInput(document.getElementById('codeArea'));
โœ… ์ด ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๋ฉด ์ง„์งœ ์—๋””ํ„ฐ ๋А๋‚Œ ๋‚จ! ๊ด„ํ˜ธ ์ž๋™ ๋‹ซ๊ธฐ, Enter ์‹œ ๋“ค์—ฌ์“ฐ๊ธฐ ์œ ์ง€, ์„ ํƒ ์˜์—ญ ๊ด„ํ˜ธ๋กœ ๊ฐ์‹ธ๊ธฐ๊นŒ์ง€ ๊ตฌํ˜„ํ•˜๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ํ™• ์˜ฌ๋ผ๊ฐ€์š”. ์žฌ๋Šฅ๋„ท์—์„œ ์ด๋Ÿฐ ์—๋””ํ„ฐ ๊ด€๋ จ ํ”„๋กœ์ ํŠธ ์˜๋ขฐ๋„ ์ข…์ข… ์˜ฌ๋ผ์˜ค๋Š”๋ฐ, ์ด ์ •๋„ ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด ์ถฉ๋ถ„ํžˆ ๊ฒฝ์Ÿ๋ ฅ ์žˆ์–ด์š”! ๐Ÿ’ช

โ†ฉ๏ธ 7. ์‹คํ–‰์ทจ์†Œ(Undo) / ๋‹ค์‹œ์‹คํ–‰(Redo) ๊ตฌํ˜„

Ctrl+Z ์—†๋Š” ์—๋””ํ„ฐ๋Š” ์ƒ์ƒ๋„ ๋ชป ํ•˜์ฃ  ใ…‹ใ…‹ ๋ธŒ๋ผ์šฐ์ € ๊ธฐ๋ณธ undo/redo๋ฅผ ์“ธ ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์ปค์Šคํ…€ ํžˆ์Šคํ† ๋ฆฌ ์Šคํƒ์„ ๊ตฌํ˜„ํ•˜๋ฉด ํ›จ์”ฌ ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ œ์–ดํ•  ์ˆ˜ ์žˆ์–ด์š”.

// ์ปค์Šคํ…€ Undo/Redo ํžˆ์Šคํ† ๋ฆฌ ๊ด€๋ฆฌ
class HistoryManager {
  constructor(editor) {
    this.editor = editor;
    this.history = [];      // ํžˆ์Šคํ† ๋ฆฌ ์Šคํƒ
    this.future = [];       // ๋‹ค์‹œ์‹คํ–‰ ์Šคํƒ
    this.maxHistory = 100;  // ์ตœ๋Œ€ ํžˆ์Šคํ† ๋ฆฌ ๊ฐœ์ˆ˜
    this.lastSaved = '';    // ๋งˆ์ง€๋ง‰ ์ €์žฅ ์ƒํƒœ
    this.saveTimer = null;  // ๋””๋ฐ”์šด์Šค ํƒ€์ด๋จธ

    this.init();
  }

  init() {
    // ์ดˆ๊ธฐ ์ƒํƒœ ์ €์žฅ
    this.saveState();

    this.editor.addEventListener('input', () => {
      // ๋””๋ฐ”์šด์Šค: 300ms ๋™์•ˆ ์ž…๋ ฅ ์—†์œผ๋ฉด ์ƒํƒœ ์ €์žฅ
      clearTimeout(this.saveTimer);
      this.saveTimer = setTimeout(() => {
        this.saveState();
      }, 300);
    });

    // ํ‚ค๋ณด๋“œ ๋‹จ์ถ•ํ‚ค
    document.addEventListener('keydown', (e) => {
      if ((e.ctrlKey || e.metaKey) && !e.shiftKey && e.key === 'z') {
        e.preventDefault();
        this.undo();
      }
      if ((e.ctrlKey || e.metaKey) && (e.shiftKey && e.key === 'z' || e.key === 'y')) {
        e.preventDefault();
        this.redo();
      }
    });
  }

  // ํ˜„์žฌ ์ƒํƒœ ์ €์žฅ
  saveState() {
    const currentState = {
      value: this.editor.value,
      selectionStart: this.editor.selectionStart,
      selectionEnd: this.editor.selectionEnd,
      timestamp: Date.now()
    };

    // ์ด์ „ ์ƒํƒœ์™€ ๋™์ผํ•˜๋ฉด ์ €์žฅ ์•ˆ ํ•จ
    if (this.history.length > 0) {
      const lastState = this.history[this.history.length - 1];
      if (lastState.value === currentState.value) return;
    }

    this.history.push(currentState);
    this.future = []; // ์ƒˆ ์ž…๋ ฅ ์‹œ ๋‹ค์‹œ์‹คํ–‰ ์Šคํƒ ์ดˆ๊ธฐํ™”

    // ์ตœ๋Œ€ ๊ฐœ์ˆ˜ ์ดˆ๊ณผ ์‹œ ์˜ค๋ž˜๋œ ๊ฒƒ ์ œ๊ฑฐ
    if (this.history.length > this.maxHistory) {
      this.history.shift();
    }
  }

  // ์‹คํ–‰ ์ทจ์†Œ
  undo() {
    if (this.history.length <= 1) return; // ์ดˆ๊ธฐ ์ƒํƒœ๋Š” ์ทจ์†Œ ๋ถˆ๊ฐ€

    const current = this.history.pop();
    this.future.push(current);

    const prevState = this.history[this.history.length - 1];
    this.restoreState(prevState);
  }

  // ๋‹ค์‹œ ์‹คํ–‰
  redo() {
    if (this.future.length === 0) return;

    const nextState = this.future.pop();
    this.history.push(nextState);
    this.restoreState(nextState);
  }

  // ์ƒํƒœ ๋ณต์›
  restoreState(state) {
    this.editor.value = state.value;
    this.editor.setSelectionRange(state.selectionStart, state.selectionEnd);
    this.editor.focus();

    // ์ค„ ๋ฒˆํ˜ธ ๋“ฑ UI ์—…๋ฐ์ดํŠธ ํŠธ๋ฆฌ๊ฑฐ
    this.editor.dispatchEvent(new Event('input'));
  }

  // ํžˆ์Šคํ† ๋ฆฌ ์ •๋ณด ๋ฐ˜ํ™˜
  getInfo() {
    return {
      canUndo: this.history.length > 1,
      canRedo: this.future.length > 0,
      historyCount: this.history.length,
      futureCount: this.future.length
    };
  }
}

const historyManager = new HistoryManager(document.getElementById('codeArea'));

๐Ÿš€ 8. ์ „์ฒด ํ†ตํ•ฉ & ๋งˆ๋ฌด๋ฆฌ

์ด์ œ ๋ชจ๋“  ๋ชจ๋“ˆ์„ ํ•˜๋‚˜๋กœ ํ•ฉ์ณ๋ณผ ์‹œ๊ฐ„! ๊ฐ ๊ธฐ๋Šฅ์„ ๋…๋ฆฝ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์—ˆ์œผ๋‹ˆ ํ†ตํ•ฉ์ด ๊น”๋”ํ•ด์š” ใ…Žใ…Ž

// ๋ฏธ๋‹ˆ IDE ๋ฉ”์ธ ์ดˆ๊ธฐํ™”
class MiniIDE {
  constructor() {
    this.editor = document.getElementById('codeArea');
    this.modules = {};
    this.init();
  }

  init() {
    // ๋ชจ๋“  ๋ชจ๋“ˆ ์ดˆ๊ธฐํ™”
    this.modules.autoComplete = new AutoComplete(this.editor);
    this.modules.findReplace = new FindReplace(this.editor);
    this.modules.smartInput = new SmartInput(this.editor);
    this.modules.history = new HistoryManager(this.editor);

    // ์ค„ ๋ฒˆํ˜ธ & ์Šคํฌ๋กค ๋™๊ธฐํ™”
    this.setupLineNumbers();
    this.setupScrollSync();
    this.setupStatusBar();

    // ๊ธฐ๋ณธ ์ฝ”๋“œ ๋กœ๋“œ
    this.loadDefaultCode();

    console.log('๐ŸŽ‰ ๋ฏธ๋‹ˆ IDE ์ดˆ๊ธฐํ™” ์™„๋ฃŒ!');
  }

  setupLineNumbers() {
    const update = () => {
      const lines = this.editor.value.split('\n').length;
      const lineNumbers = document.getElementById('lineNumbers');
      lineNumbers.innerHTML = Array.from(
        {length: lines}, (_, i) => `<div>${i + 1}</div>`
      ).join('');
    };
    this.editor.addEventListener('input', update);
    update();
  }

  setupScrollSync() {
    const lineNumbers = document.getElementById('lineNumbers');
    this.editor.addEventListener('scroll', () => {
      lineNumbers.scrollTop = this.editor.scrollTop;
    });
  }

  setupStatusBar() {
    this.editor.addEventListener('keyup', () => {
      const pos = this.editor.selectionStart;
      const textBefore = this.editor.value.substring(0, pos);
      const lines = textBefore.split('\n');
      document.getElementById('cursorPos').textContent =
        `์ค„ ${lines.length}, ์—ด ${lines[lines.length-1].length + 1}`;
    });
  }

  loadDefaultCode() {
    this.editor.value = `// ๐ŸŽ‰ ๋ฏธ๋‹ˆ IDE์— ์˜ค์‹  ๊ฑธ ํ™˜์˜ํ•ด์š”!
// Ctrl+F: ๊ฒ€์ƒ‰, Ctrl+Z: ์‹คํ–‰์ทจ์†Œ

function hello(name) {
  const greeting = \`์•ˆ๋…•ํ•˜์„ธ์š”, \${name}!\`;
  console.log(greeting);
  return greeting;
}

hello("๊ฐœ๋ฐœ์ž");`;
    this.editor.dispatchEvent(new Event('input'));
  }
}

// ์•ฑ ์‹œ์ž‘!
document.addEventListener('DOMContentLoaded', () => {
  window.ide = new MiniIDE();
});
โœ… ์™„์„ฑ! ์ด ์ •๋„๋ฉด ์ง„์งœ ์“ธ๋งŒํ•œ ๋ฏธ๋‹ˆ ์—๋””ํ„ฐ๊ฐ€ ์™„์„ฑ๋ผ์š”. ์—ฌ๊ธฐ์„œ ๋” ๋ฐœ์ „์‹œํ‚ค๊ณ  ์‹ถ๋‹ค๋ฉด Prism.js๋กœ ํ•˜์ด๋ผ์ดํŒ… ์—…๊ทธ๋ ˆ์ด๋“œ, CodeMirror๋‚˜ Monaco Editor(VS Code ์—”์ง„) ํ†ตํ•ฉ, ํŒŒ์ผ ์ €์žฅ/๋ถˆ๋Ÿฌ์˜ค๊ธฐ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ ๋“ฑ์„ ๊ณ ๋ คํ•ด๋ณผ ์ˆ˜ ์žˆ์–ด์š”!
๐Ÿ“Š ๋ฏธ๋‹ˆ IDE ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋‚œ์ด๋„ & ์ค‘์š”๋„ ๋‚ฎ์Œ ์ค‘๊ฐ„ ๋†’์Œ ์ค‘์š”๋„ ๊ตฌํ˜„ ๋‚œ์ด๋„ โ†’ ์ค„ ๋ฒˆํ˜ธ โญโญโญโญโญ ์Šค๋งˆํŠธ ํƒญ โญโญโญโญ ๊ด„ํ˜ธ ๋งค์นญ โญโญโญโญโญ Undo/Redo โญโญโญโญ ๊ฒ€์ƒ‰/์น˜ํ™˜ โญโญโญโญ ์ž๋™์™„์„ฑ AutoComplete โญโญโญโญโญ ์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ… โญโญโญโญโญ ๋ฒ„๋ธ” ํฌ๊ธฐ = ๊ตฌํ˜„ ๋ณต์žก๋„ | โญ = ์‚ฌ์šฉ์ž ์ฒด๊ฐ ์ค‘์š”๋„

๐Ÿ“ฆ 9. ์ง์ ‘ ๊ตฌํ˜„ vs ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ ํƒ ๊ฐ€์ด๋“œ

์ง์ ‘ ๋‹ค ๋งŒ๋“œ๋Š” ๊ฒŒ ํ•ญ์ƒ ์ •๋‹ต์€ ์•„๋‹ˆ์—์š”! ์ƒํ™ฉ์— ๋”ฐ๋ผ ๊ฒ€์ฆ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ๋Š” ๊ฒŒ ํ›จ์”ฌ ํšจ์œจ์ ์ผ ์ˆ˜ ์žˆ์–ด์š”. ์–ด๋–ค ๊ฑธ ์„ ํƒํ•ด์•ผ ํ• ์ง€ ์ •๋ฆฌํ•ด๋ดค์–ด์š” ใ…Žใ…Ž

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํŠน์ง• ์ ํ•ฉํ•œ ์ƒํ™ฉ
์ง์ ‘ ๊ตฌํ˜„ ์™„์ „ํ•œ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•, ๋ฒˆ๋“ค ํฌ๊ธฐ ์ตœ์†Œํ™” ํ•™์Šต ๋ชฉ์ , ๋งค์šฐ ํŠน์ˆ˜ํ•œ ์š”๊ตฌ์‚ฌํ•ญ
CodeMirror 6 ๋ชจ๋“ˆ์‹, ๊ฐ€๋ณ๊ณ  ํ™•์žฅ์„ฑ ์šฐ์ˆ˜ ์›น ์•ฑ ๋‚ด ์ž„๋ฒ ๋””๋“œ ์—๋””ํ„ฐ
Monaco Editor VS Code ์—”์ง„, ํ’๋ถ€ํ•œ ๊ธฐ๋Šฅ VS Code ์ˆ˜์ค€์˜ ์—๋””ํ„ฐ ํ•„์š” ์‹œ
Ace Editor ์„ฑ์ˆ™ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ๋„“์€ ์–ธ์–ด ์ง€์› ๋น ๋ฅธ ํ”„๋กœํ† ํƒ€์ดํ•‘
Prism.js ํ•˜์ด๋ผ์ดํŒ… ์ „์šฉ, ์ดˆ๊ฒฝ๋Ÿ‰ ์ฝ๊ธฐ ์ „์šฉ ์ฝ”๋“œ ํ‘œ์‹œ
๐Ÿ’ก ์žฌ๋Šฅ๋„ท ๊ฟ€ํŒ! ์žฌ๋Šฅ๋„ท์—์„œ ์—๋””ํ„ฐ ๊ด€๋ จ ํ”„๋ฆฌ๋žœ์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐ›์„ ๋•Œ, ํด๋ผ์ด์–ธํŠธ๊ฐ€ "๊ฐ„๋‹จํ•œ ์ฝ”๋“œ ์—๋””ํ„ฐ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”"๋ผ๊ณ  ํ•˜๋ฉด Monaco Editor ๊ธฐ๋ฐ˜์œผ๋กœ ๋น ๋ฅด๊ฒŒ ๊ตฌํ˜„ํ•˜๊ณ , "์™„์ „ ์ปค์Šคํ…€ ์—๋””ํ„ฐ"๋ฅผ ์›ํ•˜๋ฉด ์˜ค๋Š˜ ๋ฐฐ์šด ๋ฐฉ์‹์œผ๋กœ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒŒ ์ข‹์•„์š”!

โœ… ํ•ต์‹ฌ ์ •๋ฆฌ & ๋‹ค์Œ ๋‹จ๊ณ„

1
๊ธฐ๋ณธ ๊ตฌ์กฐ: textarea + ์ค„๋ฒˆํ˜ธ div + ์ƒํƒœ๋ฐ”๋กœ ๋ผˆ๋Œ€ ๊ตฌ์„ฑ. spellcheck="false" ํ•„์ˆ˜!
2
์ค„ ๋ฒˆํ˜ธ: ์ž…๋ ฅ ์ด๋ฒคํŠธ๋งˆ๋‹ค ๋™์  ์—…๋ฐ์ดํŠธ + ์Šคํฌ๋กค ๋™๊ธฐํ™”๊ฐ€ ํ•ต์‹ฌ
3
์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ…: ์ •๊ทœ์‹ ํ† ํฌ๋‚˜์ด์ €๋กœ ๊ธฐ๋ณธ ๊ตฌํ˜„, ํ”„๋กœ๋•์…˜์—” Prism.js ์ถ”์ฒœ
4
์ž๋™์™„์„ฑ: ํ˜„์žฌ ๋‹จ์–ด ๊ฐ์ง€ โ†’ ๋งค์นญ ๋ชฉ๋ก โ†’ ๋“œ๋กญ๋‹ค์šด โ†’ ํ‚ค๋ณด๋“œ ๋„ค๋น„๊ฒŒ์ด์…˜
5
๊ฒ€์ƒ‰/์น˜ํ™˜: ์ •๊ทœ์‹ ๊ธฐ๋ฐ˜ ๊ฒ€์ƒ‰, ๋Œ€์†Œ๋ฌธ์ž ์˜ต์…˜, ์ „์ฒด ์น˜ํ™˜ ๊ธฐ๋Šฅ
6
์Šค๋งˆํŠธ ์ž…๋ ฅ: ๊ด„ํ˜ธ ์ž๋™ ๋‹ซ๊ธฐ, Enter ๋“ค์—ฌ์“ฐ๊ธฐ, Tab ์ฒ˜๋ฆฌ
7
Undo/Redo: ํžˆ์Šคํ† ๋ฆฌ ์Šคํƒ + ๋””๋ฐ”์šด์Šค๋กœ ํšจ์œจ์ ์ธ ์ƒํƒœ ๊ด€๋ฆฌ

์˜ค๋Š˜ ๋ฐฐ์šด ๋‚ด์šฉ๋“ค์„ ์กฐํ•ฉํ•˜๋ฉด ์ง„์งœ ์“ธ๋งŒํ•œ ๋ฏธ๋‹ˆ IDE๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด์š”! ๐ŸŽ‰ ๊ฐ ๊ธฐ๋Šฅ์„ ๋…๋ฆฝ ํด๋ž˜์Šค๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๊ตฌํ˜„ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์œ ์ง€๋ณด์ˆ˜๋„ ํŽธํ•˜๊ณ , ํ•„์š”ํ•œ ๊ธฐ๋Šฅ๋งŒ ๊ณจ๋ผ์„œ ์“ธ ์ˆ˜๋„ ์žˆ์–ด์š”. ๋‹ค์Œ ๋‹จ๊ณ„๋กœ๋Š” LSP(Language Server Protocol) ์—ฐ๋™์ด๋‚˜ ํ”Œ๋Ÿฌ๊ทธ์ธ ์‹œ์Šคํ…œ ๊ตฌํ˜„์— ๋„์ „ํ•ด๋ณด์„ธ์š”! ํ™”์ดํŒ… ๐Ÿ”ฅ

JavaScript
HTML/CSS
์ฝ”๋“œ ์—๋””ํ„ฐ
์‹ ํƒ์Šค ํ•˜์ด๋ผ์ดํŒ…
์ž๋™์™„์„ฑ
์ •๊ทœ์‹
IDE ๊ฐœ๋ฐœ
ํ”„๋ก ํŠธ์—”๋“œ
๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.