From 7175e5099f85a05fd3a06999935b5c1307fd195e Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Fri, 24 Feb 2023 11:39:59 +0200 Subject: [PATCH] fake cursor --- wax-prosemirror-core/src/WaxView.js | 6 +-- .../src/TablesService/TablesService.js | 7 +++ .../TablesService/plugins/FakeCursorPlugin.js | 45 +++++++++++++++++++ .../src/TablesService/table.css | 5 +++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 wax-prosemirror-services/src/TablesService/plugins/FakeCursorPlugin.js diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index 40ad70192..8a147827f 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -86,9 +86,9 @@ const WaxView = forwardRef((props, ref) => { }, handleDOMEvents: { blur: (editorView, event) => { - if (view && event.relatedTarget === null) { - view.focus(); - } + // if (view && event.relatedTarget === null) { + // view.focus(); + // } }, }, }, diff --git a/wax-prosemirror-services/src/TablesService/TablesService.js b/wax-prosemirror-services/src/TablesService/TablesService.js index 84f3d0207..0d2656054 100644 --- a/wax-prosemirror-services/src/TablesService/TablesService.js +++ b/wax-prosemirror-services/src/TablesService/TablesService.js @@ -1,8 +1,15 @@ import { Service } from 'wax-prosemirror-core'; import TablesServices from './index'; +import FakeCursorPlugin from './plugins/FakeCursorPlugin'; import './table.css'; class TablesService extends Service { + boot() { + this.app.PmPlugins.add( + 'fakeCursorPlugin', + FakeCursorPlugin('fakeCursorPlugin'), + ); + } dependencies = TablesServices; } diff --git a/wax-prosemirror-services/src/TablesService/plugins/FakeCursorPlugin.js b/wax-prosemirror-services/src/TablesService/plugins/FakeCursorPlugin.js new file mode 100644 index 000000000..b2fd2aeb0 --- /dev/null +++ b/wax-prosemirror-services/src/TablesService/plugins/FakeCursorPlugin.js @@ -0,0 +1,45 @@ +/* eslint-disable */ + +import { Plugin, PluginKey } from 'prosemirror-state'; +import { Decoration, DecorationSet } from 'prosemirror-view'; + +const fakeCursorPlugin = new PluginKey('fakeCursorPlugin'); +export default props => { + return new Plugin({ + key: fakeCursorPlugin, + state: { + init: (_, state) => {}, + apply(tr, prev, _, newState) { + let createDecoration; + const widget = document.createElement('fakecursor'); + + createDecoration = DecorationSet.create(newState.doc, [ + Decoration.widget(newState.selection.from, widget, { + key: 'fakecursor', + }), + ]); + return { + createDecoration, + }; + }, + }, + props: { + decorations: state => { + const fakeCursorPluginState = state && fakeCursorPlugin.getState(state); + if (fakeCursorPluginState) + return fakeCursorPluginState.createDecoration; + }, + handleDOMEvents: { + focus: (view, _event) => { + const fakeCursor = document.getElementsByTagName('fakecursor'); + if (fakeCursor && fakeCursor[0]) fakeCursor[0].style.display = 'none'; + }, + blur: (view, _event) => { + const fakeCursor = document.getElementsByTagName('fakecursor'); + if (fakeCursor && fakeCursor[0]) + fakeCursor[0].style.display = 'inline'; + }, + }, + }, + }); +}; diff --git a/wax-prosemirror-services/src/TablesService/table.css b/wax-prosemirror-services/src/TablesService/table.css index 1737e4ac5..e5a5cef6d 100644 --- a/wax-prosemirror-services/src/TablesService/table.css +++ b/wax-prosemirror-services/src/TablesService/table.css @@ -52,4 +52,9 @@ right: 0; top: 0; z-index: 2; + } + + fakecursor { + border-right: 1px solid black; + display: none; } \ No newline at end of file -- GitLab