File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { MarkEdit } from 'markedit-api' ;
22import { proofreadingExtension } from './src/extension' ;
3+ import { buildMenuItem } from './src/menu' ;
34
45MarkEdit . addExtension ( proofreadingExtension ( ) ) ;
6+ MarkEdit . addMainMenuItem ( buildMenuItem ( ) ) ;
Original file line number Diff line number Diff line change 1+ export const repoUrl = 'https://github.com/MarkEdit-app/MarkEdit-proofreading' ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ const lintScheduler = ViewPlugin.fromClass(class {
3939
4040 async runLint ( ) {
4141 const doc = this . view . state . doc ;
42- const text = doc . sliceString ( 0 ) ;
42+ const text = doc . toString ( ) ;
4343 const lints = await lint ( text ) ;
4444
4545 if ( this . view . state . doc !== doc ) {
Original file line number Diff line number Diff line change 1+ import { MarkEdit } from 'markedit-api' ;
2+ import type { MenuItem } from 'markedit-api' ;
3+ import { setDiagnosticsEffect , lintToDiagnostic } from './decoration' ;
4+ import { lint } from './lint' ;
5+ import { repoUrl } from './const' ;
6+
7+ export function buildMenuItem ( ) : MenuItem {
8+ return {
9+ title : 'Proofread' ,
10+ icon : 'text.badge.checkmark' ,
11+ children : [
12+ {
13+ title : 'Proofread Now' ,
14+ action : proofreadNow ,
15+ } ,
16+ {
17+ title : 'Ignore All' ,
18+ action : ignoreAll ,
19+ } ,
20+ { separator : true } ,
21+ {
22+ title : `Version ${ __PKG_VERSION__ } ` ,
23+ action : ( ) => open ( `${ repoUrl } /releases/tag/v${ __PKG_VERSION__ } ` ) ,
24+ } ,
25+ {
26+ title : 'Check Release (GitHub)' ,
27+ action : ( ) => open ( `${ repoUrl } /releases` ) ,
28+ } ,
29+ ] ,
30+ } ;
31+ }
32+
33+ async function proofreadNow ( ) {
34+ const view = MarkEdit . editorView ;
35+ const text = view . state . doc . toString ( ) ;
36+ const lints = await lint ( text ) ;
37+ view . dispatch ( { effects : setDiagnosticsEffect . of ( lints . map ( lintToDiagnostic ) ) } ) ;
38+ }
39+
40+ function ignoreAll ( ) {
41+ MarkEdit . editorView . dispatch ( { effects : setDiagnosticsEffect . of ( [ ] ) } ) ;
42+ }
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest' ;
2+ import { buildMenuItem } from '../src/menu' ;
3+
4+ describe ( 'buildMenuItem' , ( ) => {
5+ it ( 'returns the expected menu structure' , ( ) => {
6+ const item = buildMenuItem ( ) ;
7+
8+ expect ( item . title ) . toBe ( 'Proofread' ) ;
9+ expect ( item . icon ) . toBe ( 'text.badge.checkmark' ) ;
10+
11+ const children = item . children ! ;
12+ expect ( children ) . toHaveLength ( 5 ) ;
13+
14+ expect ( children [ 0 ] . title ) . toBe ( 'Proofread Now' ) ;
15+ expect ( typeof children [ 0 ] . action ) . toBe ( 'function' ) ;
16+
17+ expect ( children [ 1 ] . title ) . toBe ( 'Ignore All' ) ;
18+ expect ( typeof children [ 1 ] . action ) . toBe ( 'function' ) ;
19+
20+ expect ( children [ 2 ] . separator ) . toBe ( true ) ;
21+
22+ expect ( children [ 3 ] . title ) . toMatch ( / ^ V e r s i o n \S + / ) ;
23+ expect ( typeof children [ 3 ] . action ) . toBe ( 'function' ) ;
24+
25+ expect ( children [ 4 ] . title ) . toBe ( 'Check Release (GitHub)' ) ;
26+ expect ( typeof children [ 4 ] . action ) . toBe ( 'function' ) ;
27+ } ) ;
28+ } ) ;
Original file line number Diff line number Diff line change 99 "strictNullChecks" : true ,
1010 "importHelpers" : true ,
1111 "noEmit" : true ,
12- "skipLibCheck" : true
12+ "skipLibCheck" : true ,
13+ "allowSyntheticDefaultImports" : true ,
14+ "resolveJsonModule" : true
1315 }
1416}
Original file line number Diff line number Diff line change 1+ /**
2+ * Package version read from the `package.json` file.
3+ */
4+ declare const __PKG_VERSION__ : string ;
Original file line number Diff line number Diff line change 11import { defineConfig , mergeConfig } from 'vite' ;
22import { viteSingleFile } from 'vite-plugin-singlefile' ;
33import { defaultViteConfig } from 'markedit-vite' ;
4+ import mainPackage from './package.json' with { type : 'json' } ;
45
56export default defineConfig ( mergeConfig ( defaultViteConfig ( ) , {
7+ define : {
8+ __PKG_VERSION__ : JSON . stringify ( mainPackage . version ) ,
9+ } ,
610 plugins : [ viteSingleFile ( ) ] ,
711} ) ) ;
You can’t perform that action at this time.
0 commit comments