Skip to content

Commit 3056404

Browse files
committed
Add delete highlight support
1 parent 7ebd6fa commit 3056404

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

src/components/ContentNode/CodeListing.vue

+28-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
<!-- Do not add newlines in <pre>, as they'll appear in the rendered HTML. -->
2626
<pre><CodeBlock><span
2727
v-for="(line, index) in syntaxHighlightedLines"
28-
:class="['code-line-container',{ highlighted: isHighlighted(index) }]"
28+
:class="['code-line-container',
29+
{ highlighted: !isLastCodeListing && isHighlighted(index),
30+
deleteHighlighted: isLastCodeListing && isDeleteHighlighted(index)
31+
}]"
2932
:key="index"
3033
><span
3134
v-show="showLineNumbers" class="code-number"
@@ -75,16 +78,27 @@ export default {
7578
type: Array,
7679
default: () => [],
7780
},
81+
deleteHighlights: {
82+
type: Array,
83+
default: () => [],
84+
},
7885
showLineNumbers: {
7986
type: Boolean,
8087
default: () => false,
8188
},
89+
isLastCodeListing: {
90+
type: Boolean,
91+
default: () => false,
92+
},
8293
},
8394
computed: {
8495
escapedContent: ({ content }) => content.map(escapeHtml),
8596
highlightedLineNumbers() {
8697
return new Set(this.highlights.map(({ line }) => line));
8798
},
99+
deleteHighlightedLineNumbers() {
100+
return new Set(this.deleteHighlights.map(({ line }) => line));
101+
},
88102
syntaxNameNormalized() {
89103
// `occ` is a legacy naming convention
90104
const fallbackMap = { occ: Language.objectiveC.key.url };
@@ -101,6 +115,9 @@ export default {
101115
isHighlighted(index) {
102116
return this.highlightedLineNumbers.has(this.lineNumberFor(index));
103117
},
118+
isDeleteHighlighted(index) {
119+
return this.deleteHighlightedLineNumbers.has(this.lineNumberFor(index));
120+
},
104121
// Returns the line number for the line at the given index in `content`.
105122
lineNumberFor(index) {
106123
return this.startLineNumber + index;
@@ -152,6 +169,16 @@ export default {
152169
}
153170
}
154171

172+
.deleteHighlighted {
173+
text-decoration-line: line-through;
174+
background: var(--line-delete-highlight, var(--color-code-line-delete-highlight));
175+
border-left: $highlighted-border-width solid var(--color-code-line-delete-highlight-border);
176+
177+
.code-number {
178+
padding-left: $code-number-padding-left - $highlighted-border-width;
179+
}
180+
}
181+
155182
pre {
156183
padding: $code-listing-with-numbers-padding;
157184
display: flex;

src/components/Tutorial/CodePreview.vue

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<div :class="['code-preview', { ide: isTargetIDE }]">
1313
<CodeTheme>
1414
<CodeListing v-if="code" v-bind="codeProps" showLineNumbers />
15+
<CodeListing v-if="lastCode" v-bind="lastCodeProps" showLineNumbers isLastCodeListing />
1516
</CodeTheme>
1617
<div
1718
class="runtime-preview"
@@ -89,6 +90,10 @@ export default {
8990
type: String,
9091
required: true,
9192
},
93+
lastCode: {
94+
type: String,
95+
required: false,
96+
},
9297
preview: {
9398
type: String,
9499
required: false,
@@ -157,6 +162,11 @@ export default {
157162
codeProps() {
158163
return this.references[this.code];
159164
},
165+
lastCodeProps() {
166+
const ref = this.references[this.lastCode];
167+
ref.deleteHighlights = this.codeProps.deleteHighlights;
168+
return ref;
169+
},
160170
runtimePreviewClasses() {
161171
return {
162172
collapsed: !this.shouldDisplayHideLabel,

src/components/Tutorial/CodeTheme.vue

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export default {
8484
'--text': codeColors.text,
8585
'--background': codeColors.background,
8686
'--line-highlight': codeColors.lineHighlight,
87+
'--line-delete-highlight': codeColors.lineDeleteHighlight,
8788
'--url': codeColors.commentURL,
8889
'--syntax-comment': codeColors.comment,
8990
'--syntax-quote': codeColors.comment,

src/components/Tutorial/SectionSteps.vue

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<CodePreview
4545
v-if="visibleAsset.code"
4646
:code="visibleAsset.code"
47+
:lastCode="visibleAsset.lastCode"
4748
:preview="visibleAsset.runtimePreview"
4849
:isRuntimePreviewVisible="isRuntimePreviewVisible"
4950
@runtime-preview-toggle="onRuntimePreviewToggle"
@@ -99,11 +100,13 @@ export default {
99100
runtimePreview,
100101
} = this.content[firstStepIndex] || {};
101102

103+
const lastCode = '';
102104
return {
103105
tutorialState: this.store.state,
104106
visibleAsset: {
105107
media,
106108
code,
109+
lastCode,
107110
runtimePreview,
108111
},
109112
activeStep: firstStepIndex,
@@ -190,9 +193,17 @@ export default {
190193
runtimePreview,
191194
} = this.content[key];
192195

196+
let lastCode;
197+
if (key > 0) {
198+
lastCode = this.content[key - 1].code;
199+
} else {
200+
lastCode = '';
201+
}
202+
193203
this.activeStep = key;
194204
this.visibleAsset = {
195205
code,
206+
lastCode,
196207
media,
197208
runtimePreview,
198209
};

src/styles/core/colors/_dark.scss

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
--color-badge-default: var(--color-badge-dark-default);
3737
--color-button-background-active: #{dark-color(fill-blue)};
3838
--color-code-line-highlight: #{change-color(dark-color(figure-blue), $alpha: 0.08)};
39+
--color-code-line-delete-highlight: #{change-color(dark-color(figure-red), $alpha: 0.08)};
3940
--color-dropdown-background: var(--color-dropdown-dark-background);
4041
--color-dropdown-border: var(--color-dropdown-dark-border);
4142
--color-dropdown-option-text: var(--color-dropdown-dark-option-text);

src/styles/core/colors/_light.scss

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
--color-code-collapsible-text: var(--color-figure-gray-secondary-alt);
7777
--color-code-line-highlight: #{change-color(light-color(figure-blue), $alpha: 0.08)};
7878
--color-code-line-highlight-border: var(--color-figure-blue);
79+
--color-code-line-delete-highlight: #{change-color(light-color(figure-red), $alpha: 0.08)};
80+
--color-code-line-delete-highlight-border: var(--color-figure-red);
7981
--color-code-plain: var(--color-figure-gray);
8082
--color-dropdown-background: #{transparentize(light-color(fill), 0.2)};
8183
--color-dropdown-border: #{light-color(fill-gray)};

0 commit comments

Comments
 (0)