ide-assi 0.436.0 → 0.438.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs.js +175 -141
- package/dist/bundle.esm.js +175 -141
- package/dist/components/ideDiff.js +168 -146
- package/package.json +1 -1
- package/src/components/ideDiff.js +168 -146
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ninegrid from "ninegrid2";
|
|
2
2
|
|
|
3
|
-
// CodeMirror 6 핵심 및 확장 임포트
|
|
4
3
|
import {
|
|
5
4
|
EditorView, lineNumbers, highlightSpecialChars, drawSelection,
|
|
6
5
|
dropCursor, keymap, highlightActiveLine, highlightActiveLineGutter,
|
|
@@ -12,17 +11,13 @@ import {
|
|
|
12
11
|
StateEffect,
|
|
13
12
|
Text
|
|
14
13
|
} from "@codemirror/state";
|
|
15
|
-
// ⭐️ indentWithTab, selectAll 함수로 임포트되었는지 확인하고, 아래에서 호출합니다.
|
|
16
14
|
import { history, historyKeymap, indentWithTab, selectAll, defaultKeymap } from "@codemirror/commands";
|
|
17
15
|
import { searchKeymap, highlightSelectionMatches } from "@codemirror/search";
|
|
18
|
-
// ⭐️ indentOnInput 함수도 여기서 임포트되었는지 확인합니다.
|
|
19
16
|
import { indentOnInput, bracketMatching, syntaxHighlighting, defaultHighlightStyle } from "@codemirror/language";
|
|
20
17
|
import { javascript } from "@codemirror/lang-javascript";
|
|
21
|
-
|
|
22
18
|
import { lintKeymap } from "@codemirror/lint";
|
|
23
19
|
import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
|
|
24
20
|
|
|
25
|
-
// Diff 로직을 위해 diff-match-patch 사용
|
|
26
21
|
import { diff_match_patch } from 'diff-match-patch';
|
|
27
22
|
|
|
28
23
|
// --- Diff 데코레이션을 위한 StateEffect 정의 ---
|
|
@@ -63,8 +58,71 @@ const tobeDiffDecorations = StateField.define({
|
|
|
63
58
|
});
|
|
64
59
|
|
|
65
60
|
|
|
66
|
-
|
|
61
|
+
// IdeDiff 클래스 외부 (파일 상단 or 하단)에 추가
|
|
62
|
+
class MergeButtonWidget extends WidgetType {
|
|
63
|
+
// ⭐️ diffRange는 변경이 발생할 대상 에디터의 범위입니다.
|
|
64
|
+
// ⭐️ isAsisButton: ASIS 에디터 쪽에 붙는 버튼인가? (true면 ASIS -> TOBE 적용)
|
|
65
|
+
// ⭐️ isAsisButton이 false면 TOBE 에디터 쪽에 붙는 버튼 (TOBE -> ASIS 되돌리기)
|
|
66
|
+
constructor(isAsisButton, textToApply, targetEditorView, diffRange, hostComponent) {
|
|
67
|
+
super();
|
|
68
|
+
this.isAsisButton = isAsisButton; // 이 버튼이 ASIS 에디터에 붙는 버튼인가 (true) TOBE 에디터에 붙는 버튼인가 (false)
|
|
69
|
+
this.textToApply = textToApply; // 적용할 텍스트
|
|
70
|
+
this.targetEditorView = targetEditorView; // 텍스트를 적용할 에디터 뷰 (상대편 에디터)
|
|
71
|
+
this.diffRange = diffRange; // 대상 에디터에서 변경이 일어날 정확한 from/to 오프셋
|
|
72
|
+
this.hostComponent = hostComponent; // IdeDiff 인스턴스 참조
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 위젯이 차지할 공간을 텍스트 줄에 할당할지 여부. false로 설정하여 버튼이 줄 사이에 끼어들지 않도록 함.
|
|
76
|
+
eq(other) { return false; }
|
|
77
|
+
|
|
78
|
+
// 위젯의 DOM 요소를 생성합니다.
|
|
79
|
+
toDOM(view) {
|
|
80
|
+
const button = document.createElement("button");
|
|
81
|
+
// 버튼 클래스 및 텍스트는 버튼의 위치(ASIS/TOBE)에 따라 결정됩니다.
|
|
82
|
+
button.className = `cm-merge-button ${this.isAsisButton ? 'accept' : 'revert'}`;
|
|
83
|
+
button.textContent = this.isAsisButton ? "→ 적용" : "← 되돌리기"; // ASIS 버튼: TOBE로 적용, TOBE 버튼: ASIS로 되돌리기
|
|
84
|
+
|
|
85
|
+
// 클릭 이벤트 핸들러
|
|
86
|
+
button.addEventListener("click", () => {
|
|
87
|
+
console.log(`버튼 클릭: ${this.isAsisButton ? 'ASIS -> TOBE' : 'TOBE -> ASIS'}`, this.textToApply);
|
|
88
|
+
console.log("대상 에디터:", this.targetEditorView === this.hostComponent.asisEditorView ? "ASIS" : "TOBE");
|
|
89
|
+
console.log("대상 범위:", this.diffRange);
|
|
90
|
+
|
|
91
|
+
this.applyChanges(this.textToApply, this.targetEditorView, this.diffRange);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const container = document.createElement("div");
|
|
95
|
+
container.className = "cm-merge-button-container";
|
|
96
|
+
container.appendChild(button);
|
|
97
|
+
return container;
|
|
98
|
+
}
|
|
67
99
|
|
|
100
|
+
// 실제 변경 적용 로직
|
|
101
|
+
applyChanges(text, editorView, range) {
|
|
102
|
+
if (!editorView || !range) {
|
|
103
|
+
console.error("Target editor view or range is undefined.", editorView, range);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
editorView.dispatch({
|
|
108
|
+
changes: {
|
|
109
|
+
from: range.from,
|
|
110
|
+
to: range.to,
|
|
111
|
+
insert: text
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// 변경 후 Diff를 다시 계산하고 데코레이션을 업데이트합니다.
|
|
116
|
+
// requestAnimationFrame으로 감싸서 다음 렌더링 사이클에서 Diff 계산이 이루어지도록 합니다.
|
|
117
|
+
// 이렇게 하면 UI 블로킹을 줄일 수 있습니다.
|
|
118
|
+
requestAnimationFrame(() => {
|
|
119
|
+
this.hostComponent.recalculateDiff();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
export class IdeDiff extends HTMLElement {
|
|
68
126
|
#asisEditorView;
|
|
69
127
|
#tobeEditorView;
|
|
70
128
|
#asisEditorEl;
|
|
@@ -77,17 +135,79 @@ export class IdeDiff extends HTMLElement {
|
|
|
77
135
|
_tobeScrollHandler = null;
|
|
78
136
|
|
|
79
137
|
|
|
138
|
+
get asisEditorView() {
|
|
139
|
+
return this.#asisEditorView;
|
|
140
|
+
};
|
|
141
|
+
|
|
80
142
|
constructor() {
|
|
81
143
|
super();
|
|
82
144
|
this.attachShadow({ mode: 'open' });
|
|
83
145
|
}
|
|
84
146
|
|
|
147
|
+
|
|
148
|
+
|
|
85
149
|
connectedCallback() {
|
|
86
150
|
this.shadowRoot.innerHTML = `
|
|
87
151
|
<style>
|
|
88
152
|
/* ninegrid CSS 및 필요한 기본 스타일 */
|
|
89
153
|
@import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/ideDiff.css";
|
|
90
154
|
${ninegrid.getCustomPath(this, "ideDiff.css")}
|
|
155
|
+
|
|
156
|
+
/* --- 추가된 CSS 규칙 (버튼 및 선택 관련) --- */
|
|
157
|
+
.cm-line {
|
|
158
|
+
position: relative;
|
|
159
|
+
}
|
|
160
|
+
.cm-merge-button-container {
|
|
161
|
+
position: absolute;
|
|
162
|
+
right: 5px;
|
|
163
|
+
top: 50%;
|
|
164
|
+
transform: translateY(-50%);
|
|
165
|
+
z-index: 10;
|
|
166
|
+
display: flex;
|
|
167
|
+
gap: 5px;
|
|
168
|
+
}
|
|
169
|
+
.cm-merge-button {
|
|
170
|
+
background-color: #f0f0f0;
|
|
171
|
+
border: 1px solid #ccc;
|
|
172
|
+
border-radius: 3px;
|
|
173
|
+
padding: 2px 6px;
|
|
174
|
+
cursor: pointer;
|
|
175
|
+
font-size: 0.8em;
|
|
176
|
+
line-height: 1;
|
|
177
|
+
white-space: nowrap;
|
|
178
|
+
opacity: 0.7;
|
|
179
|
+
transition: opacity 0.2s ease-in-out;
|
|
180
|
+
}
|
|
181
|
+
.cm-merge-button:hover {
|
|
182
|
+
opacity: 1;
|
|
183
|
+
background-color: #e0e0e0;
|
|
184
|
+
}
|
|
185
|
+
.cm-merge-button.accept {
|
|
186
|
+
background-color: #4CAF50;
|
|
187
|
+
color: white;
|
|
188
|
+
border-color: #4CAF50;
|
|
189
|
+
}
|
|
190
|
+
.cm-merge-button.revert {
|
|
191
|
+
background-color: #f44336;
|
|
192
|
+
color: white;
|
|
193
|
+
border-color: #f44336;
|
|
194
|
+
}
|
|
195
|
+
/* Diff 데코레이션 CSS (ideDiff.css에 없으면 여기에 추가) */
|
|
196
|
+
.cm-inserted-line-bg { background-color: #e6ffed; border-left: 3px solid #66bb6a; }
|
|
197
|
+
.cm-deleted-line-bg { background-color: #ffebe9; border-left: 3px solid #ef5350; }
|
|
198
|
+
|
|
199
|
+
/* CodeMirror 선택 스타일 (ideDiff.css에 없으면 여기에 추가) */
|
|
200
|
+
.cm-selectionBackground {
|
|
201
|
+
background-color: #d7d4f9 !important;
|
|
202
|
+
}
|
|
203
|
+
.cm-editor ::selection {
|
|
204
|
+
background-color: #d7d4f9 !important;
|
|
205
|
+
color: inherit !important;
|
|
206
|
+
}
|
|
207
|
+
.cm-editor::-moz-selection {
|
|
208
|
+
background-color: #d7d4f9 !important;
|
|
209
|
+
color: inherit !important;
|
|
210
|
+
}
|
|
91
211
|
</style>
|
|
92
212
|
|
|
93
213
|
<div class="wrapper">
|
|
@@ -133,7 +253,7 @@ export class IdeDiff extends HTMLElement {
|
|
|
133
253
|
drawSelection(),
|
|
134
254
|
dropCursor(),
|
|
135
255
|
EditorState.allowMultipleSelections.of(true),
|
|
136
|
-
indentOnInput(),
|
|
256
|
+
indentOnInput(),
|
|
137
257
|
bracketMatching(),
|
|
138
258
|
highlightActiveLine(),
|
|
139
259
|
highlightActiveLineGutter(),
|
|
@@ -144,11 +264,11 @@ export class IdeDiff extends HTMLElement {
|
|
|
144
264
|
...historyKeymap,
|
|
145
265
|
...lintKeymap,
|
|
146
266
|
...completionKeymap,
|
|
147
|
-
|
|
148
|
-
|
|
267
|
+
indentWithTab, // ⭐️ 함수가 아닌 확장 자체를 전달
|
|
268
|
+
selectAll // ⭐️ 함수가 아닌 확장 자체를 전달
|
|
149
269
|
]),
|
|
150
|
-
syntaxHighlighting(defaultHighlightStyle),
|
|
151
|
-
autocompletion(),
|
|
270
|
+
syntaxHighlighting(defaultHighlightStyle),
|
|
271
|
+
autocompletion(),
|
|
152
272
|
];
|
|
153
273
|
|
|
154
274
|
// ASIS 에디터 뷰 초기화
|
|
@@ -157,9 +277,9 @@ export class IdeDiff extends HTMLElement {
|
|
|
157
277
|
doc: '',
|
|
158
278
|
extensions: [
|
|
159
279
|
basicExtensions,
|
|
160
|
-
this.#languageCompartment.of(javascript()),
|
|
161
|
-
EditorState.readOnly.of(true),
|
|
162
|
-
asisDiffDecorations,
|
|
280
|
+
this.#languageCompartment.of(javascript()),
|
|
281
|
+
EditorState.readOnly.of(true), // ASIS는 읽기 전용 유지
|
|
282
|
+
asisDiffDecorations,
|
|
163
283
|
EditorView.updateListener.of((update) => {
|
|
164
284
|
if (update.view.contentDOM.firstChild && !update.view._initialAsisContentLoaded) {
|
|
165
285
|
update.view._initialAsisContentLoaded = true;
|
|
@@ -177,9 +297,9 @@ export class IdeDiff extends HTMLElement {
|
|
|
177
297
|
doc: '',
|
|
178
298
|
extensions: [
|
|
179
299
|
basicExtensions,
|
|
180
|
-
this.#languageCompartment.of(javascript()),
|
|
181
|
-
//EditorState.readOnly.of(true),
|
|
182
|
-
tobeDiffDecorations,
|
|
300
|
+
this.#languageCompartment.of(javascript()),
|
|
301
|
+
// EditorState.readOnly.of(true), // TOBE는 편집 가능하도록 주석 처리 유지
|
|
302
|
+
tobeDiffDecorations,
|
|
183
303
|
EditorView.updateListener.of((update) => {
|
|
184
304
|
if (update.view.contentDOM.firstChild && !update.view._initialTobeContentLoaded) {
|
|
185
305
|
update.view._initialTobeContentLoaded = true;
|
|
@@ -232,96 +352,66 @@ export class IdeDiff extends HTMLElement {
|
|
|
232
352
|
#applyDiffDecorations = (asisSrc, tobeSrc) => {
|
|
233
353
|
const dmp = new diff_match_patch();
|
|
234
354
|
|
|
235
|
-
// dmp의 기본 cleanupThreshold를 줄여서 더 세밀한 차이를 감지하도록 시도
|
|
236
|
-
// 기본값은 0.5인데, 0으로 하면 더 많은 변화를 감지할 수 있습니다.
|
|
237
|
-
// 하지만 너무 낮추면 노이즈가 많아질 수 있습니다.
|
|
238
|
-
// dmp.Diff_EditCost = 4; // 편집 비용 조정, 기본 4
|
|
239
|
-
// dmp.Diff_DualThreshold = 0.5; // 불명확한 Diff에 대한 임계값. 기본 0.5
|
|
240
|
-
// dmp.Diff_Timeout = 1.0; // 타임아웃, 기본 1.0
|
|
241
|
-
|
|
242
|
-
// 텍스트를 줄 단위로 변환하여 Diff 수행
|
|
243
355
|
const a = dmp.diff_linesToChars_(asisSrc, tobeSrc);
|
|
244
356
|
const lineText1 = a.chars1;
|
|
245
357
|
const lineText2 = a.chars2;
|
|
246
358
|
const lineArray = a.lineArray;
|
|
247
359
|
|
|
248
|
-
// dmp.diff_main(text1, text2, checklines, deadline)
|
|
249
|
-
// checklines: true (기본값)는 줄 단위 최적화, false는 문자 단위로.
|
|
250
|
-
// 여기서는 diff_linesToChars_를 사용했으므로 true가 적절.
|
|
251
360
|
const diffs = dmp.diff_main(lineText1, lineText2, true);
|
|
252
|
-
|
|
253
|
-
// cleanupEfficiency를 먼저 적용하여 효율적인 Diff를 만듭니다.
|
|
254
|
-
// 이는 작은 변경사항이 인접해 있을 때 하나의 큰 변경으로 합치는 경향이 있습니다.
|
|
255
|
-
// dmp.diff_cleanupEfficiency(diffs); // 오히려 이동을 놓칠 수 있음
|
|
256
|
-
|
|
257
|
-
// 그 다음 의미론적 정리를 적용합니다.
|
|
258
361
|
dmp.diff_cleanupSemantic(diffs);
|
|
259
|
-
|
|
260
|
-
// 다시 문자열로 변환
|
|
261
362
|
dmp.diff_charsToLines_(diffs, lineArray);
|
|
262
363
|
|
|
263
|
-
console.log(diffs);
|
|
364
|
+
console.log("Calculated Diffs:", diffs); // Diff 결과 확인용
|
|
264
365
|
|
|
265
366
|
const asisLineBuilder = new RangeSetBuilder();
|
|
266
367
|
const tobeLineBuilder = new RangeSetBuilder();
|
|
267
368
|
|
|
268
|
-
let asisCursor = 0;
|
|
269
|
-
let tobeCursor = 0;
|
|
369
|
+
let asisCursor = 0; // ASIS 텍스트에서의 현재 오프셋
|
|
370
|
+
let tobeCursor = 0; // TOBE 텍스트에서의 현재 오프셋
|
|
270
371
|
|
|
271
|
-
// 변경된 줄에 대한 새로운 데코레이션 클래스를 추가할 수 있습니다.
|
|
272
372
|
const insertedLineDeco = Decoration.line({ class: "cm-inserted-line-bg" });
|
|
273
373
|
const deletedLineDeco = Decoration.line({ class: "cm-deleted-line-bg" });
|
|
274
|
-
// const changedLineDeco = Decoration.line({ class: "cm-changed-line-bg" }); // 필요하다면
|
|
275
374
|
|
|
276
|
-
// ⭐️ IdeDiff 인스턴스에 대한 참조를 위젯에 넘겨주기 위해 임시 변수 사용
|
|
277
|
-
// 실제로는 Closure나 Bound method로 넘겨줄 수 있음
|
|
278
375
|
const currentInstance = this;
|
|
279
376
|
|
|
280
377
|
for (const [op, text] of diffs) {
|
|
281
378
|
const len = text.length;
|
|
282
379
|
|
|
283
|
-
//
|
|
284
|
-
const
|
|
285
|
-
const
|
|
380
|
+
// 각 diff op 이전에 현재 커서 위치를 저장
|
|
381
|
+
const asisRangeStart = asisCursor;
|
|
382
|
+
const tobeRangeStart = tobeCursor;
|
|
286
383
|
|
|
287
384
|
switch (op) {
|
|
288
|
-
case diff_match_patch.DIFF_INSERT:
|
|
289
|
-
console.log(
|
|
385
|
+
case diff_match_patch.DIFF_INSERT: // TOBE에 추가된 내용 (ASIS에는 없음)
|
|
386
|
+
console.log("DIFF_INSERT (TOBE added):", JSON.stringify(text));
|
|
290
387
|
const tobeLines = text.split('\n');
|
|
291
|
-
|
|
292
388
|
for (let i = 0; i < tobeLines.length; i++) {
|
|
293
|
-
// 빈 줄이 아니고, 마지막 줄이면서 줄바꿈이 없는 경우가 아니면 데코레이션
|
|
294
|
-
/**
|
|
295
|
-
if (!(i === tobeLines.length - 1 && tobeLines[i] === '' && !text.endsWith('\n'))) {
|
|
296
|
-
tobeLineBuilder.add(tobeCursor, tobeCursor, insertedLineDeco);
|
|
297
|
-
}
|
|
298
|
-
tobeCursor += tobeLines[i].length + (i < tobeLines.length - 1 ? 1 : 0);
|
|
299
|
-
*/
|
|
300
389
|
if (!(i === tobeLines.length - 1 && tobeLines[i] === '' && text.endsWith('\n'))) {
|
|
301
390
|
tobeLineBuilder.add(tobeCursor, tobeCursor, insertedLineDeco);
|
|
302
391
|
}
|
|
303
392
|
tobeCursor += tobeLines[i].length + (i < tobeLines.length - 1 ? 1 : 0);
|
|
304
393
|
}
|
|
305
394
|
|
|
395
|
+
// ⭐️ TOBE 에디터에 버튼 추가: TOBE의 추가 내용을 ASIS로 '되돌리기' (ASIS에서 삭제)
|
|
396
|
+
// 즉, TOBE에서 삽입된 내용을 ASIS에서 '없애는' 작업
|
|
306
397
|
tobeLineBuilder.add(
|
|
307
|
-
|
|
308
|
-
|
|
398
|
+
tobeRangeStart, // TOBE에서의 해당 Diff 청크 시작 오프셋
|
|
399
|
+
tobeRangeStart,
|
|
309
400
|
Decoration.widget({
|
|
310
|
-
widget:
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
),
|
|
401
|
+
widget: new MergeButtonWidget(
|
|
402
|
+
false, // 이 버튼은 TOBE 에디터에 붙는 버튼 (되돌리기)
|
|
403
|
+
"", // 텍스트를 ""로 삽입하면 삭제 효과 (ASIS에서 없앨 내용)
|
|
404
|
+
currentInstance.#asisEditorView, // 대상 에디터는 ASIS
|
|
405
|
+
{ from: asisRangeStart, to: asisRangeStart + 0 }, // ASIS에서의 대상 범위 (삽입 지점)
|
|
406
|
+
currentInstance
|
|
407
|
+
),
|
|
318
408
|
side: 1 // 텍스트 뒤에 삽입
|
|
319
409
|
})
|
|
320
410
|
);
|
|
321
411
|
break;
|
|
322
412
|
|
|
323
|
-
case diff_match_patch.DIFF_DELETE:
|
|
324
|
-
console.log(
|
|
413
|
+
case diff_match_patch.DIFF_DELETE: // ASIS에서 삭제된 내용 (TOBE에는 없음)
|
|
414
|
+
console.log("DIFF_DELETE (ASIS deleted):", JSON.stringify(text));
|
|
325
415
|
const asisLines = text.split('\n');
|
|
326
416
|
for (let i = 0; i < asisLines.length; i++) {
|
|
327
417
|
if (!(i === asisLines.length - 1 && asisLines[i] === '' && text.endsWith('\n'))) {
|
|
@@ -330,30 +420,28 @@ export class IdeDiff extends HTMLElement {
|
|
|
330
420
|
asisCursor += asisLines[i].length + (i < asisLines.length - 1 ? 1 : 0);
|
|
331
421
|
}
|
|
332
422
|
|
|
333
|
-
// ⭐️ ASIS
|
|
423
|
+
// ⭐️ ASIS 에디터에 버튼 추가: ASIS의 삭제 내용을 TOBE로 '적용' (TOBE에 삽입)
|
|
424
|
+
// 즉, ASIS에서 삭제된 내용을 TOBE에 '넣는' 작업
|
|
334
425
|
asisLineBuilder.add(
|
|
335
|
-
|
|
336
|
-
|
|
426
|
+
asisRangeStart, // ASIS에서의 해당 Diff 청크 시작 오프셋
|
|
427
|
+
asisRangeStart,
|
|
337
428
|
Decoration.widget({
|
|
338
429
|
widget: new MergeButtonWidget(
|
|
339
|
-
true, // ASIS
|
|
340
|
-
text,
|
|
341
|
-
currentInstance.#tobeEditorView //
|
|
430
|
+
true, // 이 버튼은 ASIS 에디터에 붙는 버튼 (적용)
|
|
431
|
+
text, // ASIS에서 삭제된 내용을 TOBE에 삽입
|
|
432
|
+
currentInstance.#tobeEditorView, // 대상 에디터는 TOBE
|
|
433
|
+
{ from: tobeRangeStart, to: tobeRangeStart + 0 }, // TOBE에서의 대상 범위 (삽입 지점)
|
|
434
|
+
currentInstance
|
|
342
435
|
),
|
|
343
436
|
side: 1 // 텍스트 뒤에 삽입
|
|
344
437
|
})
|
|
345
438
|
);
|
|
346
|
-
|
|
347
439
|
break;
|
|
348
440
|
|
|
349
|
-
case diff_match_patch.DIFF_EQUAL:
|
|
441
|
+
case diff_match_patch.DIFF_EQUAL: // 동일한 내용
|
|
350
442
|
asisCursor += len;
|
|
351
443
|
tobeCursor += len;
|
|
352
444
|
break;
|
|
353
|
-
|
|
354
|
-
default:
|
|
355
|
-
console.log(op);
|
|
356
|
-
break;
|
|
357
445
|
}
|
|
358
446
|
}
|
|
359
447
|
|
|
@@ -363,7 +451,6 @@ export class IdeDiff extends HTMLElement {
|
|
|
363
451
|
};
|
|
364
452
|
};
|
|
365
453
|
|
|
366
|
-
// IdeDiff 클래스 내부에 변경 후 Diff를 다시 계산하는 메서드 추가
|
|
367
454
|
recalculateDiff = () => {
|
|
368
455
|
const asisDoc = this.#asisEditorView.state.doc.toString();
|
|
369
456
|
const tobeDoc = this.#tobeEditorView.state.doc.toString();
|
|
@@ -426,69 +513,4 @@ export class IdeDiff extends HTMLElement {
|
|
|
426
513
|
};
|
|
427
514
|
}
|
|
428
515
|
|
|
429
|
-
// IdeDiff 클래스 외부 (파일 상단 or 하단)에 추가
|
|
430
|
-
class MergeButtonWidget extends WidgetType {
|
|
431
|
-
constructor(isAsis, textToApply, targetEditorView, diffRange, hostComponent) {
|
|
432
|
-
super();
|
|
433
|
-
this.isAsis = isAsis; // ASIS 쪽 버튼인지 (true) TOBE 쪽 버튼인지 (false)
|
|
434
|
-
this.textToApply = textToApply; // 적용할 텍스트
|
|
435
|
-
this.targetEditorView = targetEditorView; // 텍스트를 적용할 에디터 뷰
|
|
436
|
-
this.diffRange = diffRange; // ⭐️ 추가된 속성
|
|
437
|
-
this.hostComponent = hostComponent; // ⭐️ IdeDiff 인스턴스 참조
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// 위젯이 차지할 공간을 텍스트 줄에 할당할지 여부. false로 설정하여 버튼이 줄 사이에 끼어들지 않도록 함.
|
|
441
|
-
eq(other) { return false; }
|
|
442
|
-
|
|
443
|
-
// 위젯의 DOM 요소를 생성합니다.
|
|
444
|
-
toDOM(view) {
|
|
445
|
-
const button = document.createElement("button");
|
|
446
|
-
button.className = `cm-merge-button ${this.isAsis ? 'accept' : 'revert'}`;
|
|
447
|
-
button.textContent = this.isAsis ? "→ 적용" : "← 되돌리기"; // 버튼 텍스트
|
|
448
|
-
|
|
449
|
-
// 클릭 이벤트 핸들러
|
|
450
|
-
button.addEventListener("click", () => {
|
|
451
|
-
// 이 로직은 나중에 구현할 `applyChanges` 메서드를 호출할 것입니다.
|
|
452
|
-
// 지금은 콘솔에 로그만 남깁니다.
|
|
453
|
-
console.log(`버튼 클릭: ${this.isAsis ? 'ASIS -> TOBE' : 'TOBE -> ASIS'}`, this.textToApply);
|
|
454
|
-
|
|
455
|
-
// 실제 변경 로직 (아래 applyChanges 메서드 구현 후 주석 해제)
|
|
456
|
-
this.applyChanges(this.textToApply, this.targetEditorView);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
const container = document.createElement("div");
|
|
460
|
-
container.className = "cm-merge-button-container";
|
|
461
|
-
container.appendChild(button);
|
|
462
|
-
return container;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// 실제 변경 적용 로직
|
|
466
|
-
applyChanges(text, editorView) {
|
|
467
|
-
if (!editorView || !this.diffRange) {
|
|
468
|
-
console.error("Target editor view or diffRange is undefined.");
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// ⭐️ 해당 오프셋 범위의 내용을 교체 (삽입 또는 삭제)
|
|
473
|
-
editorView.dispatch({
|
|
474
|
-
changes: {
|
|
475
|
-
from: this.diffRange.from,
|
|
476
|
-
to: this.diffRange.to, // 삭제될 범위
|
|
477
|
-
insert: text // 삽입될 내용
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
// 변경 후 Diff를 다시 계산하고 데코레이션을 업데이트해야 합니다.
|
|
482
|
-
// this.hostComponent.recalculateDiff(); 와 같은 메서드를 호출해야 함.
|
|
483
|
-
// 이 부분은 IdeDiff 클래스 내에서 구현해야 합니다.
|
|
484
|
-
// 일단은 콘솔 로그와 함께 작동하는지 확인합니다.
|
|
485
|
-
console.log("Changes applied and diff recalculation needed!");
|
|
486
|
-
|
|
487
|
-
// 변경 후 Diff를 다시 계산하고 데코레이션을 업데이트합니다.
|
|
488
|
-
this.hostComponent.recalculateDiff(); // ⭐️ hostComponent를 통해 메서드 호출
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
516
|
customElements.define("ide-diff", IdeDiff);
|