A platform for community discussion. Free, open, simple.
FEATURE: prosemirror-codemark for a fake boundary cursor on rich editor (#32165)
Renato Atilioe84083ee3652
diff --git a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/code.js b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/code.jsnew file mode 100644index 00000000000..e0ac92e6fb8--- /dev/null+++ b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/code.js@@ -0,0 +1,10 @@+import codemark from "prosemirror-codemark";++/** @type {RichEditorExtension} */+const extension = {+ plugins({ schema }) {+ return codemark({ markType: schema.marks.code });+ },+};++export default extension;diff --git a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/register-default.js b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/register-default.jsindex ec2fe74bc28..a6b36b770d3 100644--- a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/register-default.js+++ b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/register-default.js@@ -1,5 +1,6 @@import { registerRichEditorExtension } from "discourse/lib/composer/rich-editor-extensions";import bulletList from "./bullet-list";+import code from "./code";import codeBlock from "./code-block";import emoji from "./emoji";import hashtag from "./hashtag";@@ -29,6 +30,7 @@ const defaultExtensions = [emoji,image,onebox,+ code,link,heading,codeBlock,diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.jsonindex 7489042e869..4e6cd7a61b1 100644--- a/app/assets/javascripts/discourse/package.json+++ b/app/assets/javascripts/discourse/package.json@@ -40,6 +40,7 @@"morphlex": "^0.0.16","orderedmap": "^2.1.1","pretty-text": "workspace:1.0.0",+ "prosemirror-codemark": "^0.4.2","prosemirror-commands": "^1.7.0","prosemirror-dropcursor": "^1.8.1","prosemirror-gapcursor": "^1.3.2",diff --git a/app/assets/javascripts/discourse/tests/helpers/rich-editor-helper.gjs b/app/assets/javascripts/discourse/tests/helpers/rich-editor-helper.gjsindex 6495ee1e8dd..2b27b5d7dde 100644--- a/app/assets/javascripts/discourse/tests/helpers/rich-editor-helper.gjs+++ b/app/assets/javascripts/discourse/tests/helpers/rich-editor-helper.gjs@@ -61,7 +61,12 @@ export async function setupRichEditor(assert, markdown, multiToggle = false) {// or artifacts.replace(' class=""', "")// or a trailing-paragraph with an optional <br class="ProseMirror-trailingBreak"> inside- .replace(/<p>(<br class="ProseMirror-trailingBreak">)?<\/p>$/, "");+ .replace(/<p>(<br class="ProseMirror-trailingBreak">)?<\/p>$/, "")+ // or the codemark fake cursor+ .replace(+ '<span class="fake-cursor ProseMirror-widget" contenteditable="false"></span>',+ ""+ );return [self, html];}diff --git a/app/assets/stylesheets/common/rich-editor/rich-editor.scss b/app/assets/stylesheets/common/rich-editor/rich-editor.scssindex 3ac6c5655e6..97b4dea4a7a 100644--- a/app/assets/stylesheets/common/rich-editor/rich-editor.scss+++ b/app/assets/stylesheets/common/rich-editor/rich-editor.scss@@ -276,3 +276,35 @@ li.ProseMirror-selectednode::after {.ProseMirror-focused .ProseMirror-gapcursor {display: block;}++/************************************************************+ Section below from prosemirror-codemark/src/codemark.css+ ***********************************************************/+@keyframes fake-cursor-blink {+ 49% {+ border-color: unset;+ }++ 50% {+ border-color: transparent;+ }++ 99% {+ border-color: transparent;+ }+}++.no-cursor {+ caret-color: transparent;+}++div:focus .fake-cursor,+span:focus .fake-cursor {+ margin-right: -1px;+ border-left-width: 1px;+ border-left-style: solid;+ animation: fake-cursor-blink 1s;+ animation-iteration-count: infinite;+ position: relative;+ z-index: 1;+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 5fd57ee35a3..39f7d16cedd 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -329,6 +329,9 @@ importers:pretty-text:specifier: workspace:1.0.0version: link:../pretty-text+ prosemirror-codemark:+ specifier: ^0.4.2prosemirror-commands:specifier: ^1.7.0version: 1.7.0@@ -7205,6 +7208,14 @@ packages:resolution: {integrity: sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==}+ resolution: {integrity: sha512-4n+PnGQToa/vTjn0OiivUvE8/moLtguUAfry8UA4Q8p47MhqT2Qpf2zBLustX5Upi4mSp3z1ZYBqLLovZC6abA==}+ peerDependencies:+ prosemirror-inputrules: ^1.2.0+ prosemirror-model: ^1.18.1+ prosemirror-state: ^1.4.1+ prosemirror-view: ^1.26.2+resolution: {integrity: sha512-6toodS4R/Aah5pdsrIwnTYPEjW70SlO5a66oo5Kk+CIrgJz3ukOoS+FYDGqvQlAX5PxoGWDX1oD++tn5X3pyRA==}@@ -16477,6 +16488,13 @@ snapshots:retry: 0.12.0signal-exit: 3.0.7+ dependencies:+ prosemirror-inputrules: 1.5.0+ prosemirror-model: 1.25.0+ prosemirror-state: 1.4.3+ prosemirror-view: 1.39.1+dependencies:prosemirror-model: 1.25.0diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rbindex 24b8155b936..44cd24767b4 100644--- a/spec/system/composer/prosemirror_editor_spec.rb+++ b/spec/system/composer/prosemirror_editor_spec.rb@@ -575,6 +575,50 @@ describe "Composer - ProseMirror editor", type: :system doendend+ describe "code marks with fake cursor" do+ it "allows typing after a code mark with/without the mark" do+ open_composer_and_toggle_rich_editor++ composer.type_content("This is ~~SPARTA!~~ `code!`.")++ expect(rich).to have_css("code", text: "code!")++ # within the code mark+ composer.send_keys(%i[backspace backspace])+ composer.type_content("!")++ expect(rich).to have_css("code", text: "code!")++ # after the code mark+ composer.send_keys(:right)+ composer.type_content(".")++ composer.toggle_rich_editor++ expect(composer).to have_value("This is ~~SPARTA!~~ `code!`.")+ end++ it "allows typing before a code mark with/without the mark" do+ open_composer_and_toggle_rich_editor++ composer.type_content("`code mark`")++ expect(rich).to have_css("code", text: "code mark")++ # before the code mark+ composer.send_keys(:home)+ composer.type_content("..")++ # within the code mark+ composer.send_keys(:right)+ composer.type_content("!!")++ composer.toggle_rich_editor++ expect(composer).to have_value("..`!!code mark`")+ end+ end+describe "emojis" doit "has the only-emoji class if 1-3 emojis are 'alone'" doopen_composer_and_toggle_rich_editor