Skip to content

Commit

Permalink
fix: fx editor cursor (#915)
Browse files Browse the repository at this point in the history
* fix: fx editor cursor

* fix: bar size
  • Loading branch information
Jocs authored Jan 5, 2024
1 parent 368ed2c commit cb7c923
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class FormulaEditorController extends RxDisposable {
this._commandExecutedListener();
this._syncEditorSize();
this._listenFxBtnClick();
this._listenFoldBtnClick();

this._renderManagerService.currentRender$.pipe(takeUntil(this.dispose$)).subscribe((unitId) => {
if (unitId !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {
Expand Down Expand Up @@ -157,6 +158,12 @@ export class FormulaEditorController extends RxDisposable {
});
}

private _listenFoldBtnClick() {
this._formulaEditorManagerService.foldBtnStatus$.pipe(takeUntil(this.dispose$)).subscribe(() => {
this._textSelectionManagerService.refreshSelection();
});
}

private _initialMain(unitId: string) {
const formulaEditorDocObject = this._renderManagerService.getRenderById(unitId);
if (formulaEditorDocObject == null) {
Expand Down Expand Up @@ -395,9 +402,16 @@ export class FormulaEditorController extends RxDisposable {

let scrollBar = viewportMain?.getScrollBar() as Nullable<ScrollBar>;

scene.transformByState({
width,
height: actualHeight,
});

mainComponent?.resize(width, actualHeight);

if (actualHeight > height) {
if (scrollBar == null) {
viewportMain && new ScrollBar(viewportMain, { enableHorizontal: false });
viewportMain && new ScrollBar(viewportMain, { enableHorizontal: false, barSize: 8 });
} else {
viewportMain?.resetSizeAndScrollBar();
}
Expand All @@ -406,12 +420,5 @@ export class FormulaEditorController extends RxDisposable {
viewportMain?.scrollTo({ x: 0, y: 0 });
viewportMain?.getScrollBar()?.dispose();
}

scene.transformByState({
width,
height: actualHeight,
});

mainComponent?.resize(width, actualHeight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IFormulaEditorManagerService {
position$: Observable<Nullable<DOMRect>>;
focus$: Observable<boolean>;
fxBtnClick$: Observable<boolean>;
foldBtnStatus$: Observable<boolean>;
dispose(): void;
setPosition(param: DOMRect): void;
getPosition(): Readonly<Nullable<DOMRect>>;
Expand All @@ -44,6 +45,9 @@ export class FormulaEditorManagerService implements IDisposable {
private readonly _fxBtnClick$ = new BehaviorSubject<boolean>(false);
readonly fxBtnClick$ = this._fxBtnClick$.asObservable();

private readonly _foldBtnStatus$ = new BehaviorSubject<boolean>(false);
readonly foldBtnStatus$ = this._foldBtnStatus$.asObservable();

dispose(): void {
this._position$.complete();
this._focus$.complete();
Expand All @@ -70,6 +74,10 @@ export class FormulaEditorManagerService implements IDisposable {
this._fxBtnClick$.next(params);
}

handleFoldBtnClick(params: boolean) {
this._foldBtnStatus$.next(params);
}

private _refresh(param: DOMRect): void {
this._position$.next(param);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ enum ArrowDirection {
Up,
}

interface IFormulaState {
iconStyle: string;
arrowDirection: ArrowDirection;
}

export function FormulaBar() {
const [iconStyle, setIconStyle] = useState<string>(styles.formulaGrey);
const [arrowDirection, setArrowDirection] = useState<ArrowDirection>(ArrowDirection.Down);
Expand Down Expand Up @@ -85,6 +80,11 @@ export function FormulaBar() {

function handleArrowClick() {
setArrowDirection(arrowDirection === ArrowDirection.Down ? ArrowDirection.Up : ArrowDirection.Down);

const ANIMATION_DURATION = 150;
setTimeout(() => {
formulaEditorManagerService.handleFoldBtnClick(arrowDirection === ArrowDirection.Up);
}, ANIMATION_DURATION);
}

function handleCloseBtnClick() {
Expand Down

0 comments on commit cb7c923

Please sign in to comment.