ide-assi 0.343.0 → 0.344.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.
@@ -234948,58 +234948,57 @@ class IdeDiff extends HTMLElement {
234948
234948
  const diffs = dmp.diff_main(asisSrc, tobeSrc);
234949
234949
  dmp.diff_cleanupSemantic(diffs);
234950
234950
 
234951
- // 모든 데코레이션을 builder에 추가하기 전에 수집합니다.
234952
- const asisDecorationsToAdd = [];
234953
- const tobeDecorationsToAdd = [];
234951
+ // Separate collections for line decorations and mark decorations
234952
+ const asisLineDecos = [];
234953
+ const asisMarkDecos = [];
234954
+ const tobeLineDecos = [];
234955
+ const tobeMarkDecos = [];
234954
234956
 
234955
- let asisCursor = 0; // asis 에디터에서의 현재 텍스트 오프셋
234956
- let tobeCursor = 0; // tobe 에디터에서의 현재 텍스트 오프셋
234957
+ let asisCursor = 0;
234958
+ let tobeCursor = 0;
234957
234959
 
234958
234960
  for (const [op, text] of diffs) {
234959
234961
  const len = text.length;
234960
234962
 
234961
234963
  switch (op) {
234962
- case diffMatchPatchExports.diff_match_patch.DIFF_INSERT: // 추가된 텍스트
234963
- // tobe 쪽에 인라인 데코레이션 추가
234964
- tobeDecorationsToAdd.push({
234964
+ case diffMatchPatchExports.diff_match_patch.DIFF_INSERT: // Added text
234965
+ // Inline mark decoration for tobe
234966
+ tobeMarkDecos.push({
234965
234967
  from: tobeCursor,
234966
234968
  to: tobeCursor + len,
234967
234969
  deco: Decoration.mark({ class: "cm-inserted-inline" })
234968
234970
  });
234969
234971
 
234970
- // tobe 쪽에 배경 데코레이션 추가 (삽입된 )
234971
- // text가 여러 줄일 수 있으므로 각 줄에 적용
234972
+ // Line background decoration for tobe (for each line in the inserted text)
234972
234973
  let currentTobeLineOffset = tobeCursor;
234973
234974
  const tobeLines = text.split('\n');
234974
234975
  for (let i = 0; i < tobeLines.length; i++) {
234975
- // 현재 에디터 뷰의 문서에서 줄 정보를 가져옵니다.
234976
- // 이전에 `tobeEditorView`가 전역 변수처럼 사용되었을 가능성을 위해 `this.#tobeEditorView`로 명시
234977
234976
  const line = this.#tobeEditorView.state.doc.lineAt(currentTobeLineOffset);
234978
- tobeDecorationsToAdd.push({
234977
+ tobeLineDecos.push({
234979
234978
  from: line.from,
234980
234979
  to: line.to,
234981
234980
  deco: Decoration.line({ class: "cm-inserted-line-bg" })
234982
234981
  });
234983
- currentTobeLineOffset += tobeLines[i].length + 1; // 다음 시작 위치로 이동
234982
+ currentTobeLineOffset += tobeLines[i].length + 1; // Move to the start of the next line segment
234984
234983
  }
234985
234984
 
234986
234985
  tobeCursor += len;
234987
234986
  break;
234988
234987
 
234989
- case diffMatchPatchExports.diff_match_patch.DIFF_DELETE: // 삭제된 텍스트
234990
- // asis 쪽에 인라인 데코레이션 추가
234991
- asisDecorationsToAdd.push({
234988
+ case diffMatchPatchExports.diff_match_patch.DIFF_DELETE: // Deleted text
234989
+ // Inline mark decoration for asis
234990
+ asisMarkDecos.push({
234992
234991
  from: asisCursor,
234993
234992
  to: asisCursor + len,
234994
234993
  deco: Decoration.mark({ class: "cm-deleted-inline" })
234995
234994
  });
234996
234995
 
234997
- // asis 쪽에 배경 데코레이션 추가 (삭제된 )
234996
+ // Line background decoration for asis (for each line in the deleted text)
234998
234997
  let currentAsisLineOffset = asisCursor;
234999
234998
  const asisLines = text.split('\n');
235000
234999
  for (let i = 0; i < asisLines.length; i++) {
235001
235000
  const line = this.#asisEditorView.state.doc.lineAt(currentAsisLineOffset);
235002
- asisDecorationsToAdd.push({
235001
+ asisLineDecos.push({
235003
235002
  from: line.from,
235004
235003
  to: line.to,
235005
235004
  deco: Decoration.line({ class: "cm-deleted-line-bg" })
@@ -235010,34 +235009,59 @@ class IdeDiff extends HTMLElement {
235010
235009
  asisCursor += len;
235011
235010
  break;
235012
235011
 
235013
- case diffMatchPatchExports.diff_match_patch.DIFF_EQUAL: // 변경되지 않은 텍스트
235012
+ case diffMatchPatchExports.diff_match_patch.DIFF_EQUAL: // Unchanged text
235014
235013
  asisCursor += len;
235015
235014
  tobeCursor += len;
235016
235015
  break;
235017
235016
  }
235018
235017
  }
235019
235018
 
235020
- // ⭐️ 중요: 데코레이션들을 'from' 위치를 기준으로 정렬합니다.
235021
- asisDecorationsToAdd.sort((a, b) => a.from - b.from);
235022
- tobeDecorationsToAdd.sort((a, b) => a.from - b.from);
235019
+ // Sort all collections by 'from' position
235020
+ // Although separating builders helps, sorting is still a good practice.
235021
+ asisLineDecos.sort((a, b) => a.from - b.from);
235022
+ asisMarkDecos.sort((a, b) => a.from - b.from);
235023
+ tobeLineDecos.sort((a, b) => a.from - b.from);
235024
+ tobeMarkDecos.sort((a, b) => a.from - b.from);
235023
235025
 
235024
- // 정렬된 데코레이션들을 RangeSetBuilder에 추가합니다.
235025
- const asisBuilder = new RangeSetBuilder();
235026
- for (const { from, to, deco } of asisDecorationsToAdd) {
235027
- asisBuilder.add(from, to, deco);
235026
+ // Build separate RangeSets for lines and marks for ASIS editor
235027
+ const asisLineBuilder = new RangeSetBuilder();
235028
+ for (const { from, to, deco } of asisLineDecos) {
235029
+ asisLineBuilder.add(from, to, deco);
235028
235030
  }
235031
+ const asisMarkBuilder = new RangeSetBuilder();
235032
+ for (const { from, to, deco } of asisMarkDecos) {
235033
+ asisMarkBuilder.add(from, to, deco);
235034
+ }
235035
+
235036
+ // Combine line and mark RangeSets for ASIS editor
235037
+ // The `RangeSet.join()` static method is used to combine multiple RangeSets.
235038
+ const finalAsisDecorations = asisLineBuilder.finish().update({
235039
+ add: asisMarkBuilder.finish().children // Combine children of mark builder's RangeSet
235040
+ });
235041
+
235029
235042
 
235030
- const tobeBuilder = new RangeSetBuilder();
235031
- for (const { from, to, deco } of tobeDecorationsToAdd) {
235032
- tobeBuilder.add(from, to, deco);
235043
+ // Build separate RangeSets for lines and marks for TOBE editor
235044
+ const tobeLineBuilder = new RangeSetBuilder();
235045
+ for (const { from, to, deco } of tobeLineDecos) {
235046
+ tobeLineBuilder.add(from, to, deco);
235033
235047
  }
235048
+ const tobeMarkBuilder = new RangeSetBuilder();
235049
+ for (const { from, to, deco } of tobeMarkDecos) {
235050
+ tobeMarkBuilder.add(from, to, deco);
235051
+ }
235052
+
235053
+ // Combine line and mark RangeSets for TOBE editor
235054
+ const finalTobeDecorations = tobeLineBuilder.finish().update({
235055
+ add: tobeMarkBuilder.finish().children
235056
+ });
235057
+
235034
235058
 
235035
- // 데코레이션 업데이트를 위한 Effect를 디스패치합니다.
235059
+ // Dispatch effects to update decorations
235036
235060
  this.#asisEditorView.dispatch({
235037
- effects: setAsisDecorationsEffect.of(asisBuilder.finish())
235061
+ effects: setAsisDecorationsEffect.of(finalAsisDecorations)
235038
235062
  });
235039
235063
  this.#tobeEditorView.dispatch({
235040
- effects: setTobeDecorationsEffect.of(tobeBuilder.finish())
235064
+ effects: setTobeDecorationsEffect.of(finalTobeDecorations)
235041
235065
  });
235042
235066
  };
235043
235067
 
@@ -234944,58 +234944,57 @@ class IdeDiff extends HTMLElement {
234944
234944
  const diffs = dmp.diff_main(asisSrc, tobeSrc);
234945
234945
  dmp.diff_cleanupSemantic(diffs);
234946
234946
 
234947
- // 모든 데코레이션을 builder에 추가하기 전에 수집합니다.
234948
- const asisDecorationsToAdd = [];
234949
- const tobeDecorationsToAdd = [];
234947
+ // Separate collections for line decorations and mark decorations
234948
+ const asisLineDecos = [];
234949
+ const asisMarkDecos = [];
234950
+ const tobeLineDecos = [];
234951
+ const tobeMarkDecos = [];
234950
234952
 
234951
- let asisCursor = 0; // asis 에디터에서의 현재 텍스트 오프셋
234952
- let tobeCursor = 0; // tobe 에디터에서의 현재 텍스트 오프셋
234953
+ let asisCursor = 0;
234954
+ let tobeCursor = 0;
234953
234955
 
234954
234956
  for (const [op, text] of diffs) {
234955
234957
  const len = text.length;
234956
234958
 
234957
234959
  switch (op) {
234958
- case diffMatchPatchExports.diff_match_patch.DIFF_INSERT: // 추가된 텍스트
234959
- // tobe 쪽에 인라인 데코레이션 추가
234960
- tobeDecorationsToAdd.push({
234960
+ case diffMatchPatchExports.diff_match_patch.DIFF_INSERT: // Added text
234961
+ // Inline mark decoration for tobe
234962
+ tobeMarkDecos.push({
234961
234963
  from: tobeCursor,
234962
234964
  to: tobeCursor + len,
234963
234965
  deco: Decoration.mark({ class: "cm-inserted-inline" })
234964
234966
  });
234965
234967
 
234966
- // tobe 쪽에 배경 데코레이션 추가 (삽입된 )
234967
- // text가 여러 줄일 수 있으므로 각 줄에 적용
234968
+ // Line background decoration for tobe (for each line in the inserted text)
234968
234969
  let currentTobeLineOffset = tobeCursor;
234969
234970
  const tobeLines = text.split('\n');
234970
234971
  for (let i = 0; i < tobeLines.length; i++) {
234971
- // 현재 에디터 뷰의 문서에서 줄 정보를 가져옵니다.
234972
- // 이전에 `tobeEditorView`가 전역 변수처럼 사용되었을 가능성을 위해 `this.#tobeEditorView`로 명시
234973
234972
  const line = this.#tobeEditorView.state.doc.lineAt(currentTobeLineOffset);
234974
- tobeDecorationsToAdd.push({
234973
+ tobeLineDecos.push({
234975
234974
  from: line.from,
234976
234975
  to: line.to,
234977
234976
  deco: Decoration.line({ class: "cm-inserted-line-bg" })
234978
234977
  });
234979
- currentTobeLineOffset += tobeLines[i].length + 1; // 다음 시작 위치로 이동
234978
+ currentTobeLineOffset += tobeLines[i].length + 1; // Move to the start of the next line segment
234980
234979
  }
234981
234980
 
234982
234981
  tobeCursor += len;
234983
234982
  break;
234984
234983
 
234985
- case diffMatchPatchExports.diff_match_patch.DIFF_DELETE: // 삭제된 텍스트
234986
- // asis 쪽에 인라인 데코레이션 추가
234987
- asisDecorationsToAdd.push({
234984
+ case diffMatchPatchExports.diff_match_patch.DIFF_DELETE: // Deleted text
234985
+ // Inline mark decoration for asis
234986
+ asisMarkDecos.push({
234988
234987
  from: asisCursor,
234989
234988
  to: asisCursor + len,
234990
234989
  deco: Decoration.mark({ class: "cm-deleted-inline" })
234991
234990
  });
234992
234991
 
234993
- // asis 쪽에 배경 데코레이션 추가 (삭제된 )
234992
+ // Line background decoration for asis (for each line in the deleted text)
234994
234993
  let currentAsisLineOffset = asisCursor;
234995
234994
  const asisLines = text.split('\n');
234996
234995
  for (let i = 0; i < asisLines.length; i++) {
234997
234996
  const line = this.#asisEditorView.state.doc.lineAt(currentAsisLineOffset);
234998
- asisDecorationsToAdd.push({
234997
+ asisLineDecos.push({
234999
234998
  from: line.from,
235000
234999
  to: line.to,
235001
235000
  deco: Decoration.line({ class: "cm-deleted-line-bg" })
@@ -235006,34 +235005,59 @@ class IdeDiff extends HTMLElement {
235006
235005
  asisCursor += len;
235007
235006
  break;
235008
235007
 
235009
- case diffMatchPatchExports.diff_match_patch.DIFF_EQUAL: // 변경되지 않은 텍스트
235008
+ case diffMatchPatchExports.diff_match_patch.DIFF_EQUAL: // Unchanged text
235010
235009
  asisCursor += len;
235011
235010
  tobeCursor += len;
235012
235011
  break;
235013
235012
  }
235014
235013
  }
235015
235014
 
235016
- // ⭐️ 중요: 데코레이션들을 'from' 위치를 기준으로 정렬합니다.
235017
- asisDecorationsToAdd.sort((a, b) => a.from - b.from);
235018
- tobeDecorationsToAdd.sort((a, b) => a.from - b.from);
235015
+ // Sort all collections by 'from' position
235016
+ // Although separating builders helps, sorting is still a good practice.
235017
+ asisLineDecos.sort((a, b) => a.from - b.from);
235018
+ asisMarkDecos.sort((a, b) => a.from - b.from);
235019
+ tobeLineDecos.sort((a, b) => a.from - b.from);
235020
+ tobeMarkDecos.sort((a, b) => a.from - b.from);
235019
235021
 
235020
- // 정렬된 데코레이션들을 RangeSetBuilder에 추가합니다.
235021
- const asisBuilder = new RangeSetBuilder();
235022
- for (const { from, to, deco } of asisDecorationsToAdd) {
235023
- asisBuilder.add(from, to, deco);
235022
+ // Build separate RangeSets for lines and marks for ASIS editor
235023
+ const asisLineBuilder = new RangeSetBuilder();
235024
+ for (const { from, to, deco } of asisLineDecos) {
235025
+ asisLineBuilder.add(from, to, deco);
235024
235026
  }
235027
+ const asisMarkBuilder = new RangeSetBuilder();
235028
+ for (const { from, to, deco } of asisMarkDecos) {
235029
+ asisMarkBuilder.add(from, to, deco);
235030
+ }
235031
+
235032
+ // Combine line and mark RangeSets for ASIS editor
235033
+ // The `RangeSet.join()` static method is used to combine multiple RangeSets.
235034
+ const finalAsisDecorations = asisLineBuilder.finish().update({
235035
+ add: asisMarkBuilder.finish().children // Combine children of mark builder's RangeSet
235036
+ });
235037
+
235025
235038
 
235026
- const tobeBuilder = new RangeSetBuilder();
235027
- for (const { from, to, deco } of tobeDecorationsToAdd) {
235028
- tobeBuilder.add(from, to, deco);
235039
+ // Build separate RangeSets for lines and marks for TOBE editor
235040
+ const tobeLineBuilder = new RangeSetBuilder();
235041
+ for (const { from, to, deco } of tobeLineDecos) {
235042
+ tobeLineBuilder.add(from, to, deco);
235029
235043
  }
235044
+ const tobeMarkBuilder = new RangeSetBuilder();
235045
+ for (const { from, to, deco } of tobeMarkDecos) {
235046
+ tobeMarkBuilder.add(from, to, deco);
235047
+ }
235048
+
235049
+ // Combine line and mark RangeSets for TOBE editor
235050
+ const finalTobeDecorations = tobeLineBuilder.finish().update({
235051
+ add: tobeMarkBuilder.finish().children
235052
+ });
235053
+
235030
235054
 
235031
- // 데코레이션 업데이트를 위한 Effect를 디스패치합니다.
235055
+ // Dispatch effects to update decorations
235032
235056
  this.#asisEditorView.dispatch({
235033
- effects: setAsisDecorationsEffect.of(asisBuilder.finish())
235057
+ effects: setAsisDecorationsEffect.of(finalAsisDecorations)
235034
235058
  });
235035
235059
  this.#tobeEditorView.dispatch({
235036
- effects: setTobeDecorationsEffect.of(tobeBuilder.finish())
235060
+ effects: setTobeDecorationsEffect.of(finalTobeDecorations)
235037
235061
  });
235038
235062
  };
235039
235063
 
@@ -221,58 +221,57 @@ export class IdeDiff extends HTMLElement {
221
221
  const diffs = dmp.diff_main(asisSrc, tobeSrc);
222
222
  dmp.diff_cleanupSemantic(diffs);
223
223
 
224
- // 모든 데코레이션을 builder에 추가하기 전에 수집합니다.
225
- const asisDecorationsToAdd = [];
226
- const tobeDecorationsToAdd = [];
224
+ // Separate collections for line decorations and mark decorations
225
+ const asisLineDecos = [];
226
+ const asisMarkDecos = [];
227
+ const tobeLineDecos = [];
228
+ const tobeMarkDecos = [];
227
229
 
228
- let asisCursor = 0; // asis 에디터에서의 현재 텍스트 오프셋
229
- let tobeCursor = 0; // tobe 에디터에서의 현재 텍스트 오프셋
230
+ let asisCursor = 0;
231
+ let tobeCursor = 0;
230
232
 
231
233
  for (const [op, text] of diffs) {
232
234
  const len = text.length;
233
235
 
234
236
  switch (op) {
235
- case diff_match_patch.DIFF_INSERT: // 추가된 텍스트
236
- // tobe 쪽에 인라인 데코레이션 추가
237
- tobeDecorationsToAdd.push({
237
+ case diff_match_patch.DIFF_INSERT: // Added text
238
+ // Inline mark decoration for tobe
239
+ tobeMarkDecos.push({
238
240
  from: tobeCursor,
239
241
  to: tobeCursor + len,
240
242
  deco: Decoration.mark({ class: "cm-inserted-inline" })
241
243
  });
242
244
 
243
- // tobe 쪽에 배경 데코레이션 추가 (삽입된 )
244
- // text가 여러 줄일 수 있으므로 각 줄에 적용
245
+ // Line background decoration for tobe (for each line in the inserted text)
245
246
  let currentTobeLineOffset = tobeCursor;
246
247
  const tobeLines = text.split('\n');
247
248
  for (let i = 0; i < tobeLines.length; i++) {
248
- // 현재 에디터 뷰의 문서에서 줄 정보를 가져옵니다.
249
- // 이전에 `tobeEditorView`가 전역 변수처럼 사용되었을 가능성을 위해 `this.#tobeEditorView`로 명시
250
249
  const line = this.#tobeEditorView.state.doc.lineAt(currentTobeLineOffset);
251
- tobeDecorationsToAdd.push({
250
+ tobeLineDecos.push({
252
251
  from: line.from,
253
252
  to: line.to,
254
253
  deco: Decoration.line({ class: "cm-inserted-line-bg" })
255
254
  });
256
- currentTobeLineOffset += tobeLines[i].length + 1; // 다음 시작 위치로 이동
255
+ currentTobeLineOffset += tobeLines[i].length + 1; // Move to the start of the next line segment
257
256
  }
258
257
 
259
258
  tobeCursor += len;
260
259
  break;
261
260
 
262
- case diff_match_patch.DIFF_DELETE: // 삭제된 텍스트
263
- // asis 쪽에 인라인 데코레이션 추가
264
- asisDecorationsToAdd.push({
261
+ case diff_match_patch.DIFF_DELETE: // Deleted text
262
+ // Inline mark decoration for asis
263
+ asisMarkDecos.push({
265
264
  from: asisCursor,
266
265
  to: asisCursor + len,
267
266
  deco: Decoration.mark({ class: "cm-deleted-inline" })
268
267
  });
269
268
 
270
- // asis 쪽에 배경 데코레이션 추가 (삭제된 )
269
+ // Line background decoration for asis (for each line in the deleted text)
271
270
  let currentAsisLineOffset = asisCursor;
272
271
  const asisLines = text.split('\n');
273
272
  for (let i = 0; i < asisLines.length; i++) {
274
273
  const line = this.#asisEditorView.state.doc.lineAt(currentAsisLineOffset);
275
- asisDecorationsToAdd.push({
274
+ asisLineDecos.push({
276
275
  from: line.from,
277
276
  to: line.to,
278
277
  deco: Decoration.line({ class: "cm-deleted-line-bg" })
@@ -283,34 +282,59 @@ export class IdeDiff extends HTMLElement {
283
282
  asisCursor += len;
284
283
  break;
285
284
 
286
- case diff_match_patch.DIFF_EQUAL: // 변경되지 않은 텍스트
285
+ case diff_match_patch.DIFF_EQUAL: // Unchanged text
287
286
  asisCursor += len;
288
287
  tobeCursor += len;
289
288
  break;
290
289
  }
291
290
  }
292
291
 
293
- // ⭐️ 중요: 데코레이션들을 'from' 위치를 기준으로 정렬합니다.
294
- asisDecorationsToAdd.sort((a, b) => a.from - b.from);
295
- tobeDecorationsToAdd.sort((a, b) => a.from - b.from);
296
-
297
- // 정렬된 데코레이션들을 RangeSetBuilder에 추가합니다.
298
- const asisBuilder = new RangeSetBuilder();
299
- for (const { from, to, deco } of asisDecorationsToAdd) {
300
- asisBuilder.add(from, to, deco);
292
+ // Sort all collections by 'from' position
293
+ // Although separating builders helps, sorting is still a good practice.
294
+ asisLineDecos.sort((a, b) => a.from - b.from);
295
+ asisMarkDecos.sort((a, b) => a.from - b.from);
296
+ tobeLineDecos.sort((a, b) => a.from - b.from);
297
+ tobeMarkDecos.sort((a, b) => a.from - b.from);
298
+
299
+ // Build separate RangeSets for lines and marks for ASIS editor
300
+ const asisLineBuilder = new RangeSetBuilder();
301
+ for (const { from, to, deco } of asisLineDecos) {
302
+ asisLineBuilder.add(from, to, deco);
303
+ }
304
+ const asisMarkBuilder = new RangeSetBuilder();
305
+ for (const { from, to, deco } of asisMarkDecos) {
306
+ asisMarkBuilder.add(from, to, deco);
301
307
  }
302
308
 
303
- const tobeBuilder = new RangeSetBuilder();
304
- for (const { from, to, deco } of tobeDecorationsToAdd) {
305
- tobeBuilder.add(from, to, deco);
309
+ // Combine line and mark RangeSets for ASIS editor
310
+ // The `RangeSet.join()` static method is used to combine multiple RangeSets.
311
+ const finalAsisDecorations = asisLineBuilder.finish().update({
312
+ add: asisMarkBuilder.finish().children // Combine children of mark builder's RangeSet
313
+ });
314
+
315
+
316
+ // Build separate RangeSets for lines and marks for TOBE editor
317
+ const tobeLineBuilder = new RangeSetBuilder();
318
+ for (const { from, to, deco } of tobeLineDecos) {
319
+ tobeLineBuilder.add(from, to, deco);
306
320
  }
321
+ const tobeMarkBuilder = new RangeSetBuilder();
322
+ for (const { from, to, deco } of tobeMarkDecos) {
323
+ tobeMarkBuilder.add(from, to, deco);
324
+ }
325
+
326
+ // Combine line and mark RangeSets for TOBE editor
327
+ const finalTobeDecorations = tobeLineBuilder.finish().update({
328
+ add: tobeMarkBuilder.finish().children
329
+ });
330
+
307
331
 
308
- // 데코레이션 업데이트를 위한 Effect를 디스패치합니다.
332
+ // Dispatch effects to update decorations
309
333
  this.#asisEditorView.dispatch({
310
- effects: setAsisDecorationsEffect.of(asisBuilder.finish())
334
+ effects: setAsisDecorationsEffect.of(finalAsisDecorations)
311
335
  });
312
336
  this.#tobeEditorView.dispatch({
313
- effects: setTobeDecorationsEffect.of(tobeBuilder.finish())
337
+ effects: setTobeDecorationsEffect.of(finalTobeDecorations)
314
338
  });
315
339
  };
316
340
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ide-assi",
3
3
  "type": "module",
4
- "version": "0.343.0",
4
+ "version": "0.344.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -221,58 +221,57 @@ export class IdeDiff extends HTMLElement {
221
221
  const diffs = dmp.diff_main(asisSrc, tobeSrc);
222
222
  dmp.diff_cleanupSemantic(diffs);
223
223
 
224
- // 모든 데코레이션을 builder에 추가하기 전에 수집합니다.
225
- const asisDecorationsToAdd = [];
226
- const tobeDecorationsToAdd = [];
224
+ // Separate collections for line decorations and mark decorations
225
+ const asisLineDecos = [];
226
+ const asisMarkDecos = [];
227
+ const tobeLineDecos = [];
228
+ const tobeMarkDecos = [];
227
229
 
228
- let asisCursor = 0; // asis 에디터에서의 현재 텍스트 오프셋
229
- let tobeCursor = 0; // tobe 에디터에서의 현재 텍스트 오프셋
230
+ let asisCursor = 0;
231
+ let tobeCursor = 0;
230
232
 
231
233
  for (const [op, text] of diffs) {
232
234
  const len = text.length;
233
235
 
234
236
  switch (op) {
235
- case diff_match_patch.DIFF_INSERT: // 추가된 텍스트
236
- // tobe 쪽에 인라인 데코레이션 추가
237
- tobeDecorationsToAdd.push({
237
+ case diff_match_patch.DIFF_INSERT: // Added text
238
+ // Inline mark decoration for tobe
239
+ tobeMarkDecos.push({
238
240
  from: tobeCursor,
239
241
  to: tobeCursor + len,
240
242
  deco: Decoration.mark({ class: "cm-inserted-inline" })
241
243
  });
242
244
 
243
- // tobe 쪽에 배경 데코레이션 추가 (삽입된 )
244
- // text가 여러 줄일 수 있으므로 각 줄에 적용
245
+ // Line background decoration for tobe (for each line in the inserted text)
245
246
  let currentTobeLineOffset = tobeCursor;
246
247
  const tobeLines = text.split('\n');
247
248
  for (let i = 0; i < tobeLines.length; i++) {
248
- // 현재 에디터 뷰의 문서에서 줄 정보를 가져옵니다.
249
- // 이전에 `tobeEditorView`가 전역 변수처럼 사용되었을 가능성을 위해 `this.#tobeEditorView`로 명시
250
249
  const line = this.#tobeEditorView.state.doc.lineAt(currentTobeLineOffset);
251
- tobeDecorationsToAdd.push({
250
+ tobeLineDecos.push({
252
251
  from: line.from,
253
252
  to: line.to,
254
253
  deco: Decoration.line({ class: "cm-inserted-line-bg" })
255
254
  });
256
- currentTobeLineOffset += tobeLines[i].length + 1; // 다음 시작 위치로 이동
255
+ currentTobeLineOffset += tobeLines[i].length + 1; // Move to the start of the next line segment
257
256
  }
258
257
 
259
258
  tobeCursor += len;
260
259
  break;
261
260
 
262
- case diff_match_patch.DIFF_DELETE: // 삭제된 텍스트
263
- // asis 쪽에 인라인 데코레이션 추가
264
- asisDecorationsToAdd.push({
261
+ case diff_match_patch.DIFF_DELETE: // Deleted text
262
+ // Inline mark decoration for asis
263
+ asisMarkDecos.push({
265
264
  from: asisCursor,
266
265
  to: asisCursor + len,
267
266
  deco: Decoration.mark({ class: "cm-deleted-inline" })
268
267
  });
269
268
 
270
- // asis 쪽에 배경 데코레이션 추가 (삭제된 )
269
+ // Line background decoration for asis (for each line in the deleted text)
271
270
  let currentAsisLineOffset = asisCursor;
272
271
  const asisLines = text.split('\n');
273
272
  for (let i = 0; i < asisLines.length; i++) {
274
273
  const line = this.#asisEditorView.state.doc.lineAt(currentAsisLineOffset);
275
- asisDecorationsToAdd.push({
274
+ asisLineDecos.push({
276
275
  from: line.from,
277
276
  to: line.to,
278
277
  deco: Decoration.line({ class: "cm-deleted-line-bg" })
@@ -283,34 +282,59 @@ export class IdeDiff extends HTMLElement {
283
282
  asisCursor += len;
284
283
  break;
285
284
 
286
- case diff_match_patch.DIFF_EQUAL: // 변경되지 않은 텍스트
285
+ case diff_match_patch.DIFF_EQUAL: // Unchanged text
287
286
  asisCursor += len;
288
287
  tobeCursor += len;
289
288
  break;
290
289
  }
291
290
  }
292
291
 
293
- // ⭐️ 중요: 데코레이션들을 'from' 위치를 기준으로 정렬합니다.
294
- asisDecorationsToAdd.sort((a, b) => a.from - b.from);
295
- tobeDecorationsToAdd.sort((a, b) => a.from - b.from);
296
-
297
- // 정렬된 데코레이션들을 RangeSetBuilder에 추가합니다.
298
- const asisBuilder = new RangeSetBuilder();
299
- for (const { from, to, deco } of asisDecorationsToAdd) {
300
- asisBuilder.add(from, to, deco);
292
+ // Sort all collections by 'from' position
293
+ // Although separating builders helps, sorting is still a good practice.
294
+ asisLineDecos.sort((a, b) => a.from - b.from);
295
+ asisMarkDecos.sort((a, b) => a.from - b.from);
296
+ tobeLineDecos.sort((a, b) => a.from - b.from);
297
+ tobeMarkDecos.sort((a, b) => a.from - b.from);
298
+
299
+ // Build separate RangeSets for lines and marks for ASIS editor
300
+ const asisLineBuilder = new RangeSetBuilder();
301
+ for (const { from, to, deco } of asisLineDecos) {
302
+ asisLineBuilder.add(from, to, deco);
303
+ }
304
+ const asisMarkBuilder = new RangeSetBuilder();
305
+ for (const { from, to, deco } of asisMarkDecos) {
306
+ asisMarkBuilder.add(from, to, deco);
301
307
  }
302
308
 
303
- const tobeBuilder = new RangeSetBuilder();
304
- for (const { from, to, deco } of tobeDecorationsToAdd) {
305
- tobeBuilder.add(from, to, deco);
309
+ // Combine line and mark RangeSets for ASIS editor
310
+ // The `RangeSet.join()` static method is used to combine multiple RangeSets.
311
+ const finalAsisDecorations = asisLineBuilder.finish().update({
312
+ add: asisMarkBuilder.finish().children // Combine children of mark builder's RangeSet
313
+ });
314
+
315
+
316
+ // Build separate RangeSets for lines and marks for TOBE editor
317
+ const tobeLineBuilder = new RangeSetBuilder();
318
+ for (const { from, to, deco } of tobeLineDecos) {
319
+ tobeLineBuilder.add(from, to, deco);
306
320
  }
321
+ const tobeMarkBuilder = new RangeSetBuilder();
322
+ for (const { from, to, deco } of tobeMarkDecos) {
323
+ tobeMarkBuilder.add(from, to, deco);
324
+ }
325
+
326
+ // Combine line and mark RangeSets for TOBE editor
327
+ const finalTobeDecorations = tobeLineBuilder.finish().update({
328
+ add: tobeMarkBuilder.finish().children
329
+ });
330
+
307
331
 
308
- // 데코레이션 업데이트를 위한 Effect를 디스패치합니다.
332
+ // Dispatch effects to update decorations
309
333
  this.#asisEditorView.dispatch({
310
- effects: setAsisDecorationsEffect.of(asisBuilder.finish())
334
+ effects: setAsisDecorationsEffect.of(finalAsisDecorations)
311
335
  });
312
336
  this.#tobeEditorView.dispatch({
313
- effects: setTobeDecorationsEffect.of(tobeBuilder.finish())
337
+ effects: setTobeDecorationsEffect.of(finalTobeDecorations)
314
338
  });
315
339
  };
316
340