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

refactor(docs-ui): refactor to RenderUnit #2539

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: refactor back scroll render controller
  • Loading branch information
wzhudev committed Jun 17, 2024
commit 1b2a7fccba0f265a7ed2a98709171153dc193ba4
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
* limitations under the License.
*/

import { IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';
import { DocSkeletonManagerService, getDocObject, TextSelectionManagerService, VIEWPORT_KEY } from '@univerjs/docs';
import { getAnchorBounding, IRenderManagerService, NodePositionConvertToCursor } from '@univerjs/engine-render';
import type { DocumentDataModel } from '@univerjs/core';
import { RxDisposable } from '@univerjs/core';
import { DocSkeletonManagerService, neoGetDocObject, TextSelectionManagerService, VIEWPORT_KEY } from '@univerjs/docs';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { getAnchorBounding, NodePositionConvertToCursor } from '@univerjs/engine-render';
import { IEditorService } from '@univerjs/ui';
import { Inject } from '@wendellhu/redi';
import { takeUntil } from 'rxjs';

const ANCHOR_WIDTH = 1.5;

@OnLifecycle(LifecycleStages.Rendered, BackScrollController)
export class BackScrollController extends RxDisposable {
export class DocBackScrollRenderController extends RxDisposable implements IRenderModule {
constructor(
private readonly _context: IRenderContext<DocumentDataModel>,
@Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService,
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
@IEditorService private readonly _editorService: IEditorService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService
@IEditorService private readonly _editorService: IEditorService
) {
super();

Expand All @@ -54,7 +54,7 @@ export class BackScrollController extends RxDisposable {
// Let the selection show on the current screen.
private _scrollToSelection(unitId: string) {
const activeTextRange = this._textSelectionManagerService.getActiveRange();
const docObject = this._getDocObject();
const docObject = neoGetDocObject(this._context);
const skeleton = this._docSkeletonManagerService.getCurrent()?.skeleton;

if (activeTextRange == null || docObject == null || skeleton == null) {
Expand Down Expand Up @@ -115,8 +115,4 @@ export class BackScrollController extends RxDisposable {
const config = viewportMain.transViewportScroll2ScrollValue(offsetX, offsetY);
viewportMain.scrollBy(config);
}

private _getDocObject() {
return getDocObject(this._univerInstanceService, this._renderManagerService);
}
}
39 changes: 9 additions & 30 deletions packages/docs-ui/src/docs-ui-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ import { BreakLineShortcut, DeleteLeftShortcut, DeleteRightShortcut } from './sh
import { DocClipboardService, IDocClipboardService } from './services/clipboard/clipboard.service';
import { DocClipboardController } from './controllers/clipboard.controller';
import { DocEditorBridgeController } from './controllers/doc-editor-bridge.controller';
import { DocRenderController } from './views/doc-canvas-view';
import { DocRenderController } from './controllers/render-controllers/doc.render-controller';
import { DocFloatingObjectController } from './controllers/doc-floating-object.controller';
import { DocZoomRenderController } from './controllers/zoom.controller';
import { DocZoomRenderController } from './controllers/render-controllers/zoom.render-controller';
import { TextSelectionController } from './controllers/text-selection.controller';
import { BackScrollController } from './controllers/back-scroll.controller';
import { DocBackScrollRenderController } from './controllers/render-controllers/back-scroll.render-controller';
import { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
import { DocsRenderService } from './services/doc-render.service';

Expand Down Expand Up @@ -105,47 +105,25 @@ export class UniverDocsUIPlugin extends Plugin {

private _initDependencies(injector: Injector) {
const dependencies: Dependency[] = [
// Controller
[
DocUIController,
{
useFactory: () => this._injector.createInstance(DocUIController, this._config),
},
],
[DocUIController, { useFactory: () => this._injector.createInstance(DocUIController, this._config) }],
[DocClipboardController],

// Some of the controllers here should be moved to RenderUnit.
[DocEditorBridgeController],
[DocsRenderService],
[DocFloatingObjectController],
[TextSelectionController],
[BackScrollController],
[
// controllers
AppUIController,
{
useFactory: () => this._injector.createInstance(AppUIController, this._config),
},
],
[
IDocClipboardService,
{
useClass: DocClipboardService,
},
],
[AppUIController, { useFactory: () => this._injector.createInstance(AppUIController, this._config) }],
[IDocClipboardService, { useClass: DocClipboardService }],
[DocCanvasPopManagerService],
];

dependencies.forEach((d) => {
injector.add(d);
});
dependencies.forEach((d) => injector.add(d));
}

private _markDocAsFocused() {
const currentService = this._injector.get(IUniverInstanceService);
const editorService = this._injector.get(IEditorService);
try {
const doc = currentService.getCurrentUniverDocInstance();
const doc = currentService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
if (!doc) return;

const id = doc.getUnitId();
Expand All @@ -165,6 +143,7 @@ export class UniverDocsUIPlugin extends Plugin {
([
DocRenderController,
DocZoomRenderController,
DocBackScrollRenderController,
]).forEach((m) => {
this._renderManagerSrv.registerRenderController(UniverInstanceType.UNIVER_DOC, m);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

export * from './basics';
export * from './docs-ui-plugin';
export { DocRenderController } from './views/doc-canvas-view';
export { DocRenderController } from './controllers/render-controllers/doc.render-controller';
export * from './services';
export { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
export { docDrawingPositionToTransform, transformToDocDrawingPosition } from './basics/transform-position';