소스 검색

refac/fix: code block input

Timothy Jaeryang Baek 2 달 전
부모
커밋
60fb643109
1개의 변경된 파일30개의 추가작업 그리고 20개의 파일을 삭제
  1. 30 20
      src/lib/components/common/RichTextInput.svelte

+ 30 - 20
src/lib/components/common/RichTextInput.svelte

@@ -929,12 +929,39 @@
 					},
 					keydown: (view, event) => {
 						if (messageInput) {
+							// Check if the current selection is inside a structured block (like codeBlock or list)
+							const { state } = view;
+							const { $head } = state.selection;
+
+							// Recursive function to check ancestors for specific node types
+							function isInside(nodeTypes: string[]): boolean {
+								let currentNode = $head;
+								while (currentNode) {
+									if (nodeTypes.includes(currentNode.parent.type.name)) {
+										return true;
+									}
+									if (!currentNode.depth) break; // Stop if we reach the top
+									currentNode = state.doc.resolve(currentNode.before()); // Move to the parent node
+								}
+								return false;
+							}
+
 							// Handle Tab Key
 							if (event.key === 'Tab') {
-								const handled = selectNextTemplate(view.state, view.dispatch);
-								if (handled) {
+								const isInCodeBlock = isInside(['codeBlock']);
+
+								if (isInCodeBlock) {
+									// Handle tab in code block - insert tab character or spaces
+									const tabChar = '\t'; // or '    ' for 4 spaces
+									editor.commands.insertContent(tabChar);
 									event.preventDefault();
-									return true;
+									return true; // Prevent further propagation
+								} else {
+									const handled = selectNextTemplate(view.state, view.dispatch);
+									if (handled) {
+										event.preventDefault();
+										return true;
+									}
 								}
 							}
 
@@ -946,23 +973,6 @@
 									event.preventDefault();
 									return true;
 								} else {
-									// Check if the current selection is inside a structured block (like codeBlock or list)
-									const { state } = view;
-									const { $head } = state.selection;
-
-									// Recursive function to check ancestors for specific node types
-									function isInside(nodeTypes: string[]): boolean {
-										let currentNode = $head;
-										while (currentNode) {
-											if (nodeTypes.includes(currentNode.parent.type.name)) {
-												return true;
-											}
-											if (!currentNode.depth) break; // Stop if we reach the top
-											currentNode = state.doc.resolve(currentNode.before()); // Move to the parent node
-										}
-										return false;
-									}
-
 									const isInCodeBlock = isInside(['codeBlock']);
 									const isInList = isInside(['listItem', 'bulletList', 'orderedList', 'taskList']);
 									const isInHeading = isInside(['heading']);