Skip to content

Commit

Permalink
修复:paragraph 子区域之间无法接收输入
Browse files Browse the repository at this point in the history
  • Loading branch information
SuiltaPico committed Nov 17, 2024
1 parent 88016bc commit e1f6944
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/components/base/mix_editor/plugins/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,24 @@ export class TextInline
}
} else if (event.event_type === "input") {
const curr_value = this.data.value.get();
let to = event.to;
if (to === ToEnd) {
to = curr_value.length;
}
this.data.value.set(
curr_value.slice(0, event.to) + event.value + curr_value.slice(event.to)
curr_value.slice(0, to) + event.value + curr_value.slice(to)
);
return InputEventResult.done(event.to + event.value.length);
return InputEventResult.done(to + event.value.length);
} else if (event.event_type === "delete") {
const curr_value = this.data.value.get();
let to = event.to;
if (to === ToEnd) {
to = curr_value.length;
}
if (event.type === "backward") {
if (to <= 0) {
return DeleteEventResult.skip;
}
const new_value = curr_value.slice(0, to - 1) + curr_value.slice(to);

if (new_value.length === 0) {
Expand All @@ -83,6 +90,9 @@ export class TextInline
this.data.value.set(new_value);
return DeleteEventResult.done(to - 1);
} else if (event.type === "forward") {
if (to >= curr_value.length) {
return DeleteEventResult.skip;
}
const new_value = curr_value.slice(0, to) + curr_value.slice(to + 1);

if (new_value.length === 0) {
Expand Down
32 changes: 25 additions & 7 deletions src/components/base/mix_editor/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,37 @@ export class Selection {
const editor_mode = this.editor.mode.get();
if (!selected || editor_mode !== "edit") return;
if (selected?.type === "collapsed") {
const result = await selected.start.area.handle_event?.<InputEventPair>({
let current_area = selected.start.area;
let result = await current_area.handle_event?.<InputEventPair>({
event_type: "input",
value,
to: selected.start.child_path,
dataTransfer,
});

if (result?.type === "done") {
this.collapsed_select({
area: selected.start.area,
child_path: result.to,
});
return true;
console.log(`input_to_selection`, current_area, value, result);

while (true) {
if (result?.type === "done") {
this.collapsed_select({
area: current_area,
child_path: result.to,
});
return true;
} else if (result?.type === "enter_child") {
const child = selected.start.area.get_child(result.to);
if (!child) return;

current_area = child;
result = await current_area.handle_event?.<InputEventPair>({
event_type: "input",
value,
to: ToEnd,
dataTransfer,
});
} else {
break;
}
}
}
}
Expand Down

0 comments on commit e1f6944

Please sign in to comment.