-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dcd25cd
Initial plan
Copilot 7e536b7
Add extension menu items: Proofread Now, Ignore All, Version, Check R…
Copilot bb42c7c
Move globals.d.ts from src to types directory
Copilot a1867a3
Wrap menu items under a parent "Proofread" menu with SF Symbol icon
Copilot 992eccd
Move repoUrl to const.ts; remove addMenuItems wrapper, call buildMenu…
Copilot b3ec8ae
nit-picking
cyanzhong 70b343d
Remove unnecessary stale document check from proofreadNow
Copilot b6ca28f
Revert accidental lock file changes
Copilot b9de631
Replace sliceString(0) with toString() in menu.ts and extension.ts
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const repoUrl = 'https://github.com/MarkEdit-app/MarkEdit-proofreading'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__}`), | ||
| }, | ||
| { | ||
| 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([]) }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()], | ||
| })); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.