Skip to content

Commit

Permalink
Revert "Handle section breaks when pasting text from other sources (#210
Browse files Browse the repository at this point in the history
)" (#213)

This reverts commit 499103e.
  • Loading branch information
auniverseaway authored Sep 12, 2024
1 parent ca2914b commit 7d75b16
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 206 deletions.
37 changes: 0 additions & 37 deletions blocks/edit/prose/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable max-classes-per-file */
import {
DOMParser,
EditorState,
EditorView,
Schema,
TextSelection,
baseSchema,
history,
buildKeymap,
Expand All @@ -19,8 +17,6 @@ import {
liftListItem,
sinkListItem,
gapCursor,
InputRule,
inputRules,
Y,
WebsocketProvider,
ySyncPlugin,
Expand All @@ -35,7 +31,6 @@ import prose2aem from '../../shared/prose2aem.js';
import menu from './plugins/menu.js';
import imageDrop from './plugins/imageDrop.js';
import linkConverter from './plugins/linkConverter.js';
import sectionPasteHandler from './plugins/sectionPasteHandler.js';
import { COLLAB_ORIGIN, getDaAdmin } from '../../shared/constants.js';
import { addLocNodes, getLocClass } from './loc-utils.js';

Expand Down Expand Up @@ -206,36 +201,6 @@ function generateColor(name, hRange = [0, 360], sRange = [60, 80], lRange = [40,
return `#${f(0)}${f(8)}${f(4)}`;
}

function getDashesInputRule() {
return new InputRule(
/^---[\n]$/,
(state, match, start, end) => {
const div = document.createElement('div');
div.append(document.createElement('hr'));
const newNodes = DOMParser.fromSchema(state.schema).parse(div);

const selection = TextSelection.create(state.doc, start, end);
dispatchTransaction(state.tr.setSelection(selection).replaceSelectionWith(newNodes));
},
);
}

// This function returns a modified inputrule plugin that triggers when the regex in the
// rule matches and the Enter key is pressed
function getInputRulesPlugin() {
const irsplugin = inputRules({ rules: [getDashesInputRule()] });

const hkd = (view, event) => {
if (event.key !== 'Enter') return false;
const { $cursor } = view.state.selection;
if ($cursor) return irsplugin.props.handleTextInput(view, $cursor.pos, $cursor.pos, '\n');
return false;
};
irsplugin.props.handleKeyDown = hkd; // Add the handleKeyDown function

return irsplugin;
}

export default function initProse({ editor, path }) {
// Destroy ProseMirror if it already exists - GH-212
if (window.view) delete window.view;
Expand Down Expand Up @@ -296,10 +261,8 @@ export default function initProse({ editor, path }) {
menu,
imageDrop(schema),
linkConverter(schema),
sectionPasteHandler(schema),
columnResizing(),
tableEditing(),
getInputRulesPlugin(),
keymap(buildKeymap(schema)),
keymap(baseKeymap),
keymap({
Expand Down
153 changes: 0 additions & 153 deletions blocks/edit/prose/plugins/sectionPasteHandler.js

This file was deleted.

Loading

0 comments on commit 7d75b16

Please sign in to comment.