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(sheets-ui): set focus editing mode when dbclick & error resize when change sub sheet #3725

Merged
merged 3 commits into from
Oct 12, 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
11 changes: 11 additions & 0 deletions packages/sheets-data-validation-ui/src/views/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DataValidationModel, DataValidatorRegistryScope, DataValidatorRegistryS
import { Button, FormLayout, Select } from '@univerjs/design';
import { RangeSelector } from '@univerjs/docs-ui';
import { serializeRange } from '@univerjs/engine-formula';
import { SheetsSelectionsService } from '@univerjs/sheets';
import { RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand } from '@univerjs/sheets-data-validation';
import { ComponentManager, useEvent, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useState } from 'react';
Expand Down Expand Up @@ -56,6 +57,16 @@ export function DataValidationDetail() {
const validators = validatorService.getValidatorsByScope(DataValidatorRegistryScope.SHEET);
const [localRanges, setLocalRanges] = useState<IUnitRange[]>(() => localRule.ranges.map((i) => ({ unitId: '', sheetId: '', range: i })));
const debounceExecute = useMemo(() => debounceExecuteFactory(commandService), [commandService]);
const sheetSelectionService = useDependency(SheetsSelectionsService);

useEffect(() => {
return () => {
const currentSelection = sheetSelectionService.getCurrentSelections();
if (currentSelection) {
sheetSelectionService.setSelections([...currentSelection]);
}
};
}, [sheetSelectionService]);

useEffect(() => {
commandService.onCommandExecuted((commandInfo) => {
Expand Down
61 changes: 35 additions & 26 deletions packages/sheets-formula-ui/src/controllers/prompt.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,46 +252,55 @@ export class PromptController extends Disposable {

private _initialCursorSync() {
this.disposeWithMe(
this._docSelectionManagerService.textSelection$.subscribe((params) => {
if (params?.unitId == null) {
return;
}
this._docSelectionManagerService.textSelection$
.pipe(
distinctUntilChanged(
(prev, curr) =>
prev?.unitId === curr?.unitId &&
prev?.segmentId === curr?.segmentId &&
Boolean(prev?.textRanges.every((t, i) => t.startOffset === curr?.textRanges[i].startOffset && t.endOffset === curr?.textRanges[i].endOffset))
)
)
.subscribe((params) => {
if (params?.unitId == null) {
return;
}

const editor = this._editorService.getEditor(params.unitId);
if (!editor
const editor = this._editorService.getEditor(params.unitId);
if (!editor
|| editor.onlyInputContent()
|| (editor.isSheetEditor() && !this._isFormulaEditorActivated())
// Remove this latter.
|| editor.params.scrollBar
) {
return;
}
) {
return;
}

const onlyInputRange = editor.onlyInputRange();
const onlyInputRange = editor.onlyInputRange();

// @ts-ignore
if (params?.options?.fromSelection) {
return;
} else {
this._quitSelectingMode();
}
if (params?.options?.fromSelection) {
return;
} else {
this._quitSelectingMode();
}

this._contextSwitch();
this._checkShouldEnterSelectingMode(onlyInputRange);
this._contextSwitch();
this._checkShouldEnterSelectingMode(onlyInputRange);

if (this._formulaPromptService.isLockedSelectionChange()) {
return;
}
if (this._formulaPromptService.isLockedSelectionChange()) {
return;
}

this._highlightFormula();
this._highlightFormula();

if (onlyInputRange) {
return;
}
if (onlyInputRange) {
return;
}

// TODO@Dushusir: use real text info
this._changeFunctionPanelState();
})
this._changeFunctionPanelState();
})
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import {
ScrollBar,
} from '@univerjs/engine-render';

import { ClearSelectionFormatCommand, COMMAND_LISTENER_SKELETON_CHANGE, SetRangeValuesCommand, SetRangeValuesMutation, SetSelectionsOperation, SetWorksheetActivateCommand, SheetsSelectionsService } from '@univerjs/sheets';
import { ClearSelectionFormatCommand, COMMAND_LISTENER_SKELETON_CHANGE, SetRangeValuesCommand, SetRangeValuesMutation, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetsSelectionsService } from '@univerjs/sheets';
import { ILayoutService, KeyCode, SetEditorResizeOperation } from '@univerjs/ui';
import { distinctUntilChanged, filter } from 'rxjs';
import { getEditorObject } from '../../basics/editor/get-editor-object';
Expand Down Expand Up @@ -245,6 +245,8 @@ export class EditingRenderController extends Disposable implements IRenderModule

private _initSkeletonListener(d: DisposableCollection) {
const commandList = new Set(COMMAND_LISTENER_SKELETON_CHANGE);
commandList.delete(SetWorksheetActiveOperation.id);

d.add(this._commandService.onCommandExecuted((commandInfo) => {
if (!commandList.has(commandInfo.id)) {
return;
Expand All @@ -259,12 +261,12 @@ export class EditingRenderController extends Disposable implements IRenderModule
if (!state) return;
if (!this._editorBridgeService.isVisible().visible) return;
this._editorBridgeService.refreshEditCellPosition(true);
const latestEditCellState = this._editorBridgeService.getEditCellState();
if (!latestEditCellState) return;
const editCellState = this._editorBridgeService.getEditCellState();
if (!editCellState) return;

const skeleton = this._sheetSkeletonManagerService.getWorksheetSkeleton(latestEditCellState.sheetId)?.skeleton;
const skeleton = this._sheetSkeletonManagerService.getWorksheetSkeleton(editCellState.sheetId)?.skeleton;
if (!skeleton) return;
const { row, column, scaleX, scaleY, position, canvasOffset, documentLayoutObject } = latestEditCellState;
const { row, column, scaleX, scaleY, position, canvasOffset, documentLayoutObject } = editCellState;
const maxSize = this._getEditorMaxSize(position, canvasOffset);
if (!maxSize) return;
const { height: clientHeight, width: clientWidth, scaleAdjust } = maxSize;
Expand All @@ -278,11 +280,11 @@ export class EditingRenderController extends Disposable implements IRenderModule
if (currentHeight !== height || currentWidth !== width) {
this._editorBridgeService.refreshEditCellPosition(true);

const skeleton = this._getEditorSkeleton(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
if (!skeleton) {
const docSkeleton = this._getEditorSkeleton(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
if (!docSkeleton) {
return;
}
this._fitTextSize(position, canvasOffset, skeleton, documentLayoutObject, scaleX, scaleY, () => {
this._fitTextSize(position, canvasOffset, docSkeleton, documentLayoutObject, scaleX, scaleY, () => {
this._textSelectionManagerService.refreshSelection({
unitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
subUnitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
Expand Down Expand Up @@ -644,7 +646,7 @@ export class EditingRenderController extends Disposable implements IRenderModule

// Change `CursorChange` to changed status, when formula bar clicked.
this._cursorChange =
eventType === DeviceInputEventType.PointerDown
(eventType === DeviceInputEventType.PointerDown || eventType === DeviceInputEventType.Dblclick)
? CursorChange.CursorChange
: CursorChange.StartEditor;

Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-ui/src/services/editor-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
const ru = this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET);
if (!ru) return;

const skeleton = ru.with(SheetSkeletonManagerService).getCurrentSkeleton();
const skeleton = ru.with(SheetSkeletonManagerService).getWorksheetSkeleton(currentEditCell.sheetId)?.skeleton;
const selectionRenderService = ru.with(ISheetSelectionRenderService);
if (!skeleton) return;
if (!this._currentEditCellState) return;
Expand Down
Loading