Skip to content

Commit 34347ad

Browse files
committed
feat: add support for single-sided copy
1 parent 3cef953 commit 34347ad

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

src/split/SplitLine.vue

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ function getCodeMarker(type: DiffType) {
1515
return '+'
1616
return ''
1717
}
18+
19+
function onSplitLineMousedown(side: 'left' | 'right') {
20+
window.getSelection()!.removeAllRanges()
21+
22+
const leftElements = document.querySelectorAll('.file-diff-split .split-side-left')!
23+
const rightElements = document.querySelectorAll('.file-diff-split .split-side-right')!
24+
25+
for (const el of rightElements)
26+
el.classList.toggle('no-select', side === 'left')
27+
28+
for (const el of leftElements)
29+
el.classList.toggle('no-select', side === 'right')
30+
}
1831
</script>
1932

2033
<template>
@@ -27,31 +40,40 @@ function getCodeMarker(type: DiffType) {
2740
</td>
2841
</tr>
2942
<tr v-else-if="!splitLine.hide">
30-
<template v-for="line in [splitLine.left, splitLine.right]">
43+
<template v-for="(line, index) in [splitLine.left, splitLine.right]">
3144
<!-- eslint-disable -->
3245
<template v-if="line.type === DiffType.EMPTY">
3346
<td class="blob-num blob-num-empty empty-cell" />
3447
<td class="blob-code blob-code-empty empty-cell" />
3548
</template>
3649
<template v-else>
37-
<td class="blob-num" :class="{
38-
'blob-num-deletion': line.type === DiffType.DELETE,
39-
'blob-num-addition': line.type === DiffType.ADD,
40-
'blob-num-context': line.type === DiffType.EQUAL,
41-
'blob-num-hunk': splitLine.hide !== undefined,
42-
43-
}">
50+
<td
51+
class="blob-num"
52+
:class="{
53+
'blob-num-deletion': line.type === DiffType.DELETE,
54+
'blob-num-addition': line.type === DiffType.ADD,
55+
'blob-num-context': line.type === DiffType.EQUAL,
56+
'blob-num-hunk': splitLine.hide !== undefined,
57+
}"
58+
>
4459
{{ line.num }}
4560
</td>
46-
<td class="blob-code" :class="{
47-
'blob-code-deletion': line.type === DiffType.DELETE,
48-
'blob-code-addition': line.type === DiffType.ADD,
49-
'blob-code-context': line.type === DiffType.EQUAL,
50-
'blob-code-hunk': splitLine.hide !== undefined,
51-
52-
}">
53-
<span class="blob-code-inner blob-code-marker" :data-code-marker="getCodeMarker(line.type)"
54-
v-html="line.code" />
61+
<td
62+
class="blob-code"
63+
:class="{
64+
'blob-code-deletion': line.type === DiffType.DELETE,
65+
'blob-code-addition': line.type === DiffType.ADD,
66+
'blob-code-context': line.type === DiffType.EQUAL,
67+
'blob-code-hunk': splitLine.hide !== undefined,
68+
'split-side-left': index === 0,
69+
'split-side-right': index === 1,
70+
}"
71+
@mousedown="onSplitLineMousedown(index === 0 ? 'left' : 'right')"
72+
>
73+
<span
74+
class="blob-code-inner blob-code-marker" :data-code-marker="getCodeMarker(line.type)"
75+
v-html="line.code"
76+
/>
5577
</td>
5678
</template>
5779
<!-- eslint-enable -->

src/style.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@
140140
.blob-code + .blob-num {
141141
border-left: 1px solid var(--color-border-muted);
142142
}
143+
144+
.no-select {
145+
user-select: none;
146+
}
143147
}
144148

145149
.empty-cell {
@@ -148,4 +152,3 @@
148152
border-right-color: var(--color-border-muted);
149153
}
150154
}
151-

0 commit comments

Comments
 (0)