-
Notifications
You must be signed in to change notification settings - Fork 1
Add extension menu items #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
dcd25cd
7e536b7
bb42c7c
a1867a3
992eccd
b3ec8ae
70b343d
b6ca28f
b9de631
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { addMenuItems } from './src/menu'; | ||
|
|
||
| MarkEdit.addExtension(proofreadingExtension()); | ||
| addMenuItems(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { MarkEdit } from 'markedit-api'; | ||
| import type { MenuItem } from 'markedit-api'; | ||
| import { setDiagnosticsEffect, lintToDiagnostic } from './decoration'; | ||
| import { lint } from './lint'; | ||
|
|
||
| const repoUrl = 'https://github.com/MarkEdit-app/MarkEdit-proofreading'; | ||
|
|
||
| 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__}`), | ||
| }, | ||
|
cyanzhong marked this conversation as resolved.
|
||
| { | ||
| title: 'Check Release (GitHub)', | ||
| action: () => open(`${repoUrl}/releases`), | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| export function addMenuItems() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot this is not needed, since
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
| MarkEdit.addMainMenuItem(buildMenuItem()); | ||
| } | ||
|
|
||
| async function proofreadNow() { | ||
| const view = MarkEdit.editorView; | ||
| const doc = view.state.doc; | ||
| const text = doc.sliceString(0); | ||
| const lints = await lint(text); | ||
|
|
||
| if (view.state.doc !== doc) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot What are you doing here? Is this really a needed pattern??
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the stale document check in 70b343d. The |
||
| return; | ||
| } | ||
|
|
||
| view.dispatch({ effects: setDiagnosticsEffect.of(lints.map(lintToDiagnostic)) }); | ||
| } | ||
|
|
||
| function ignoreAll() { | ||
| MarkEdit.editorView.dispatch({ effects: setDiagnosticsEffect.of([]) }); | ||
| } | ||
| 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'); | ||
|
|
||
|
cyanzhong marked this conversation as resolved.
|
||
| expect(children[4].title).toBe('Check Release (GitHub)'); | ||
| expect(typeof children[4].action).toBe('function'); | ||
| }); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot Move this to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare const __PKG_VERSION__: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot move to
const.ts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
repoUrltosrc/const.tsin 992eccd.