Roo-Code: Indentation lost when using `apply_diff` with multiple search/replace blocks

Which version of the app are you using?

3.8.4

Which API Provider are you using?

Anthropic

Which Model are you using?

3.5

What happened?

starting with code of:

		const BUTTON_HEIGHT=100
		const scrollRect = scrollContainer.getBoundingClientRect()
		const isPartiallyVisible = rectCodeBlock.top < (scrollRect.bottom - BUTTON_HEIGHT) && rectCodeBlock.bottom >= (scrollRect.top + BUTTON_HEIGHT)

		// Calculate margin from existing padding in the component
		const computedStyle = window.getComputedStyle(codeBlock)
		const paddingValue = parseInt(computedStyle.getPropertyValue("padding") || "0", 10)
		const margin =
			paddingValue > 0 ? paddingValue : parseInt(computedStyle.getPropertyValue("padding-top") || "0", 10)

		// Get wrapper height dynamically
		let wrapperHeight
		if (copyWrapper) {
			const copyRect = copyWrapper.getBoundingClientRect()
			// If height is 0 due to styling, estimate from children
			if (copyRect.height > 0) {
				wrapperHeight = copyRect.height
			} else if (copyWrapper.children.length > 0) {
				// Try to get height from the button inside
				const buttonRect = copyWrapper.children[0].getBoundingClientRect()
				const buttonStyle = window.getComputedStyle(copyWrapper.children[0] as Element)
				const buttonPadding =
					parseInt(buttonStyle.getPropertyValue("padding-top") || "0", 10) +
					parseInt(buttonStyle.getPropertyValue("padding-bottom") || "0", 10)
				wrapperHeight = buttonRect.height + buttonPadding
			}
		}

		// If we still don't have a height, calculate from font size
		if (!wrapperHeight) {
			const fontSize = parseInt(window.getComputedStyle(document.body).getPropertyValue("font-size"), 10)
			wrapperHeight = fontSize * 2.5 // Approximate button height based on font size
		}

The 2x replacement

<<<<<<< SEARCH
:start_line:219
:end_line:223
-------
		const BUTTON_HEIGHT=100
		const scrollRect = scrollContainer.getBoundingClientRect()
		const isPartiallyVisible = rectCodeBlock.top < (scrollRect.bottom - BUTTON_HEIGHT) && rectCodeBlock.bottom >= (scrollRect.top + BUTTON_HEIGHT)

=======
		const scrollRect = scrollContainer.getBoundingClientRect()
		
		// Get wrapper height dynamically
		let wrapperHeight
		if (copyWrapper) {
			const copyRect = copyWrapper.getBoundingClientRect()
			// If height is 0 due to styling, estimate from children
			if (copyRect.height > 0) {
				wrapperHeight = copyRect.height
			} else if (copyWrapper.children.length > 0) {
				// Try to get height from the button inside
				const buttonRect = copyWrapper.children[0].getBoundingClientRect()
				const buttonStyle = window.getComputedStyle(copyWrapper.children[0] as Element)
				const buttonPadding =
					parseInt(buttonStyle.getPropertyValue("padding-top") || "0", 10) +
					parseInt(buttonStyle.getPropertyValue("padding-bottom") || "0", 10)
				wrapperHeight = buttonRect.height + buttonPadding
			}
		}

		// If we still don't have a height, calculate from font size
		if (!wrapperHeight) {
			const fontSize = parseInt(window.getComputedStyle(document.body).getPropertyValue("font-size"), 10)
			wrapperHeight = fontSize * 2.5 // Approximate button height based on font size
		}

		const isPartiallyVisible = rectCodeBlock.top < (scrollRect.bottom - wrapperHeight) && rectCodeBlock.bottom >= (scrollRect.top + wrapperHeight)

>>>>>>> REPLACE

<<<<<<< SEARCH
:start_line:231
:end_line:253
-------
		// Get wrapper height dynamically
		let wrapperHeight
		if (copyWrapper) {
			const copyRect = copyWrapper.getBoundingClientRect()
			// If height is 0 due to styling, estimate from children
			if (copyRect.height > 0) {
				wrapperHeight = copyRect.height
			} else if (copyWrapper.children.length > 0) {
				// Try to get height from the button inside
				const buttonRect = copyWrapper.children[0].getBoundingClientRect()
				const buttonStyle = window.getComputedStyle(copyWrapper.children[0] as Element)
				const buttonPadding =
					parseInt(buttonStyle.getPropertyValue("padding-top") || "0", 10) +
					parseInt(buttonStyle.getPropertyValue("padding-bottom") || "0", 10)
				wrapperHeight = buttonRect.height + buttonPadding
			}
		}

		// If we still don't have a height, calculate from font size
		if (!wrapperHeight) {
			const fontSize = parseInt(window.getComputedStyle(document.body).getPropertyValue("font-size"), 10)
			wrapperHeight = fontSize * 2.5 // Approximate button height based on font size
		}

=======
>>>>>>> REPLACE

produced exactly, missing indentation:

const scrollRect = scrollContainer.getBoundingClientRect()

// Get wrapper height dynamically
let wrapperHeight
if (copyWrapper) {
	const copyRect = copyWrapper.getBoundingClientRect()
	// If height is 0 due to styling, estimate from children
	if (copyRect.height > 0) {
		wrapperHeight = copyRect.height
	} else if (copyWrapper.children.length > 0) {
		// Try to get height from the button inside
		const buttonRect = copyWrapper.children[0].getBoundingClientRect()
		const buttonStyle = window.getComputedStyle(copyWrapper.children[0] as Element)
		const buttonPadding =
			parseInt(buttonStyle.getPropertyValue("padding-top") || "0", 10) +
			parseInt(buttonStyle.getPropertyValue("padding-bottom") || "0", 10)
		wrapperHeight = buttonRect.height + buttonPadding
	}
}

// If we still don't have a height, calculate from font size
if (!wrapperHeight) {
	const fontSize = parseInt(window.getComputedStyle(document.body).getPropertyValue("font-size"), 10)
	wrapperHeight = fontSize * 2.5 // Approximate button height based on font size
}

const isPartiallyVisible = rectCodeBlock.top < (scrollRect.bottom - wrapperHeight) && rectCodeBlock.bottom >= (scrollRect.top + wrapperHeight)

Steps to reproduce

you could probably write a test using this to reproduce the problem

Relevant API REQUEST output

see above

Additional context

Note that the indentation in the resulting code is not completely lost - it appears that tab indentation within code blocks is preserved, but the leading indentation (the two tabs at the beginning of each line in the original code) is removed.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 22

Commits related to this issue

Most upvoted comments

I believe i have already fixed the issue with long outputs, view https://github.com/RooVetGit/Roo-Code/pull/3387