diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index 40ad701925f13fd50c968ae6b3d12893b221e09a..8a147827fd1ad5c9ced633ab9801d3bf8564cc89 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 84f3d020762dc909ebd02d9ef0226fcada4173bd..0d26560544d126e697737e2195ed52fedc47c9ab 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 0000000000000000000000000000000000000000..b2fd2aeb0525076f7c71a5c9e05c20b0997eee9e --- /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 1737e4ac5e6407dddce1c2eaa0be6147117d96e6..e5a5cef6defb1e3042f8d1482fde5b9a01e9d69a 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