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 @@
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; // "