summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/utils/markdownUtilities.ts
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-04-26 19:31:41 -0700
committerN. Taylor Mullen <[email protected]>2025-04-26 19:32:56 -0700
commit688b2d0da7f59421312e132461b33c8c593698a0 (patch)
tree4be08e5c0dcb9b2e73c792a746db517056cdfd15 /packages/cli/src/ui/utils/markdownUtilities.ts
parent5be89befeff9c4d4f3ab9f508f030bc153fdd06b (diff)
Follow up fixes from flickering PR.
- The push for these changes didn't make it through.... Just doing a quick fix here which should have been in: https://github.com/google-gemini/gemini-code/pull/181
Diffstat (limited to 'packages/cli/src/ui/utils/markdownUtilities.ts')
-rw-r--r--packages/cli/src/ui/utils/markdownUtilities.ts51
1 files changed, 15 insertions, 36 deletions
diff --git a/packages/cli/src/ui/utils/markdownUtilities.ts b/packages/cli/src/ui/utils/markdownUtilities.ts
index d16b7a51..94492b8c 100644
--- a/packages/cli/src/ui/utils/markdownUtilities.ts
+++ b/packages/cli/src/ui/utils/markdownUtilities.ts
@@ -163,45 +163,24 @@ export const findSafeSplitPoint = (
}
// idealMaxLength is NOT inside a code block.
- // Search backwards from idealMaxLength for a double newline (\n\n) not in a code block.
- for (let i = Math.min(idealMaxLength, content.length) - 1; i > 0; i--) {
- if (content[i] === '\n' && content[i - 1] === '\n') {
- const potentialSplitPoint = i + 1;
- if (potentialSplitPoint <= idealMaxLength) {
- if (!isIndexInsideCodeBlock(content, potentialSplitPoint)) {
- return potentialSplitPoint;
- }
- }
+ // Search forwards from idealMaxLength for the next double newline (\n\n) not in a code block.
+ let searchStartIndex = idealMaxLength;
+ while (searchStartIndex < content.length) {
+ const dnlIndex = content.indexOf('\n\n', searchStartIndex);
+ if (dnlIndex === -1) {
+ // No more double newlines found after idealMaxLength
+ break;
}
- }
- // If no safe double newline, look for a single newline (\n)
- for (let i = Math.min(idealMaxLength, content.length) - 1; i >= 0; i--) {
- if (content[i] === '\n') {
- const potentialSplitPoint = i + 1;
- if (potentialSplitPoint <= idealMaxLength) {
- if (!isIndexInsideCodeBlock(content, potentialSplitPoint)) {
- return potentialSplitPoint;
- }
- }
+ const potentialSplitPoint = dnlIndex + 2;
+ if (!isIndexInsideCodeBlock(content, potentialSplitPoint)) {
+ return potentialSplitPoint;
}
- }
- // Fallback logic if no prior safe split was found
- if (!isIndexInsideCodeBlock(content, idealMaxLength)) {
- return idealMaxLength;
- } else {
- // This should ideally not be reached frequently if prior logic is sound.
- // enclosingBlockStartForIdealMax would have been set if idealMaxLength was in a block.
- // If somehow it's still in a block, attempt to use the start of that block.
- const lastResortBlockStart = findEnclosingCodeBlockStart(
- content,
- idealMaxLength,
- ); // Re-check
- if (lastResortBlockStart !== -1) {
- return lastResortBlockStart;
- }
- // Absolute fallback: if idealMaxLength is in a block and we can't find its start (very unlikely)
- return 0;
+ searchStartIndex = potentialSplitPoint; // Continue search after the found \n\n
}
+
+ // If no safe double newline found after idealMaxLength, return content.length
+ // to keep the entire content as one piece.
+ return content.length;
};