Skip to content

Commit aeda672

Browse files
author
Jesse Haigh
committed
WIP PR feedback
1 parent 7e7991b commit aeda672

File tree

4 files changed

+10
-40
lines changed

4 files changed

+10
-40
lines changed

src/components/ContentNode/CodeListing.vue

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class="code-listing"
1414
:data-syntax="syntaxNameNormalized"
1515
:class="{ 'single-line': syntaxHighlightedLines.length === 1, 'is-wrapped': wrap > 0 }"
16-
:style="wrapStyle"
16+
:style="wrap > 0 ? { '--wrap-ch': wrap } : null"
1717
>
1818
<Filename
1919
v-if="fileName"
@@ -42,8 +42,8 @@
4242
><span
4343
:key="index"
4444
:class="['code-line-container',{ highlighted: isHighlighted(index),
45-
'user-highlighted': isUserHighlighted(index),
46-
'user-strikethrough': isUserStrikethrough(index),}]"
45+
highlighted: isUserHighlighted(index),
46+
strikethrough: isUserStrikethrough(index),}]"
4747
><span
4848
v-if="showLineNumbers"
4949
class="code-number"
@@ -113,10 +113,13 @@ export default {
113113
highlightedLines: {
114114
type: Array,
115115
default: () => [],
116+
validator: lines => lines.every(number => Number.isInteger(number) && number > 0),
116117
},
117118
strikethroughLines: {
118119
type: Array,
119120
default: () => [],
121+
validator: lines => lines.every(number => Number.isInteger(number) && number > 0),
122+
120123
},
121124
startLineNumber: {
122125
type: Number,
@@ -144,26 +147,6 @@ export default {
144147
copyableText() {
145148
return this.content.join('\n');
146149
},
147-
highlightSet() {
148-
const arr = this.highlightedLines || [];
149-
return new Set(arr.map(Number).filter(n => Number.isFinite(n) && n > 0));
150-
},
151-
strikethroughSet() {
152-
const arr = this.strikethroughLines || [];
153-
return new Set(arr.map(Number).filter(n => Number.isFinite(n) && n > 0));
154-
},
155-
wrapStyle() {
156-
const style = {};
157-
if (this.wrap > 0) {
158-
style.whiteSpace = 'pre-wrap';
159-
style.wordBreak = 'break-word';
160-
style.overflowWrap = 'anywhere';
161-
style['--wrap-ch'] = String(this.wrap);
162-
} else {
163-
style.whiteSpace = 'pre';
164-
}
165-
return style;
166-
},
167150
},
168151
watch: {
169152
content: {
@@ -176,10 +159,10 @@ export default {
176159
return this.highlightedLineNumbers.has(this.lineNumberFor(index));
177160
},
178161
isUserHighlighted(index) {
179-
return this.highlightSet.has(this.lineNumberFor(index));
162+
return this.highlightedLines.includes(this.lineNumberFor(index));
180163
},
181164
isUserStrikethrough(index) {
182-
return this.strikethroughSet.has(this.lineNumberFor(index));
165+
return this.strikethroughLines.includes(this.lineNumberFor(index));
183166
},
184167
// Returns the line number for the line at the given index in `content`.
185168
lineNumberFor(index) {
@@ -250,16 +233,7 @@ export default {
250233
}
251234
}
252235
253-
.user-highlighted {
254-
background: var(--user-line-highlight, var(--color-user-code-line-highlight));
255-
border-left: $highlighted-border-width solid var(--color-user-code-line-highlight-border);
256-
257-
.code-number {
258-
padding-left: $code-number-padding-left - $highlighted-border-width;
259-
}
260-
}
261-
262-
.user-strikethrough {
236+
.strikethrough {
263237
text-decoration-line: line-through;
264238
text-decoration-color: var(--color-figure-gray);
265239
opacity: 0.85;

src/styles/core/colors/_dark.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
--color-badge-default: var(--color-badge-dark-default);
3838
--color-button-background-active: #{dark-color(fill-blue)};
3939
--color-code-line-highlight: #{change-color(dark-color(figure-blue), $alpha: 0.08)};
40-
--color-user-code-line-highlight: #{change-color(dark-color(figure-orange), $alpha: 0.32)};
4140
--color-dropdown-background: var(--color-dropdown-dark-background);
4241
--color-dropdown-border: var(--color-dropdown-dark-border);
4342
--color-dropdown-option-text: var(--color-dropdown-dark-option-text);

src/styles/core/colors/_light.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@
7777
--color-code-collapsible-text: var(--color-figure-gray-secondary-alt);
7878
--color-code-line-highlight: #{change-color(light-color(figure-blue), $alpha: 0.08)};
7979
--color-code-line-highlight-border: var(--color-figure-blue);
80-
--color-user-code-line-highlight: #{change-color(light-color(figure-orange), $alpha: 0.32)};
81-
--color-user-code-line-highlight-border: var(--color-figure-orange);
8280
--color-code-plain: var(--color-figure-gray);
8381
--color-dropdown-background: #{transparentize(light-color(fill), 0.2)};
8482
--color-dropdown-border: #{light-color(fill-gray)};

tests/unit/components/ContentNode/CodeListing.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ describe('CodeListing', () => {
351351

352352
await wrapper.setProps({ wrap: 0 });
353353
style = wrapper.attributes('style') || '';
354-
expect(wrapper.classes()).not.toContain('is-wrapped');
355-
expect(style).not.toMatch(/--wrap-ch:\s*\d+/);
354+
expect(style).toMatch(/--wrap-ch:\s*0\b/);
356355
});
357356

358357
it('treats negative wrap as no-wrap', async () => {

0 commit comments

Comments
 (0)