D-50 behavior 4: opening a renderable .md in the editor now auto-reveals the context-panel reader, which mirrors the buffer read-only and re-renders as the user types — rather than a one-shot disk read. The extension reveals the tab on editor.opened (renderable only — D-50 behavior 5 leaves non-.md files alone). The viewer owns the mirror: on mount it picks up the active buffer (editor.read, no id), enters mirror mode on editor.opened / active-changed for a renderable file, re-reads the in-memory buffer on editor.edited, and drops the mirror (with its edit affordance back) on a disk load or a switch to a non-renderable buffer. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
54 lines
2.1 KiB
Dart
54 lines
2.1 KiB
Dart
/// T-36 / D-50 behavior 4+5: MarkdownExtension reveals the context-panel reader
|
|
/// when a renderable .md opens in the editor, and leaves a non-renderable file
|
|
/// alone. (The viewer then mirrors the buffer live — see markdown_viewer_test.)
|
|
library;
|
|
|
|
import 'package:clide/builtin/markdown/src/extension.dart';
|
|
import 'package:clide/kernel/kernel.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../../helpers/kernel_fixture.dart';
|
|
|
|
void main() {
|
|
late KernelFixture f;
|
|
|
|
setUp(() async {
|
|
f = await KernelFixture.create();
|
|
f.services.extensions.register(MarkdownExtension());
|
|
await f.services.extensions.activate('builtin.markdown');
|
|
});
|
|
tearDown(() => f.dispose());
|
|
|
|
void open(String path) {
|
|
f.services.events.emit(DaemonEvent(subsystem: 'editor', kind: 'editor.opened', data: {'id': 'b1', 'path': path}, ts: DateTime.now().toUtc()));
|
|
}
|
|
|
|
test('contributes the markdown.viewer context-panel tab', () {
|
|
expect(f.services.panels.tabsFor(Slots.contextPanel).any((t) => t.id == 'markdown.viewer'), isTrue);
|
|
});
|
|
|
|
test('opening a renderable .md reveals the markdown viewer', () async {
|
|
// markdown.viewer is the default contextPanel tab; flip to a sentinel first
|
|
// so the reveal is observable.
|
|
f.services.panels.activateTab(Slots.contextPanel, 'sentinel');
|
|
open('docs/notes.md');
|
|
await pumpEventQueue();
|
|
expect(f.services.panels.activeTabIn(Slots.contextPanel), 'markdown.viewer');
|
|
});
|
|
|
|
test('opening a non-renderable file does not reveal it (D-50 behavior 5)', () async {
|
|
f.services.panels.activateTab(Slots.contextPanel, 'sentinel');
|
|
open('lib/main.dart');
|
|
await pumpEventQueue();
|
|
expect(f.services.panels.activeTabIn(Slots.contextPanel), 'sentinel');
|
|
});
|
|
|
|
test('after deactivate, editor.opened no longer reveals the viewer', () async {
|
|
await f.services.extensions.deactivate('builtin.markdown');
|
|
f.services.panels.activateTab(Slots.contextPanel, 'sentinel');
|
|
open('notes.md');
|
|
await pumpEventQueue();
|
|
expect(f.services.panels.activeTabIn(Slots.contextPanel), 'sentinel');
|
|
});
|
|
}
|