Skip to content

Commit ce2ef45

Browse files
author
Marcell Toth
authored
feat(code-viewer): animated transition from plain to highlighted (#193)
* feat(code-viewer): animate syntax highlighting When first rendering the CodeViewer it does not perform syntax highlighting. To optimize performance highlighting happens after rendering in a `useEffect` hook. This causes a flicker when the coloring is finally applied to the text. This fix smoothens out the process using a short (0.3s) animation to introduce the color. * fix: remove invalid cast * fix: only animate CodeViewer CodeEditor is probably missing some keys, which makes every token remounted on change (which happens quite often) in an editor
1 parent ea21887 commit ce2ef45

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/CodeViewer/components/BlockCodeViewer/SingleCodeBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const SingleCodeBlock: React.FC<IBlockProps> = ({
8484
}, [isVisible, lineNumber, value, language, showLineNumbers]);
8585

8686
if (markup !== void 0) {
87-
return markup as any;
87+
return <>{markup}</>;
8888
}
8989

9090
return <div ref={nodeRef}>{value}</div>;

src/styles/components/Code/_base.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
$line-number-char-width: 10px;
66
$line-padding-left: 10px;
77

8+
@keyframes set-color {
9+
0% {
10+
color: inherit;
11+
}
12+
}
13+
14+
815
.CodeEditor,
916
.CodeViewer {
1017
@include lightCodeTheme;
@@ -216,6 +223,10 @@ $line-padding-left: 10px;
216223
}
217224

218225
.CodeViewer {
226+
.token {
227+
animation: set-color 0.3s ease-out;
228+
}
229+
219230
&--line-numbers {
220231
@for $i from 1 through 6 {
221232
&--#{$i} {

0 commit comments

Comments
 (0)