diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 09fdd142cab4..d768bd39df70 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -88,6 +88,7 @@ export { type IMutationInfo, type IOperation, type IOperationInfo, + type ISyncableCommandExecutionOptions, NilCommand, sequenceExecute, sequenceExecuteAsync, diff --git a/packages/core/src/services/command/command.service.ts b/packages/core/src/services/command/command.service.ts index 1514c85e6c6e..ee3d79751ad0 100644 --- a/packages/core/src/services/command/command.service.ts +++ b/packages/core/src/services/command/command.service.ts @@ -233,6 +233,18 @@ export interface ICommandService { * @param listener */ beforeCommandExecuted(listener: CommandListener): IDisposable; + /** + * Execute a command with the given id and parameters syncable. + * @param id Identifier of the command. + * @param params Parameters of this execution. + * @param options Options of this execution. + * @returns The result of the execution. It is a boolean value by default which indicates the command is executed. + */ + syncableExecuteCommand
(
+ id: string,
+ params?: P,
+ options?: IExecutionOptions & ISyncableCommandExecutionOptions (id: string, params?: P, options?: IExecutionOptions & ISyncableCommandExecutionOptions (id, params, options);
+ }
+
private _pushCommandExecutionStack(stackItem: ICommandExecutionStackItem): IDisposable {
this._commandExecutionStack.push(stackItem);
return toDisposable(() => remove(this._commandExecutionStack, stackItem));
diff --git a/packages/sheets/src/facade/f-range.ts b/packages/sheets/src/facade/f-range.ts
index 9a944b062a18..69330cab78b0 100644
--- a/packages/sheets/src/facade/f-range.ts
+++ b/packages/sheets/src/facade/f-range.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import type { CellValue, ICellData, IColorStyle, IObjectMatrixPrimitiveType, IRange, IStyleData, ITextDecoration, Nullable, Workbook, Worksheet } from '@univerjs/core';
-import type { ISetHorizontalTextAlignCommandParams, ISetStyleCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams, IStyleTypeValue } from '@univerjs/sheets';
+import type { CellValue, ICellData, IColorStyle, IObjectMatrixPrimitiveType, IRange, IStyleData, ISyncableCommandExecutionOptions, ITextDecoration, Nullable, Workbook, Worksheet } from '@univerjs/core';
+import type { ISetHorizontalTextAlignCommandParams, ISetRangeValuesCommandParams, ISetStyleCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams, IStyleTypeValue } from '@univerjs/sheets';
import type { FHorizontalAlignment, FVerticalAlignment } from './utils';
import { BooleanNumber, Dimension, FBase, ICommandService, Inject, Injector, Rectangle, WrapStrategy } from '@univerjs/core';
import { FormulaDataModel } from '@univerjs/engine-formula';
@@ -309,21 +309,22 @@ export class FRange extends FBase {
* Sets a different value for each cell in the range. The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats. If a value begins with `=`, it is interpreted as a formula.
* @param value
*/
- setValues(
+ setValues
+ ): S extends true ? R : Promise): S extends true ? R : Promise(
value:
| CellValue[][]
| IObjectMatrixPrimitiveType = {}
+ ) {
+ const { sync } = options;
const realValue = covertCellValues(value, this._range);
-
- return this._commandService.executeCommand(SetRangeValuesCommand.id, {
+ return this._commandService.syncableExecuteCommand