Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Cache Markdown list continuations

Emre Sokullua224ab5a5e12
diff --git a/src/chrome/src/ui/markdown-render.js b/src/chrome/src/ui/markdown-render.js
index 87fe5835f..de36ae02a 100644
--- a/src/chrome/src/ui/markdown-render.js
+++ b/src/chrome/src/ui/markdown-render.js
@@ -307,11 +307,17 @@ function listContinuationContainer(source, position, prefix, indentation, noList
current.leadingQuoteIndent,
);
const cacheKey = `${current.quoteDepth}:${continuationIndent}:${current.leadingQuoteIndent}`;
- const cachedPosition = noListScanPositions.get(cacheKey);
+ const cached = noListScanPositions.get(cacheKey);
+ if (cached?.container) return cached.container;
+ const cachedPosition = cached?.noList;
const noList = () => {
- noListScanPositions.set(cacheKey, position);
+ noListScanPositions.set(cacheKey, { noList: position });
return null;
};
+ const foundList = container => {
+ noListScanPositions.set(cacheKey, { container });
+ return container;
+ };
let lineEnd = position;
if (source[lineEnd - 1] === '\n') lineEnd -= 1;
if (source[lineEnd - 1] === '\r') lineEnd -= 1;
@@ -351,7 +357,7 @@ function listContinuationContainer(source, position, prefix, indentation, noList
}
const listIndent = container.listIndentGroups.at(-1);
if (listIndent && continuationIndent >= listIndent && continuationIndent <= listIndent + 3) {
- return container;
+ return foundList(container);
}
return noList();
}
diff --git a/src/firefox/src/ui/markdown-render.js b/src/firefox/src/ui/markdown-render.js
index 87fe5835f..de36ae02a 100644
--- a/src/firefox/src/ui/markdown-render.js
+++ b/src/firefox/src/ui/markdown-render.js
@@ -307,11 +307,17 @@ function listContinuationContainer(source, position, prefix, indentation, noList
current.leadingQuoteIndent,
);
const cacheKey = `${current.quoteDepth}:${continuationIndent}:${current.leadingQuoteIndent}`;
- const cachedPosition = noListScanPositions.get(cacheKey);
+ const cached = noListScanPositions.get(cacheKey);
+ if (cached?.container) return cached.container;
+ const cachedPosition = cached?.noList;
const noList = () => {
- noListScanPositions.set(cacheKey, position);
+ noListScanPositions.set(cacheKey, { noList: position });
return null;
};
+ const foundList = container => {
+ noListScanPositions.set(cacheKey, { container });
+ return container;
+ };
let lineEnd = position;
if (source[lineEnd - 1] === '\n') lineEnd -= 1;
if (source[lineEnd - 1] === '\r') lineEnd -= 1;
@@ -351,7 +357,7 @@ function listContinuationContainer(source, position, prefix, indentation, noList
}
const listIndent = container.listIndentGroups.at(-1);
if (listIndent && continuationIndent >= listIndent && continuationIndent <= listIndent + 3) {
- return container;
+ return foundList(container);
}
return noList();
}