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

FIx errors on enter press when several blocks selected #1349

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ export default class BlockSelection extends Module {
BlockManager.insertDefaultBlockAtIndex(indexToInsert, true);
Caret.setToBlock(BlockManager.currentBlock);
_.delay(() => {
Caret.insertContentAtCaretPosition((reason as KeyboardEvent).key);
const eventKey = (reason as KeyboardEvent).key;

Caret.insertContentAtCaretPosition(eventKey.length > 1 ? '' : eventKey);
}, 20)();
}

Expand Down
7 changes: 7 additions & 0 deletions src/components/modules/caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ export default class Caret extends Module {

Array.from(wrapper.childNodes).forEach((child: Node) => fragment.appendChild(child));

/**
* If there is no child node, append empty one
*/
if (fragment.childNodes.length === 0) {
fragment.appendChild(new Text(''));
}

const lastChild = fragment.lastChild;

range.deleteContents();
Expand Down
4 changes: 0 additions & 4 deletions src/components/modules/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,6 @@ export default class UI extends Module<UINodes> {
* remove selected blocks
*/
if (BlockSelection.anyBlockSelected && !Selection.isSelectionExists) {
const selectionPositionIndex = BlockManager.removeSelectedBlocks();

Caret.setToBlock(BlockManager.insertDefaultBlockAtIndex(selectionPositionIndex, true), Caret.positions.START);

/** Clear selection */
BlockSelection.clearSelection(event);

Expand Down