If Gemini generates code with REGEX, every "\n" causes a new line in the text editor, which messes everything up

Is there some setting that can solve this maybe? It’s extremely annoying because the only way around it is to have Gemini always output full code that I can manually copy & paste…and at that point what are we doing here? Lol

I shouldn’t really be complaining because I’m really enjoying this tool and it’s enabling me to do things I’ve always wanted to do. So I don’t want to come off too salty, I’m grateful for all of this amazing stuff Google. But it just seems kind of funny that there’s no way for Gemini to avoid this simple problem in its own IDE!

I’m sure this is a simple fix though, so Google, let’s please fix this :slight_smile:

1 Like

Tagging @ali and @romannurik who may know more about this.

@SlugBen Can you help provide some examples, that would help us debug/provide workarounds.

1 Like

A couple examples:

This:

        if (xmlChanged) {
            console.log("\nXML was modified. Preparing output zip file...");

Would come out like this:

        if (xmlChanged) {
            console.log("
XML was modified. Preparing output zip file...");

This:

function* parseSrtContent(srtContent: string, filename: string): Generator<SrtEntry> {
    if (!srtContent) return;
    const content = srtContent.trim();
    const blocks = content.split(/\r?\n\s*\r?\n/);

    for (const block of blocks) {
        const lines = block.trim().split(/\r?\n/);
        if (!lines || lines.length < 2 || !lines[0].trim()) continue;

        let timeLineIndex = -1;
        for (let i = 0; i < lines.length; i++) {
            if (lines[i].includes('-->')) {
                timeLineIndex = i;
                break;
            }
        }

Would come out like this:

function* parseSrtContent(srtContent: string, filename: string): Generator<SrtEntry> {
    if (!srtContent) return;
    const content = srtContent.trim();
    const blocks = content.split(/\r?
\s*\r?
/);

    for (const block of blocks) {
        const lines = block.trim().split(/\r?
/);
        if (!lines || lines.length < 2 || !lines[0].trim()) continue;

        let timeLineIndex = -1;
        for (let i = 0; i < lines.length; i++) {
            if (lines[i].includes('-->')) {
                timeLineIndex = i;
                break;
            }
        }

This happens when Gemini tries to write the code to a file. It outputs the code correctly if you tell it to just give you the full code to copy & paste, but the problem is when it tries to pass it to the text editor the \n is interpreted as ENTER and there doesn’t seem to be a way for it to get around that.

1 Like