Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(editor): open big text files editable, drop the mode switch for text docs (#3096)

Abrahamb9f9353e2dd3
diff --git a/.changeset/text-doc-polish.md b/.changeset/text-doc-polish.md
new file mode 100644
index 000000000..3e0a0bd15
--- /dev/null
+++ b/.changeset/text-doc-polish.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Two rough edges on the new text-file editing: large-but-ordinary files like an 800 KB lockfile now open editable (only pathologically large files stay on the read-only viewer), and the visual/markdown mode switcher no longer shows for code and text files, which only have one editing surface.
diff --git a/packages/app/src/components/EditorToolbar.tsx b/packages/app/src/components/EditorToolbar.tsx
index a9e3e4643..aba0a0e94 100644
--- a/packages/app/src/components/EditorToolbar.tsx
+++ b/packages/app/src/components/EditorToolbar.tsx
@@ -1,4 +1,5 @@
import {
+ isEditableTextDocFile,
parseExternalSkillDocName,
parseManagedArtifactName,
type SkillScope,
@@ -127,11 +128,15 @@ export function EditorToolbar({
)}
</div>
<div className="pointer-events-auto flex justify-center">
- <EditorModeToggle
- isSourceMode={isSourceMode}
- onModeChange={onModeChange}
- sourceDisabled={sourceDisabled}
- />
+ {/* Editable text docs have exactly one surface (CodeMirror), so
+ the wysiwyg/source switch would be a no-op pair of buttons. */}
+ {activeDocName !== null && isEditableTextDocFile(activeDocName) ? null : (
+ <EditorModeToggle
+ isSourceMode={isSourceMode}
+ onModeChange={onModeChange}
+ sourceDisabled={sourceDisabled}
+ />
+ )}
</div>
{/*
Third column kept empty so the mode toggle stays centered in the
diff --git a/packages/app/src/components/file-tree-selection.test.ts b/packages/app/src/components/file-tree-selection.test.ts
index 5e9d1d102..7c8841130 100644
--- a/packages/app/src/components/file-tree-selection.test.ts
+++ b/packages/app/src/components/file-tree-selection.test.ts
@@ -287,7 +287,22 @@ describe('resolveFileTreeSelectionAction — editable text assets', () => {
).toEqual({ kind: 'document', path: 'src/util.ts' });
});
- test('an oversized text asset stays on the read-only asset viewer', () => {
+ test('an everyday-large lockfile still opens as an editable doc', () => {
+ expect(
+ resolveFileTreeSelectionAction('pnpm-lock.yaml', [
+ {
+ kind: 'asset',
+ path: 'pnpm-lock.yaml',
+ assetExt: '.yaml',
+ mediaKind: 'text',
+ size: 900 * 1024,
+ modified: '',
+ },
+ ]),
+ ).toEqual({ kind: 'document', path: 'pnpm-lock.yaml' });
+ });
+
+ test('a pathologically large text asset stays on the read-only asset viewer', () => {
expect(
resolveFileTreeSelectionAction('big/data.json', [
{
@@ -295,7 +310,7 @@ describe('resolveFileTreeSelectionAction — editable text assets', () => {
path: 'big/data.json',
assetExt: '.json',
mediaKind: 'text',
- size: 5 * 1024 * 1024,
+ size: 20 * 1024 * 1024,
modified: '',
},
]),
diff --git a/packages/app/src/components/file-tree-selection.ts b/packages/app/src/components/file-tree-selection.ts
index da54331bd..b0afc1d85 100644
--- a/packages/app/src/components/file-tree-selection.ts
+++ b/packages/app/src/components/file-tree-selection.ts
@@ -1,5 +1,9 @@
import type { InlineAssetMediaKind } from '@inkeep/open-knowledge-core';
-import { isDocumentOverOpenByteLimit, isEditableTextDocFile } from '@inkeep/open-knowledge-core';
+import {
+ isDocumentOverOpenByteLimit,
+ isEditableTextDocFile,
+ TEXT_DOC_OPEN_BYTE_LIMIT,
+} from '@inkeep/open-knowledge-core';
import { hashFromAssetPath } from '@/lib/doc-hash';
import {
fileEntryToTreePath,
@@ -105,7 +109,8 @@ export function resolveFileTreeSelectionAction(
// (extension retained), so route the selection as a document.
if (
entry.mediaKind === 'mermaid' ||
- (isEditableTextDocFile(entry.path) && !isDocumentOverOpenByteLimit(entry.size))
+ (isEditableTextDocFile(entry.path) &&
+ !isDocumentOverOpenByteLimit(entry.size, TEXT_DOC_OPEN_BYTE_LIMIT))
) {
// Oversized text files stay on the read-only asset viewer — the
// verbatim load path has no large-doc defer, so seeding a multi-MB
diff --git a/packages/core/src/constants/document-open.ts b/packages/core/src/constants/document-open.ts
index f6fdad6fd..7916bc7f4 100644
--- a/packages/core/src/constants/document-open.ts
+++ b/packages/core/src/constants/document-open.ts
@@ -6,3 +6,12 @@ export function isDocumentOverOpenByteLimit(
): boolean {
return typeof bytes === 'number' && Number.isFinite(bytes) && bytes > limit;
}
+
+/**
+ * Editable text docs (code/config/plain text on the verbatim Y.Text path)
+ * open in a single CodeMirror surface, which handles multi-megabyte files
+ * comfortably — the markdown dual-editor's 512 KiB defer would wrongly
+ * push everyday files like an 800 KB lockfile to the read-only viewer.
+ * The cap only guards pathological sizes.
+ */
+export const TEXT_DOC_OPEN_BYTE_LIMIT = 10 * 1024 * 1024;
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index b52881615..f237dcfae 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -290,6 +290,7 @@ export { LINEAGE_EPOCH_KEY } from './constants/doc-lifecycle.ts';
export {
DOCUMENT_OPEN_BYTE_LIMIT,
isDocumentOverOpenByteLimit,
+ TEXT_DOC_OPEN_BYTE_LIMIT,
} from './constants/document-open.ts';
export {
ALL_EDITOR_IDS,