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): doc select all content and remove when has tables #3800

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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 @@ -459,10 +459,9 @@ export interface IInnerCutCommandParams {
selections?: ITextRange[];
}

const INNER_CUT_COMMAND_ID = 'doc.command.inner-cut';

export const CutContentCommand: ICommand<IInnerCutCommandParams> = {
id: INNER_CUT_COMMAND_ID,
id: 'doc.command.inner-cut',

type: CommandType.COMMAND,

handler: async (accessor, params: IInnerCutCommandParams) => {
Expand All @@ -471,6 +470,7 @@ export const CutContentCommand: ICommand<IInnerCutCommandParams> = {
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selections = params.selections ?? docSelectionManagerService.getTextRanges();

const rectRanges = docSelectionManagerService.getRectRanges();

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { DocumentDataModel, ICommand } from '@univerjs/core';
import type { ISuccinctDocRangeParam } from '@univerjs/engine-render';
import { CommandType, DOC_RANGE_TYPE, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';

interface ISelectAllCommandParams { }

export const DocSelectAllCommand: ICommand<ISelectAllCommandParams> = {
id: 'doc.command.select-all',
type: CommandType.COMMAND,
handler: async (accessor) => {
const univerInstanceService = accessor.get(IUniverInstanceService);
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
const docDataModel = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);
const activeTextRange = docSelectionManagerService.getActiveTextRange();
if (docDataModel == null || activeTextRange == null) {
return false;
}

const { segmentId } = activeTextRange;
const unitId = docDataModel.getUnitId();
const prevBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;
if (prevBody == null) {
return false;
}

const { tables = [] } = prevBody;
const textRanges: ISuccinctDocRangeParam[] = [];
let offset = 0;

for (const table of tables) {
const { startIndex, endIndex } = table;
if (offset !== startIndex) {
textRanges.push({
startOffset: offset,
endOffset: startIndex - 1,
rangeType: DOC_RANGE_TYPE.TEXT,
});
}

// Push the rect range.
textRanges.push({
startOffset: startIndex + 3, // 3 is TABLE_START, ROW_START, CELL_START.
endOffset: endIndex - 5, // 4 is CELL_END, ROW_END, TABLE_END AND \n.
rangeType: DOC_RANGE_TYPE.RECT,
});

offset = endIndex;
}

if (offset !== prevBody.dataStream.length - 2) {
textRanges.push({
startOffset: offset,
endOffset: prevBody.dataStream.length - 2,
rangeType: DOC_RANGE_TYPE.TEXT,
});
}

docSelectionManagerService.replaceDocRanges(textRanges, {
unitId,
subUnitId: unitId,
}, false);

return true;
},
};

This file was deleted.

4 changes: 2 additions & 2 deletions packages/docs-ui/src/docs-ui-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { DeleteCommand, InsertCommand, UpdateCommand } from './commands/commands
import { DeleteCustomBlockCommand, DeleteLeftCommand, DeleteRightCommand, MergeTwoParagraphCommand } from './commands/commands/delete.command';
import { CloseHeaderFooterCommand } from './commands/commands/doc-header-footer.command';
import { DocParagraphSettingCommand } from './commands/commands/doc-paragraph-setting.command';
import { DocSelectAllCommand } from './commands/commands/doc-select-all.command';
import { IMEInputCommand } from './commands/commands/ime-input.command';
import { ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from './commands/commands/inline-format.command';
import { BulletListCommand, ChangeListNestingLevelCommand, ChangeListTypeCommand, CheckListCommand, ListOperationCommand, OrderListCommand, QuickListCommand, ToggleCheckListCommand } from './commands/commands/list.command';
Expand All @@ -51,7 +52,6 @@ import { DocTableInsertColumnCommand, DocTableInsertColumnLeftCommand, DocTableI
import { DocTableTabCommand } from './commands/commands/table/doc-table-tab.command';
import { MoveCursorOperation, MoveSelectionOperation } from './commands/operations/doc-cursor.operation';
import { DocParagraphSettingPanelOperation } from './commands/operations/doc-paragraph-setting-panel.operation';
import { SelectAllOperation } from './commands/operations/select-all.operation';
import { SetDocZoomRatioOperation } from './commands/operations/set-doc-zoom-ratio.operation';
import { AppUIController } from './controllers';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
Expand Down Expand Up @@ -211,7 +211,7 @@ export class UniverDocsUIPlugin extends Plugin {
ReplaceSnapshotCommand,
CoverContentCommand,
SetDocZoomRatioCommand,
SelectAllOperation,
DocSelectAllCommand,
DocParagraphSettingPanelOperation,
MoveCursorOperation,
MoveSelectionOperation,
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 @@ -147,7 +147,7 @@ export { genTableSource, getEmptyTableCell, getEmptyTableRow, getTableColumn } f
export { DocCreateTableOperation } from './commands/operations/doc-create-table.operation';
export { MoveSelectionOperation } from './commands/operations/doc-cursor.operation';
export { MoveCursorOperation } from './commands/operations/doc-cursor.operation';
export { SelectAllOperation } from './commands/operations/select-all.operation';
export { DocSelectAllCommand } from './commands/commands/doc-select-all.command';
export { type ISetDocZoomRatioOperationParams, SetDocZoomRatioOperation } from './commands/operations/set-doc-zoom-ratio.operation';

// #endregion
2 changes: 1 addition & 1 deletion packages/docs-ui/src/shortcuts/core-editing.shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { KeyCode } from '@univerjs/ui';
import type { IShortcutItem } from '@univerjs/ui';
import { KeyCode } from '@univerjs/ui';
import { EnterCommand } from '../commands/commands/auto-format.command';
import { DeleteLeftCommand, DeleteRightCommand } from '../commands/commands/delete.command';
import { whenDocAndEditorFocused, whenDocAndEditorFocusedWithBreakLine } from './utils';
Expand Down
6 changes: 3 additions & 3 deletions packages/docs-ui/src/shortcuts/cursor.shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

import type { IShortcutItem } from '@univerjs/ui';
import { Direction, EDITOR_ACTIVATED, FOCUSING_DOC, FOCUSING_UNIVER_EDITOR } from '@univerjs/core';
import { KeyCode, MetaKeys } from '@univerjs/ui';
import type { IShortcutItem } from '@univerjs/ui';
import { DocSelectAllCommand } from '../commands/commands/doc-select-all.command';
import { MoveCursorOperation, MoveSelectionOperation } from '../commands/operations/doc-cursor.operation';
import { SelectAllOperation } from '../commands/operations/select-all.operation';
import { whenDocAndEditorFocused } from './utils';

export const MoveCursorUpShortcut: IShortcutItem = {
Expand Down Expand Up @@ -94,7 +94,7 @@ export const MoveSelectionRightShortcut: IShortcutItem = {
};

export const SelectAllShortcut: IShortcutItem = {
id: SelectAllOperation.id,
id: DocSelectAllCommand.id,
binding: KeyCode.A | MetaKeys.CTRL_COMMAND,
preconditions: (contextService) =>
contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && (contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED)),
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-ui/src/shortcuts/toolbar.shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { KeyCode, MetaKeys } from '@univerjs/ui';
import type { IShortcutItem } from '@univerjs/ui';
import { KeyCode, MetaKeys } from '@univerjs/ui';
import { SetInlineFormatBoldCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatUnderlineCommand } from '../commands/commands/inline-format.command';
import { BulletListCommand, OrderListCommand } from '../commands/commands/list.command';
import { AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignRightCommand } from '../commands/commands/paragraph-align.command';
Expand Down
Loading