Skip to content

Commit 8e003fb

Browse files
authored
Merge pull request #259 from beNative/tisi/add-visual/source-editor-toggle-for-new-html-documents
Ensure HTML language enables rich text editing
2 parents dcbc4fa + 0915252 commit 8e003fb

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

App.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,21 @@ export const MainApp: React.FC = () => {
21192119
const handleLanguageChange = useCallback((newLanguage: string) => {
21202120
if (activeNodeId && activeNode?.type === 'document') {
21212121
addLog('INFO', `User action: Change language for document "${activeNode?.title}" to "${newLanguage}".`);
2122-
updateItem(activeNodeId, { language_hint: newLanguage });
2122+
const normalizedLanguage = newLanguage.toLowerCase();
2123+
let nextDocType: DocType | undefined;
2124+
2125+
if (normalizedLanguage === 'html') {
2126+
nextDocType = 'rich_text';
2127+
} else if (activeNode.doc_type === 'rich_text') {
2128+
nextDocType = 'prompt';
2129+
}
2130+
2131+
const updates: Partial<Omit<DocumentOrFolder, 'id' | 'content'>> = { language_hint: newLanguage };
2132+
if (nextDocType) {
2133+
updates.doc_type = nextDocType;
2134+
}
2135+
2136+
updateItem(activeNodeId, updates);
21232137
}
21242138
}, [activeNodeId, activeNode, updateItem, addLog]);
21252139

hooks/useNodes.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect, useCallback } from 'react';
2-
import type { Node, ViewMode, ImportedNodeSummary, DraggedNodeTransfer, ClassificationSummary } from '../types';
2+
import type { Node, ViewMode, ImportedNodeSummary, DraggedNodeTransfer, ClassificationSummary, DocType } from '../types';
33
import { repository } from '../services/repository';
44
import { useLogger } from './useLogger';
55

@@ -32,7 +32,10 @@ export const useNodes = () => {
3232
return newNode;
3333
}, [addLog, refreshNodes]);
3434

35-
const updateNode = useCallback(async (nodeId: string, updates: Partial<Pick<Node, 'title' | 'parent_id'> & { language_hint?: string | null; default_view_mode?: ViewMode | null }>) => {
35+
const updateNode = useCallback(async (
36+
nodeId: string,
37+
updates: Partial<Pick<Node, 'title' | 'parent_id'> & { language_hint?: string | null; default_view_mode?: ViewMode | null; doc_type?: DocType | null }>,
38+
) => {
3639
await repository.updateNode(nodeId, updates);
3740
addLog('DEBUG', `Node updated with ID: ${nodeId}. Refreshing tree.`);
3841
await refreshNodes(true);

hooks/usePrompts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const useDocuments = () => {
117117
if (updates.parentId !== undefined) nodeUpdates.parent_id = updates.parentId;
118118
if (updates.language_hint !== undefined) nodeUpdates.language_hint = updates.language_hint;
119119
if (updates.default_view_mode !== undefined) nodeUpdates.default_view_mode = updates.default_view_mode;
120+
if (updates.doc_type !== undefined) nodeUpdates.doc_type = updates.doc_type as DocType;
120121

121122
if (Object.keys(nodeUpdates).length > 0) {
122123
await updateNode(id, nodeUpdates);

services/repository.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,10 @@ export const repository = {
965965

966966
return { node: newNode, summary: classification.summary };
967967
},
968-
async updateNode(nodeId: string, updates: Partial<Pick<Node, 'title' | 'parent_id'> & { language_hint?: string | null; default_view_mode?: ViewMode | null }>) {
968+
async updateNode(
969+
nodeId: string,
970+
updates: Partial<Pick<Node, 'title' | 'parent_id'> & { language_hint?: string | null; default_view_mode?: ViewMode | null; doc_type?: DocType | null }>,
971+
) {
969972
if (!isElectron) {
970973
const state = ensureBrowserState();
971974
const result = findNodeWithParent(nodeId, state.nodes);
@@ -1001,6 +1004,11 @@ export const repository = {
10011004
if (updates.default_view_mode !== undefined) {
10021005
node.document.default_view_mode = updates.default_view_mode;
10031006
}
1007+
if (updates.doc_type !== undefined) {
1008+
node.document.doc_type = updates.doc_type ?? node.document.doc_type;
1009+
node.document.doc_type_source = 'user';
1010+
node.document.classification_updated_at = now;
1011+
}
10041012
}
10051013

10061014
node.updated_at = now;
@@ -1038,6 +1046,14 @@ export const repository = {
10381046
);
10391047
await window.electronAPI!.dbRun(`UPDATE nodes SET updated_at = ? WHERE node_id = ?`, [now, nodeId]);
10401048
}
1049+
1050+
if (updates.doc_type !== undefined) {
1051+
await window.electronAPI!.dbRun(
1052+
`UPDATE documents SET doc_type = ?, doc_type_source = 'user', classification_updated_at = ? WHERE node_id = ?`,
1053+
[updates.doc_type, now, nodeId]
1054+
);
1055+
await window.electronAPI!.dbRun(`UPDATE nodes SET updated_at = ? WHERE node_id = ?`, [now, nodeId]);
1056+
}
10411057
},
10421058

10431059
async updateDocumentContent(nodeId: string, newContent: string, documentId?: number) {

0 commit comments

Comments
 (0)