Skip to content
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

Android,Desktop: Plugin API: Fix unable to require @codemirror/search #10205

Conversation

personalizedrefrigerator
Copy link
Collaborator

@personalizedrefrigerator personalizedrefrigerator commented Mar 25, 2024

Summary

Allows requiring the Joplin built-in version of @codemirror/search from the plugin API. This allows plugins to toggle CodeMirror search, get the current search query, and move between search matches.

Testing

  1. Apply the following diff:
diff --git a/packages/app-cli/tests/support/plugins/codemirror6/package-lock.json b/packages/app-cli/tests/support/plugins/codemirror6/package-lock.json
index caef3d189..a99ca752a 100644
--- a/packages/app-cli/tests/support/plugins/codemirror6/package-lock.json
+++ b/packages/app-cli/tests/support/plugins/codemirror6/package-lock.json
@@ -10,6 +10,7 @@
       "license": "MIT",
       "devDependencies": {
         "@codemirror/autocomplete": "6.12.0",
+        "@codemirror/search": "^6.5.6",
         "@codemirror/view": "6.22.2",
         "@joplin/lib": "~2.9",
         "@types/node": "^18.7.13",
@@ -959,6 +960,17 @@
         "w3c-keyname": "^2.2.4"
       }
     },
+    "node_modules/@codemirror/search": {
+      "version": "6.5.6",
+      "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.5.6.tgz",
+      "integrity": "sha512-rpMgcsh7o0GuCDUXKPvww+muLA1pDJaFrpq/CCHtpQJYz8xopu4D1hPcKRoDD0YlF8gZaqTNIRa4VRBWyhyy7Q==",
+      "dev": true,
+      "dependencies": {
+        "@codemirror/state": "^6.0.0",
+        "@codemirror/view": "^6.0.0",
+        "crelt": "^1.0.5"
+      }
+    },
     "node_modules/@codemirror/state": {
       "version": "6.4.1",
       "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.4.1.tgz",
@@ -3554,6 +3566,12 @@
         "layout-base": "^1.0.0"
       }
     },
+    "node_modules/crelt": {
+      "version": "1.0.6",
+      "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz",
+      "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
+      "dev": true
+    },
     "node_modules/cross-spawn": {
       "version": "7.0.3",
       "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
diff --git a/packages/app-cli/tests/support/plugins/codemirror6/package.json b/packages/app-cli/tests/support/plugins/codemirror6/package.json
index a918e5811..4abd3f99f 100644
--- a/packages/app-cli/tests/support/plugins/codemirror6/package.json
+++ b/packages/app-cli/tests/support/plugins/codemirror6/package.json
@@ -15,6 +15,10 @@
     "publish"
   ],
   "devDependencies": {
+    "@codemirror/autocomplete": "6.12.0",
+    "@codemirror/search": "^6.5.6",
+    "@codemirror/view": "6.22.2",
+    "@joplin/lib": "~2.9",
     "@types/node": "^18.7.13",
     "chalk": "^4.1.0",
     "copy-webpack-plugin": "^11.0.0",
@@ -24,9 +28,6 @@
     "ts-loader": "^9.3.1",
     "typescript": "^4.8.2",
     "webpack": "^5.74.0",
-    "webpack-cli": "^4.10.0",
-    "@joplin/lib": "~2.9",
-    "@codemirror/view": "6.22.2",
-    "@codemirror/autocomplete": "6.12.0"
+    "webpack-cli": "^4.10.0"
   }
 }
diff --git a/packages/app-cli/tests/support/plugins/codemirror6/src/contentScript.ts b/packages/app-cli/tests/support/plugins/codemirror6/src/contentScript.ts
index fe9e4a89a..2a6e261bb 100644
--- a/packages/app-cli/tests/support/plugins/codemirror6/src/contentScript.ts
+++ b/packages/app-cli/tests/support/plugins/codemirror6/src/contentScript.ts
@@ -4,7 +4,8 @@
 // This is necessary. Having multiple copies of the CodeMirror libraries loaded can cause
 // the editor to not work properly.
 //
-import { lineNumbers, highlightActiveLineGutter, EditorView } from '@codemirror/view';
+import { lineNumbers, highlightActiveLineGutter, EditorView, keymap } from '@codemirror/view';
+import { findNext } from '@codemirror/search';
 import { completeFromList } from '@codemirror/autocomplete';
 import { MarkdownEditorContentScriptModule, ContentScriptContext } from 'api/types';
 //
@@ -43,6 +44,10 @@ export default (_context: ContentScriptContext): MarkdownEditorContentScriptModu
 				// Joplin also exposes a Facet that allows enabling or disabling CodeMirror's
 				// built-in autocompletions. These apply, for example, to HTML tags.
 				codeMirrorWrapper.joplinExtensions.enableLanguageDataAutocomplete.of(true),
+
+				keymap.of([
+					{ key: 'a', run: findNext },
+				]),
 			]);
 
 			// We can also register editor commands. These commands can be later executed with:
diff --git a/packages/app-cli/tests/support/plugins/codemirror6/webpack.config.js b/packages/app-cli/tests/support/plugins/codemirror6/webpack.config.js
index 525fcf2d4..ab40972eb 100644
--- a/packages/app-cli/tests/support/plugins/codemirror6/webpack.config.js
+++ b/packages/app-cli/tests/support/plugins/codemirror6/webpack.config.js
@@ -221,6 +221,7 @@ const pluginConfig = { ...baseConfig, entry: './src/index.ts',
 const externalContentScriptLibraries = [
 	'@codemirror/view',
 	'@codemirror/state',
+	'@codemirror/search',
 	'@codemirror/language',
 	'@codemirror/autocomplete',
 	'@codemirror/commands',
  1. Add the codemirror6 demo plugin.
  2. Search for something not containing the letter a that has multiple matches with ctrl-f (cmd-f on Mac?)
  3. Click on the main editor and press a. Verify that this moves to the next match.

@laurent22 laurent22 merged commit c1ae449 into laurent22:dev Mar 26, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants