-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增:MixEditor 的输入功能,部分删除功能;修复:双击聚焦节点后,输入法触发失效。
- Loading branch information
1 parent
7a93b30
commit eac61aa
Showing
17 changed files
with
473 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MaybePromise } from "@/common/async"; | ||
import { BaseEvent } from "../event"; | ||
import { Area } from "../Area"; | ||
|
||
export type CombineEventResult = | ||
| { | ||
type: "done"; | ||
/** 合并的结束位置。 */ | ||
to: number; | ||
} | ||
| { | ||
type: "skip"; | ||
}; | ||
|
||
export const CombineEventResult = { | ||
/** 不接受合并。 */ | ||
skip: { type: "skip" } satisfies CombineEventResult, | ||
/** 接受合并,并把光标移动到指定位置。 */ | ||
done: (to: number) => ({ type: "done", to } satisfies CombineEventResult), | ||
}; | ||
|
||
/** 合并事件。 */ | ||
export interface CombineEvent extends BaseEvent { | ||
event_type: "combine"; | ||
/** 要合并的区域。 */ | ||
area: Area; | ||
/** 合并的结束位置。 */ | ||
to: number; | ||
} | ||
|
||
export type CombineEventPair = { | ||
event: CombineEvent; | ||
result: MaybePromise<CombineEventResult>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { MaybePromise } from "@/common/async"; | ||
import { BaseEvent } from "../event"; | ||
import { Area } from "../Area"; | ||
|
||
export type DeleteEventResult = | ||
| { | ||
type: "done"; | ||
/** 输入的结束位置。 */ | ||
to: number; | ||
} | ||
| { | ||
type: "skip"; | ||
} | ||
| { | ||
type: "enter_child"; | ||
/** 进入的子区域索引。 */ | ||
to: number; | ||
} | ||
| { | ||
type: "self_delete_required"; | ||
}; | ||
|
||
export const DeleteEventResult = { | ||
/** 删除成功,结束删除流程。 */ | ||
done: (to: number) => ({ type: "done", to } satisfies DeleteEventResult), | ||
/** 跳过当前节点,让父节点处理。 */ | ||
skip: { type: "skip" } satisfies DeleteEventResult, | ||
/** 进入子区域,让子区域处理。 */ | ||
enter_child: (to: number) => | ||
({ | ||
type: "enter_child", | ||
to, | ||
} satisfies DeleteEventResult), | ||
/** 需要父节点删除自己。 */ | ||
self_delete_required: { | ||
type: "self_delete_required", | ||
} satisfies DeleteEventResult, | ||
}; | ||
|
||
/** 定向删除事件。通常由键盘的退格键和删除键触发。 */ | ||
export interface DirectionalDeleteEvent extends BaseEvent { | ||
event_type: "delete"; | ||
/** 删除的方向。 */ | ||
type: "forward" | "backward"; | ||
/** 删除的位置。 */ | ||
to: number; | ||
/** 是否从子区域跳入。 | ||
* | ||
* 如果是,父元素可能要处理好子元素的邻接问题,例如: | ||
* - 根节点需要让当前锻炼和上一个段落邻接。 */ | ||
from_child: boolean; | ||
} | ||
|
||
/** 指定删除事件。指定删除范围,约定为是左闭右开。 */ | ||
export interface SpecifiedDeleteEvent extends BaseEvent { | ||
event_type: "delete"; | ||
type: "specified"; | ||
from: number; | ||
to: number; | ||
} | ||
|
||
export type DeleteEvent = DirectionalDeleteEvent | SpecifiedDeleteEvent; | ||
|
||
export type DeleteEventPair = { | ||
event: DeleteEvent; | ||
result: MaybePromise<DeleteEventResult>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { MaybePromise } from "@/common/async"; | ||
import { BaseEvent } from "../event"; | ||
|
||
export type InputEventResult = | ||
| { | ||
type: "done"; | ||
/** 输入的结束位置。 */ | ||
to: number; | ||
} | ||
| { | ||
type: "skip"; | ||
}; | ||
|
||
export const InputEventResult = { | ||
/** 不接受输入,跳过当前节点。 */ | ||
skip: { type: "skip" } satisfies InputEventResult, | ||
/** 接受输入,并把光标移动到指定位置。 */ | ||
done: (to: number) => ({ type: "done", to } satisfies InputEventResult), | ||
}; | ||
|
||
/** 输入事件。 */ | ||
export interface InputEvent extends BaseEvent { | ||
event_type: "input"; | ||
/** 输入的值。 */ | ||
value: string; | ||
/** 输入的位置。 */ | ||
to: number; | ||
/** 输入的剪切板数据。 */ | ||
dataTransfer?: DataTransfer; | ||
} | ||
|
||
export type InputEventPair = { | ||
event: InputEvent; | ||
result: MaybePromise<InputEventResult>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { CaretMoveEnterEventPair } from "./CaretMoveEnter"; | ||
import { CombineEventPair } from "./Combine"; | ||
import { DeleteEventPair } from "./Delete"; | ||
import { InputEventPair } from "./Input"; | ||
|
||
export type BaseEvent = { | ||
event_type: string; | ||
}; | ||
|
||
export type EventPair = CaretMoveEnterEventPair; | ||
export type EventPair = | ||
| CaretMoveEnterEventPair | ||
| InputEventPair | ||
| DeleteEventPair | ||
| CombineEventPair; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.