Timothy J. Baek 6 tháng trước cách đây
mục cha
commit
953a8285f7

+ 1 - 1
src/lib/components/chat/MessageInput/Commands.svelte

@@ -25,7 +25,7 @@
 	};
 	};
 
 
 	let command = '';
 	let command = '';
-	$: command = prompt.split(' ')?.at(-1) ?? '';
+	$: command = prompt?.split('\n').pop()?.split(' ')?.pop() ?? '';
 </script>
 </script>
 
 
 {#if ['/', '#', '@'].includes(command?.charAt(0)) || '\\#' === command.slice(0, 2)}
 {#if ['/', '#', '@'].includes(command?.charAt(0)) || '\\#' === command.slice(0, 2)}

+ 17 - 11
src/lib/components/common/RichTextInput.svelte

@@ -17,7 +17,7 @@
 	import { splitListItem, liftListItem, sinkListItem } from 'prosemirror-schema-list'; // Import from prosemirror-schema-list
 	import { splitListItem, liftListItem, sinkListItem } from 'prosemirror-schema-list'; // Import from prosemirror-schema-list
 	import { keymap } from 'prosemirror-keymap';
 	import { keymap } from 'prosemirror-keymap';
 	import { baseKeymap, chainCommands } from 'prosemirror-commands';
 	import { baseKeymap, chainCommands } from 'prosemirror-commands';
-	import { DOMParser, DOMSerializer, Schema } from 'prosemirror-model';
+	import { DOMParser, DOMSerializer, Schema, Fragment } from 'prosemirror-model';
 
 
 	import { marked } from 'marked'; // Import marked for markdown parsing
 	import { marked } from 'marked'; // Import marked for markdown parsing
 	import { dev } from '$app/environment';
 	import { dev } from '$app/environment';
@@ -69,7 +69,10 @@
 
 
 	// Method to convert markdown content to ProseMirror-compatible document
 	// Method to convert markdown content to ProseMirror-compatible document
 	function markdownToProseMirrorDoc(markdown: string) {
 	function markdownToProseMirrorDoc(markdown: string) {
-		return defaultMarkdownParser.parse(value || '');
+		console.log('Markdown:', markdown);
+		// Parse the Markdown content into a ProseMirror document
+		let doc = defaultMarkdownParser.parse(markdown || '');
+		return doc;
 	}
 	}
 
 
 	// Utility function to convert ProseMirror content back to markdown text
 	// Utility function to convert ProseMirror content back to markdown text
@@ -399,6 +402,7 @@
 	// Reinitialize the editor if the value is externally changed (i.e. when `value` is updated)
 	// Reinitialize the editor if the value is externally changed (i.e. when `value` is updated)
 	$: if (view && value !== serializeEditorContent(view.state.doc)) {
 	$: if (view && value !== serializeEditorContent(view.state.doc)) {
 		const newDoc = markdownToProseMirrorDoc(value || '');
 		const newDoc = markdownToProseMirrorDoc(value || '');
+
 		const newState = EditorState.create({
 		const newState = EditorState.create({
 			doc: newDoc,
 			doc: newDoc,
 			schema,
 			schema,
@@ -407,15 +411,17 @@
 		});
 		});
 		view.updateState(newState);
 		view.updateState(newState);
 
 
-		// After updating the state, try to find and select the next template
-		setTimeout(() => {
-			const templateFound = selectNextTemplate(view.state, view.dispatch);
-			if (!templateFound) {
-				// If no template found, set cursor at the end
-				const endPos = view.state.doc.content.size;
-				view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, endPos)));
-			}
-		}, 0);
+		if (value !== '') {
+			// After updating the state, try to find and select the next template
+			setTimeout(() => {
+				const templateFound = selectNextTemplate(view.state, view.dispatch);
+				if (!templateFound) {
+					// If no template found, set cursor at the end
+					const endPos = view.state.doc.content.size;
+					view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, endPos)));
+				}
+			}, 0);
+		}
 	}
 	}
 
 
 	// Destroy ProseMirror instance on unmount
 	// Destroy ProseMirror instance on unmount

+ 1 - 1
src/lib/components/layout/Navbar.svelte

@@ -47,7 +47,7 @@
 		class=" bg-gradient-to-b via-50% from-white via-white to-transparent dark:from-gray-900 dark:via-gray-900 dark:to-transparent pointer-events-none absolute inset-0 -bottom-7 z-[-1] blur"
 		class=" bg-gradient-to-b via-50% from-white via-white to-transparent dark:from-gray-900 dark:via-gray-900 dark:to-transparent pointer-events-none absolute inset-0 -bottom-7 z-[-1] blur"
 	></div>
 	></div>
 
 
-	<div class=" flex max-w-full w-full mx-auto px-5 pt-0.5 md:px-[1rem] bg-transparen">
+	<div class=" flex max-w-full w-full mx-auto px-2 pt-0.5 md:px-[1rem] bg-transparent">
 		<div class="flex items-center w-full max-w-full">
 		<div class="flex items-center w-full max-w-full">
 			<div
 			<div
 				class="{$showSidebar
 				class="{$showSidebar

+ 23 - 8
src/lib/utils/index.ts

@@ -273,20 +273,35 @@ export const findWordIndices = (text) => {
 };
 };
 
 
 export const removeLastWordFromString = (inputString, wordString) => {
 export const removeLastWordFromString = (inputString, wordString) => {
-	// Split the string into an array of words
-	const words = inputString.split(' ');
+	console.log('inputString', inputString);
+	// Split the string by newline characters to handle lines separately
+	const lines = inputString.split('\n');
+
+	// Take the last line to operate only on it
+	const lastLine = lines.pop();
+
+	// Split the last line into an array of words
+	const words = lastLine.split(' ');
 
 
-	console.log(words.at(-1), wordString);
+	// Conditional to check for the last word removal
 	if (words.at(-1) === wordString || (wordString === '' && words.at(-1) === '\\#')) {
 	if (words.at(-1) === wordString || (wordString === '' && words.at(-1) === '\\#')) {
-		words.pop();
+		words.pop(); // Remove last word if condition is satisfied
 	}
 	}
 
 
-	// Join the remaining words back into a string
-	let resultString = words.join(' ');
-	if (resultString !== '') {
-		resultString += ' ';
+	// Join the remaining words back into a string and handle space correctly
+	let updatedLastLine = words.join(' ');
+
+	// Add a trailing space to the updated last line if there are still words
+	if (updatedLastLine !== '') {
+		updatedLastLine += ' ';
 	}
 	}
 
 
+	// Combine the lines together again, placing the updated last line back in
+	const resultString = [...lines, updatedLastLine].join('\n');
+
+	// Return the final string
+	console.log('resultString', resultString);
+
 	return resultString;
 	return resultString;
 };
 };