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

feat(sheets-ui): optimize shortcut for comment & hyperlink editor #3434

Merged
merged 1 commit into from
Sep 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ export function ListDropDown(props: IDropdownComponentProps) {
p: null,
f: null,
si: null,
custom: {
__link_url: '',
},
},
};

Expand Down
24 changes: 18 additions & 6 deletions packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serial
import { SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';
import { SheetHyperLinkType } from '@univerjs/sheets-hyper-link';
import { IEditorBridgeService, IMarkSelectionService, ScrollToRangeOperation } from '@univerjs/sheets-ui';
import { IZenZoneService, RangeSelector, useEvent, useObservable } from '@univerjs/ui';
import { IZenZoneService, KeyCode, RangeSelector, useEvent, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import type { DocumentDataModel, IUnitRangeWithName, Nullable, Workbook } from '@univerjs/core';
import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
Expand Down Expand Up @@ -272,6 +272,11 @@ export const CellLinkEdit = () => {
});

const handleSubmit = async () => {
if ((showLabel && !display) || !payload || (type === SheetHyperLinkType.URL && !isLegalLink(payload))) {
setShowError(true);
return;
}

if (editing) {
if (id) {
const commandId = (editing.type === HyperLinkEditSourceType.ZEN_EDITOR || editing.type === HyperLinkEditSourceType.EDITING) ? UpdateRichHyperLinkCommand.id : UpdateHyperLinkCommand.id;
Expand Down Expand Up @@ -346,6 +351,12 @@ export const CellLinkEdit = () => {
setByPayload.current = false;
}}
placeholder={localeService.t('hyperLink.form.labelPlaceholder')}
autoFocus
onKeyDown={(e) => {
if (e.keyCode === KeyCode.ENTER) {
handleSubmit();
}
}}
/>
</FormLayout>
)
Expand Down Expand Up @@ -374,6 +385,12 @@ export const CellLinkEdit = () => {
}
}}
placeholder={localeService.t('hyperLink.form.linkPlaceholder')}
autoFocus={!showLabel}
onKeyDown={(e) => {
if (e.keyCode === KeyCode.ENTER) {
handleSubmit();
}
}}
/>
</FormLayout>
)}
Expand Down Expand Up @@ -478,11 +495,6 @@ export const CellLinkEdit = () => {
type="primary"
style={{ marginLeft: 8 }}
onClick={async () => {
if ((showLabel && !display) || !payload || (type === SheetHyperLinkType.URL && !isLegalLink(payload))) {
setShowError(true);
return;
}

handleSubmit();
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Button, Mention, Mentions } from '@univerjs/design';
import { DocSelectionManagerService } from '@univerjs/docs';
import { DocSelectionRenderService } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { KeyCode } from '@univerjs/ui';
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
import type { IDocumentBody } from '@univerjs/core';
import type { MentionProps } from '@univerjs/design';
Expand Down Expand Up @@ -113,11 +112,6 @@ export const ThreadCommentEditor = forwardRef<IThreadCommentEditorInstance, IThr
docSelectionRenderService?.blur();
setEditing(true);
}}
onKeyDown={(e) => {
if (e.keyCode === KeyCode.ENTER) {
handleSave();
}
}}
>
<Mention
key={mentionDataService.trigger}
Expand Down
Loading