From 024653dc8e2e723eb8857a629abd989e9adf5da1 Mon Sep 17 00:00:00 2001 From: king Date: Wed, 19 Aug 2026 22:17:18 +0900 Subject: [PATCH] =?UTF-8?q?feat(cafe24):=20HTML=20=ED=8E=B8=EC=A7=91?= =?UTF-8?q?=EA=B8=B0=20=EC=A4=84=20=EC=9D=B4=EB=8F=99=C2=B7=EB=B3=B5?= =?UTF-8?q?=EC=82=AC=20=EB=8B=A8=EC=B6=95=ED=82=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alt+↑/↓ 로 커서가 있는 줄(선택이 있으면 그 줄들)을 위/아래로 옮기고, Alt+Shift+↑/↓ 로 같은 줄을 하나 더 만든다. 상세페이지는 한 줄이 곧 한 구획이라 순서 바꾸기·반복이 잦다. - 이동은 윗줄/아랫줄과 통째로 자리를 바꾸는 방식이라 줄 수가 변하지 않는다. 첫 줄 위·마지막 줄 아래에서는 아무 것도 하지 않는다. - 복사는 위로 하면 커서가 원래 자리(위쪽 사본)에, 아래로 하면 새로 생긴 아래쪽 사본으로 간다. - 주석 토글과 같은 줄 범위 규칙을 쓰도록 lineRange()/applyEdit() 로 묶었다. 선택이 개행에서 끝나면 다음 줄은 대상이 아니다. - execCommand("insertText") 라 Ctrl+Z 로 되돌아간다. Co-Authored-By: Claude Opus 5 --- .../cafe24/templates/cafe24/_editor.html | 4 +- .../cafe24/templates/cafe24/products.html | 107 +++++++++++++----- 2 files changed, 82 insertions(+), 29 deletions(-) diff --git a/app/modules/cafe24/templates/cafe24/_editor.html b/app/modules/cafe24/templates/cafe24/_editor.html index cfec0ed..4a64c40 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/모바일 공통 · Ctrl+/ 주석 + 상세설명 HTML · {{ desc.description | length }}자 · PC/모바일 공통 · Ctrl+/ 주석 · Alt+↑↓ 줄 이동 @@ -100,7 +100,7 @@ + title="Tab 들여쓰기 · Ctrl+/ 주석 토글 · Alt+↑/↓ 줄 이동 · Alt+Shift+↑/↓ 줄 복사 (선택이 없으면 커서가 있는 줄)">{{ html_pc }}
diff --git a/app/modules/cafe24/templates/cafe24/products.html b/app/modules/cafe24/templates/cafe24/products.html index e7e8fd2..712fdbc 100644 --- a/app/modules/cafe24/templates/cafe24/products.html +++ b/app/modules/cafe24/templates/cafe24/products.html @@ -186,6 +186,37 @@ timer = setTimeout(repaint, 80); } + /* ── 편집 단축키 공용 헬퍼 ── + lineRange() : 지금 선택(없으면 커서)이 걸친 **줄 전체** 범위. + applyEdit() : 그 범위를 새 문자열로 바꾸고 선택을 다시 잡는다. */ + + function lineRange() { + var value = ta.value; + var start = ta.selectionStart, end = ta.selectionEnd; + // 선택이 개행에서 끝나면 그 다음 줄은 대상이 아니다(드래그로 줄 끝까지 + // 끌었을 때 아래 줄까지 딸려오는 것을 막는다). + if (end > start && value.charAt(end - 1) === "\n") end -= 1; + var from = value.lastIndexOf("\n", start - 1) + 1; + var to = value.indexOf("\n", end); + if (to === -1) to = value.length; + return { value: value, start: start, end: end, from: from, to: to }; + } + + function applyEdit(from, to, text, selStart, selEnd) { + // execCommand 로 넣어야 브라우저의 실행취소(Ctrl+Z) 이력에 남는다. + // 지원하지 않으면 value 를 직접 바꾼다(되돌리기만 안 될 뿐 동작은 같다). + var value = ta.value; + ta.selectionStart = from; + ta.selectionEnd = to; + var inserted = false; + try { inserted = document.execCommand("insertText", false, text); } catch (err) { inserted = false; } + if (!inserted) ta.value = value.slice(0, from) + text + value.slice(to); + ta.selectionStart = selStart; + ta.selectionEnd = selEnd; + dirty = true; + refresh(); + } + /* Ctrl+/ (Mac ⌘+/) 로 HTML 주석 토글. - 선택이 있으면 그 선택이 걸친 **줄 전체**가 대상이다(반쯤 걸친 줄이 잘려 태그가 깨지지 않게). @@ -196,20 +227,11 @@ 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); + var r = lineRange(); + var block = r.value.slice(r.from, r.to); if (!block.trim()) return; // 빈 줄에서는 아무 것도 하지 않는다 - var caretIn = start - lineStart; // 블록 안에서의 커서 위치 + var caretIn = r.start - r.from; // 블록 안에서의 커서 위치 var shift = 0, out; COMMENT_MARK.lastIndex = 0; @@ -225,23 +247,45 @@ shift = caretIn >= indent.length ? 5 : 0; // "