From 38de981c70f03d9a1cb0e5e2b434ba1b2c8751cb Mon Sep 17 00:00:00 2001
From: yanmao <55792257+yanmao-cc@users.noreply.github.com>
Date: Wed, 17 Nov 2021 15:46:17 +0800
Subject: [PATCH] feat(): disable shift-keydown
---
packages/engine/src/engine/index.ts | 2 +-
.../engine/src/typing/keydown/shift-enter.ts | 28 ++++++++++++-------
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/packages/engine/src/engine/index.ts b/packages/engine/src/engine/index.ts
index f5fb9f4f..4dc6f0bf 100644
--- a/packages/engine/src/engine/index.ts
+++ b/packages/engine/src/engine/index.ts
@@ -50,7 +50,7 @@ import Parser from '../parser';
import Language from '../language';
import Mark from '../mark';
import List from '../list';
-import { EditorInterface, TypingInterface } from '../types';
+import { TypingInterface } from '../types';
import Typing from '../typing';
import Container from './container';
import Inline from '../inline';
diff --git a/packages/engine/src/typing/keydown/shift-enter.ts b/packages/engine/src/typing/keydown/shift-enter.ts
index c052d933..41053738 100644
--- a/packages/engine/src/typing/keydown/shift-enter.ts
+++ b/packages/engine/src/typing/keydown/shift-enter.ts
@@ -34,18 +34,26 @@ class ShitEnter implements TypingHandleInterface {
event.preventDefault();
change.cacheRangeBeforeCommand();
const range = change.range.get();
- const br = $('
');
- inline.insert(br, range);
- if (block.isLastOffset(range, 'end')) {
- if (
- (!br.next() || br.next()?.name !== 'br') &&
- (!br.prev() || br.prev()?.name !== 'br')
- ) {
- const cloneBr = br.clone();
- br.after(cloneBr);
- range.select(cloneBr).collapse(false);
+ if (range.startNode.closest('li').length === 0) {
+ this.engine.typing
+ .getHandleListener('enter', 'keydown')
+ ?.trigger(event);
+ return;
+ } else {
+ const br = $('
');
+ inline.insert(br, range);
+ if (block.isLastOffset(range, 'end')) {
+ if (
+ (!br.next() || br.next()?.name !== 'br') &&
+ (!br.prev() || br.prev()?.name !== 'br')
+ ) {
+ const cloneBr = br.clone();
+ br.after(cloneBr);
+ range.select(cloneBr).collapse(false);
+ }
}
}
+
for (let i = 0; i < this.listeners.length; i++) {
const listener = this.listeners[i];
const result = listener(event);