Browse Source

Claude: Improve robustness of chat scrolling

Alessandro Pignotti 6 months ago
parent
commit
109063e433
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/lib/AnthropicTab.svelte

+ 8 - 2
src/lib/AnthropicTab.svelte

@@ -1,5 +1,6 @@
 <script>
 <script>
 	import { apiState, setApiKey, addMessage, messageList, currentMessage } from '$lib/anthropic.js'
 	import { apiState, setApiKey, addMessage, messageList, currentMessage } from '$lib/anthropic.js'
+	import { tick } from 'svelte';
 	import PanelButton from './PanelButton.svelte';
 	import PanelButton from './PanelButton.svelte';
 	export let handleTool;
 	export let handleTool;
 	function handleKeyEnter(e)
 	function handleKeyEnter(e)
@@ -30,13 +31,18 @@
 		var textArea = e.target;
 		var textArea = e.target;
 		textArea.style.height = textArea.scrollHeight + "px";
 		textArea.style.height = textArea.scrollHeight + "px";
 	}
 	}
+	async function scrollToBottom(node)
+	{
+		await tick();
+		node.scrollTop = node.scrollHeight;
+	}
 	function scrollMessage(node, messageList)
 	function scrollMessage(node, messageList)
 	{
 	{
 		// Make sure the messages are always scrolled to the bottom
 		// Make sure the messages are always scrolled to the bottom
-		node.scrollTop = node.scrollHeight;
+		scrollToBottom(node);
 		return {
 		return {
 			update(messageList) {
 			update(messageList) {
-				node.scrollTop = node.scrollHeight;
+				scrollToBottom(node);
 			}
 			}
 		}
 		}
 	}
 	}