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

fix(docs): no need to scroll when enter zen mode #3222

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/engine-render/src/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ export class Viewport {

let viewportScrollX = scrollVpPos.viewportScrollX ?? this.viewportScrollX;
let viewportScrollY = scrollVpPos.viewportScrollY ?? this.viewportScrollY;

const rawScrollXY = this.transViewportScroll2ScrollValue(viewportScrollX, viewportScrollY);
// const afterLimit = this.limitedScroll(rawScrollXY.x, rawScrollXY.y);
// const scrollX = afterLimit.scrollX;
Expand Down
1 change: 1 addition & 0 deletions packages/sheets-zen-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@
* limitations under the License.
*/

import type { ICommand, Workbook } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DeviceInputEventType } from '@univerjs/engine-render';
import type { IAccessor, ICommand, ITextRange, Workbook } from '@univerjs/core';
import { CommandType, DOCS_ZEN_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocBackScrollRenderController } from '@univerjs/docs-ui';
import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
import { IEditorBridgeService } from '@univerjs/sheets-ui';
import { IZenZoneService, KeyCode } from '@univerjs/ui';

function scrollToTop(accessor: IAccessor) {
const renderManagerService = accessor.get(IRenderManagerService);
const backScrollController = renderManagerService.getRenderById(DOCS_ZEN_EDITOR_UNIT_ID_KEY)?.with(DocBackScrollRenderController);
const textRange = {
startOffset: 0,
endOffset: 0,
};
if (backScrollController) {
backScrollController.scrollToRange(DOCS_ZEN_EDITOR_UNIT_ID_KEY, textRange as ITextRange);
}
}

export const CancelZenEditCommand: ICommand = {
id: 'zen-editor.command.cancel-zen-edit',
type: CommandType.COMMAND,
Expand All @@ -40,6 +53,8 @@ export const CancelZenEditCommand: ICommand = {

zenZoneEditorService.close();

scrollToTop(accessor);

const currentSheetInstance = univerInstanceManager.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (currentSheetInstance) {
univerInstanceManager.focusUnit(currentSheetInstance.getUnitId());
Expand Down Expand Up @@ -73,6 +88,8 @@ export const ConfirmZenEditCommand: ICommand = {

zenZoneEditorService.close();

scrollToTop(accessor);

const currentSheetInstance = univerInstanceManager.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (currentSheetInstance) {
univerInstanceManager.focusUnit(currentSheetInstance.getUnitId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class ZenEditorController extends RxDisposable {
},
];

this._textSelectionManagerService.replaceTextRanges(textRanges);
this._textSelectionManagerService.replaceTextRanges(textRanges, false);
}

private _editorSyncHandler(param: IEditorBridgeServiceParam) {
Expand Down
Loading
Loading