From 42e633f424ebad22d9fd3645590846dba78a8165 Mon Sep 17 00:00:00 2001 From: "yuxin.zxy" Date: Mon, 9 Dec 2024 14:31:55 +0800 Subject: [PATCH] fix: empty file highlighting error (#225) --- src/Hunk/CodeCell.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Hunk/CodeCell.tsx b/src/Hunk/CodeCell.tsx index 117b2e5..a6b6361 100644 --- a/src/Hunk/CodeCell.tsx +++ b/src/Hunk/CodeCell.tsx @@ -27,12 +27,20 @@ const defaultRenderToken: DefaultRenderToken = ({type, value, markType, properti }; function isEmptyToken(tokens: TokenNode[]) { + if (!Array.isArray(tokens)) { + return true; + } + if (tokens.length > 1) { return false; } - const [token] = tokens; - return token.type === 'text' && !token.value; + if (tokens.length === 1) { + const [token] = tokens; + return token.type === 'text' && !token.value; + } + + return true; } export interface CodeCellProps extends HTMLAttributes {