diff --git a/app/modules/cafe24/templates/cafe24/_editor.html b/app/modules/cafe24/templates/cafe24/_editor.html index 584ea87..cfec0ed 100644 --- a/app/modules/cafe24/templates/cafe24/_editor.html +++ b/app/modules/cafe24/templates/cafe24/_editor.html @@ -78,7 +78,7 @@
diff --git a/app/modules/cafe24/templates/cafe24/products.html b/app/modules/cafe24/templates/cafe24/products.html index 915b31a..e7e8fd2 100644 --- a/app/modules/cafe24/templates/cafe24/products.html +++ b/app/modules/cafe24/templates/cafe24/products.html @@ -186,10 +186,75 @@ timer = setTimeout(repaint, 80); } + /* Ctrl+/ (Mac ⌘+/) 로 HTML 주석 토글. + - 선택이 있으면 그 선택이 걸친 **줄 전체**가 대상이다(반쯤 걸친 줄이 + 잘려 태그가 깨지지 않게). + - 선택이 없으면 커서가 있는 줄 하나. + - 대상 안에 주석 기호가 하나라도 있으면 **제거**, 없으면 블록 전체를 + 로 감싼다. HTML 주석은 중첩이 안 되므로 "이미 주석인 부분을 + 또 감싸기"를 피하는 것이 이 규칙의 이유다. */ + var COMMENT_MARK = //g; + + function toggleComment() { + var value = ta.value; + var start = ta.selectionStart, end = ta.selectionEnd; + // 선택이 개행에서 끝나면 그 다음 줄은 대상이 아니다(드래그로 줄 끝까지 + // 끌었을 때 아래 줄까지 주석되는 것을 막는다). + if (end > start && value.charAt(end - 1) === "\n") end -= 1; + + var lineStart = value.lastIndexOf("\n", start - 1) + 1; + var lineEnd = value.indexOf("\n", end); + if (lineEnd === -1) lineEnd = value.length; + + var block = value.slice(lineStart, lineEnd); + if (!block.trim()) return; // 빈 줄에서는 아무 것도 하지 않는다 + + var caretIn = start - lineStart; // 블록 안에서의 커서 위치 + var shift = 0, out; + + COMMENT_MARK.lastIndex = 0; + if (COMMENT_MARK.test(block)) { + COMMENT_MARK.lastIndex = 0; + out = block.replace(COMMENT_MARK, function (mark, offset) { + if (offset < caretIn) shift -= mark.length; // 커서 앞이 줄어든 만큼 + return ""; + }); + } else { + var indent = block.match(/^[ \t]*/)[0]; + out = indent + ""; + shift = caretIn >= indent.length ? 5 : 0; // "