From 233c8db631ccb102af67a79b3d93f617499f9fe5 Mon Sep 17 00:00:00 2001 From: king Date: Wed, 19 Aug 2026 22:10:42 +0900 Subject: [PATCH] =?UTF-8?q?feat(cafe24):=20HTML=20=ED=8E=B8=EC=A7=91?= =?UTF-8?q?=EA=B8=B0=20Ctrl+/=20=EC=A3=BC=EC=84=9D=20=ED=86=A0=EA=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 선택이 있으면 선택이 걸친 줄 전체가 대상. 반쯤 걸친 줄이 잘려 태그가 깨지지 않게 하기 위함. 선택이 없으면 커서가 있는 줄 하나. - 대상 안에 주석 기호가 하나라도 있으면 제거, 없으면 블록 전체를 로 감싼다. HTML 주석은 중첩이 안 되므로 이미 주석인 부분을 또 감싸지 않는다. - 선택이 개행에서 끝나면 다음 줄은 제외(줄 끝까지 드래그했을 때 아래 줄이 딸려오지 않게). - execCommand("insertText") 로 넣어 Ctrl+Z 이력에 남긴다. 미지원 브라우저는 value 를 직접 바꾼다. - 되돌린 뒤 커서/선택 위치를 복원한다. Co-Authored-By: Claude Opus 5 --- .../cafe24/templates/cafe24/_editor.html | 5 +- .../cafe24/templates/cafe24/products.html | 67 ++++++++++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) 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 @@
- 상세설명 HTML · {{ desc.description | length }}자 · PC/모바일 공통 + 상세설명 HTML · {{ desc.description | length }}자 · PC/모바일 공통 · Ctrl+/ 주석 @@ -99,7 +99,8 @@
+ spellcheck="false" autocapitalize="off" autocorrect="off" + title="Tab 들여쓰기 · Ctrl+/ 주석 토글(선택한 줄 전체, 선택이 없으면 커서 줄)">{{ html_pc }}
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; // "