Skip to content

Commit

Permalink
Fix one char tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Jan 28, 2023
1 parent 9ec6aa1 commit d9abe7b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 95 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-rings-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@code-hike/lighter": patch
---

Fix one char tokens
8 changes: 7 additions & 1 deletion lib/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lib/dist/index.esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2649,7 +2649,10 @@ function reannotateLine(annotatedLine, annotation) {
}
i++;
}
while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) {
else {
newAnnotatedLine.push(newGroup);
}
while (i < annotatedLine.length && annotatedLine[i].toColumn <= toColumn) {
newGroup.tokens.push(annotatedLine[i]);
i++;
}
Expand Down Expand Up @@ -2763,6 +2766,9 @@ function reannotateLines(annotatedLines, annotation) {
}
i++;
}
else {
newAnnotatedLines.push(newGroup);
}
while (i < annotatedLines.length &&
annotatedLines[i].toLineNumber <= toLineNumber) {
newGroup.lines.push(annotatedLines[i]);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/annotations.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ function reannotateLine(
newGroup.tokens.push(secondHalf);
}
i++;
} else {
newAnnotatedLine.push(newGroup);
}

while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) {
while (i < annotatedLine.length && annotatedLine[i].toColumn <= toColumn) {
newGroup.tokens.push(annotatedLine[i]);
i++;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/annotations.multiline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ function reannotateLines(
newGroup.lines.push(secondHalf);
}
i++;
} else {
newAnnotatedLines.push(newGroup);
}

while (
Expand Down
94 changes: 2 additions & 92 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { annotatedHighlight, extractAnnotations } from "@code-hike/lighter";
// console.log("default", JSON.stringify(tokens));
// });

const test1 = `
const x = 1; /* bar x */ more /* notannotated */ code`;

const code = `
// mark[4:7]
consolessssssssss
// foo[9:11]
const x = 20
`.trim();
// const code = `// foo `;
const alias = "js";
Expand All @@ -28,90 +25,3 @@ async function run() {
}

run();

const x = [
{
lineNumber: 1,
tokens: [
{
content: "console.",
style: {
color: "#F8F8F2",
},
},
{
content: "log",
style: {
color: "#50FA7B",
},
},
{
content: "(",
style: {
color: "#F8F8F2",
},
},
{
content: "1",
style: {
color: "#BD93F9",
},
},
{
content: ")",
style: {
color: "#F8F8F2",
},
},
],
},
{
lineNumber: 2,
tokens: [
{
annotationName: "mark",
annotationQuery: "",
fromColumn: 4,
toColumn: 7,
tokens: [
{
content: "console.",
style: {
color: "#F8F8F2",
},
},
{
content: "console.",
style: {
color: "#F8F8F2",
},
},
{
content: "log",
style: {
color: "#50FA7B",
},
},
{
content: "(",
style: {
color: "#F8F8F2",
},
},
{
content: "2",
style: {
color: "#BD93F9",
},
},
{
content: ")",
style: {
color: "#F8F8F2",
},
},
],
},
],
},
];

1 comment on commit d9abe7b

@vercel
Copy link

@vercel vercel bot commented on d9abe7b Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lighter – ./

lighter-codehike.vercel.app
lighter.codehike.org
lighter-git-main-codehike.vercel.app

Please sign in to comment.