Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { MarkEdit } from 'markedit-api';
import { proofreadingExtension } from './src/extension';
import { buildMenuItem } from './src/menu';

MarkEdit.addExtension(proofreadingExtension());
MarkEdit.addMainMenuItem(buildMenuItem());
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const repoUrl = 'https://github.com/MarkEdit-app/MarkEdit-proofreading';
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const lintScheduler = ViewPlugin.fromClass(class {

async runLint() {
const doc = this.view.state.doc;
const text = doc.sliceString(0);
const text = doc.toString();
const lints = await lint(text);

if (this.view.state.doc !== doc) {
Expand Down
42 changes: 42 additions & 0 deletions src/menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { MarkEdit } from 'markedit-api';
import type { MenuItem } from 'markedit-api';
import { setDiagnosticsEffect, lintToDiagnostic } from './decoration';
import { lint } from './lint';
import { repoUrl } from './const';

export function buildMenuItem(): MenuItem {
return {
title: 'Proofread',
icon: 'text.badge.checkmark',
children: [
{
title: 'Proofread Now',
action: proofreadNow,
},
{
title: 'Ignore All',
action: ignoreAll,
},
{ separator: true },
{
title: `Version ${__PKG_VERSION__}`,
action: () => open(`${repoUrl}/releases/tag/v${__PKG_VERSION__}`),
},
Comment thread
cyanzhong marked this conversation as resolved.
{
title: 'Check Release (GitHub)',
action: () => open(`${repoUrl}/releases`),
},
],
};
}

async function proofreadNow() {
const view = MarkEdit.editorView;
const text = view.state.doc.toString();
const lints = await lint(text);
view.dispatch({ effects: setDiagnosticsEffect.of(lints.map(lintToDiagnostic)) });
}

function ignoreAll() {
MarkEdit.editorView.dispatch({ effects: setDiagnosticsEffect.of([]) });
}
28 changes: 28 additions & 0 deletions tests/menu.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, expect, it } from 'vitest';
import { buildMenuItem } from '../src/menu';

describe('buildMenuItem', () => {
it('returns the expected menu structure', () => {
const item = buildMenuItem();

expect(item.title).toBe('Proofread');
expect(item.icon).toBe('text.badge.checkmark');

const children = item.children!;
expect(children).toHaveLength(5);

expect(children[0].title).toBe('Proofread Now');
expect(typeof children[0].action).toBe('function');

expect(children[1].title).toBe('Ignore All');
expect(typeof children[1].action).toBe('function');

expect(children[2].separator).toBe(true);

expect(children[3].title).toMatch(/^Version \S+/);
expect(typeof children[3].action).toBe('function');

Comment thread
cyanzhong marked this conversation as resolved.
expect(children[4].title).toBe('Check Release (GitHub)');
expect(typeof children[4].action).toBe('function');
});
});
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"strictNullChecks": true,
"importHelpers": true,
"noEmit": true,
"skipLibCheck": true
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
}
}
4 changes: 4 additions & 0 deletions types/globals.d.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Move this to types instead of src.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to types/globals.d.ts in bb42c7c.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Package version read from the `package.json` file.
*/
declare const __PKG_VERSION__: string;
4 changes: 4 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { defineConfig, mergeConfig } from 'vite';
import { viteSingleFile } from 'vite-plugin-singlefile';
import { defaultViteConfig } from 'markedit-vite';
import mainPackage from './package.json' with { type: 'json' };

export default defineConfig(mergeConfig(defaultViteConfig(), {
define: {
__PKG_VERSION__: JSON.stringify(mainPackage.version),
},
plugins: [viteSingleFile()],
}));
Loading