mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
feat(editor): replace slot with rxjs subject (#10768)
This commit is contained in:
@@ -118,7 +118,7 @@ export class EventService<TextAttributes extends BaseTextAttributes> {
|
||||
this.editor as InlineEditor
|
||||
);
|
||||
|
||||
this.editor.slots.inputting.emit();
|
||||
this.editor.slots.inputting.next();
|
||||
};
|
||||
|
||||
private readonly _onClick = (event: MouseEvent) => {
|
||||
@@ -180,7 +180,7 @@ export class EventService<TextAttributes extends BaseTextAttributes> {
|
||||
});
|
||||
}
|
||||
|
||||
this.editor.slots.inputting.emit();
|
||||
this.editor.slots.inputting.next();
|
||||
};
|
||||
|
||||
private readonly _onCompositionStart = () => {
|
||||
@@ -215,14 +215,14 @@ export class EventService<TextAttributes extends BaseTextAttributes> {
|
||||
)
|
||||
return;
|
||||
|
||||
this.editor.slots.inputting.emit();
|
||||
this.editor.slots.inputting.next();
|
||||
};
|
||||
|
||||
private readonly _onKeyDown = (event: KeyboardEvent) => {
|
||||
const inlineRange = this.editor.getInlineRange();
|
||||
if (!inlineRange) return;
|
||||
|
||||
this.editor.slots.keydown.emit(event);
|
||||
this.editor.slots.keydown.next(event);
|
||||
|
||||
if (
|
||||
!event.shiftKey &&
|
||||
|
||||
@@ -257,7 +257,8 @@ export class RangeService<TextAttributes extends BaseTextAttributes> {
|
||||
if (editor.inlineRangeProviderOverride) return;
|
||||
|
||||
if (this.editor.renderService.rendering) {
|
||||
editor.slots.renderComplete.once(() => {
|
||||
const subscription = editor.slots.renderComplete.subscribe(() => {
|
||||
subscription.unsubscribe();
|
||||
this.syncInlineRange(newInlineRange);
|
||||
});
|
||||
} else {
|
||||
@@ -308,11 +309,14 @@ export class RangeService<TextAttributes extends BaseTextAttributes> {
|
||||
selection.addRange(newRange);
|
||||
this.editor.rootElement.focus();
|
||||
|
||||
this.editor.slots.inlineRangeSync.emit(newRange);
|
||||
this.editor.slots.inlineRangeSync.next(newRange);
|
||||
} else {
|
||||
this.editor.slots.renderComplete.once(() => {
|
||||
this.syncInlineRange(inlineRange);
|
||||
});
|
||||
const subscription = this.editor.slots.renderComplete.subscribe(
|
||||
() => {
|
||||
subscription.unsubscribe();
|
||||
this.syncInlineRange(inlineRange);
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('failed to apply inline range');
|
||||
@@ -322,7 +326,10 @@ export class RangeService<TextAttributes extends BaseTextAttributes> {
|
||||
};
|
||||
|
||||
if (this.editor.renderService.rendering) {
|
||||
this.editor.slots.renderComplete.once(handler);
|
||||
const subscription = this.editor.slots.renderComplete.subscribe(() => {
|
||||
subscription.unsubscribe();
|
||||
handler();
|
||||
});
|
||||
} else {
|
||||
handler();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export class RenderService<TextAttributes extends BaseTextAttributes> {
|
||||
_: Y.YTextEvent,
|
||||
transaction: Y.Transaction
|
||||
) => {
|
||||
this.editor.slots.textChange.emit();
|
||||
this.editor.slots.textChange.next();
|
||||
|
||||
const yText = this.editor.yText;
|
||||
|
||||
@@ -153,7 +153,7 @@ export class RenderService<TextAttributes extends BaseTextAttributes> {
|
||||
.waitForUpdate()
|
||||
.then(() => {
|
||||
this._rendering = false;
|
||||
this.editor.slots.renderComplete.emit();
|
||||
this.editor.slots.renderComplete.next();
|
||||
this.editor.syncInlineRange();
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
Reference in New Issue
Block a user