Univer
Univer Sheet
Tutorials
How to find the command ID

How to find the command ID

📊📝📽️ Univer General

Developers often need to find the ID of a command when extending or developing a plugin. With the large number of commands in the Univer ecosystem, how can you quickly find the ID of a command?

Import from the plugin 0.2.0+

Univer exports all commands, and you can find the target command in the API Reference and import it from the corresponding package to get the command ID.

For example, if you want to find the ID of the command to set the underline of a range, you can first find it in the API Reference - Variable: SetRangeUnderlineCommand. Then you can import it and get the command ID like this:

import { SetRangeUnderlineCommand } from '@univerjs/sheets-ui';
 
console.log(SetRangeUnderlineCommand.id);

Enable logging

When creating an Univer instance, you can set the log level through the logLevel parameter. There are 5 log levels:

  • LogLevel.SILENT: No logs are output
  • LogLevel.ERROR: Only error logs are output
  • LogLevel.WARN: Error and warning logs are output
  • LogLevel.INFO: Error, warning, and information logs are output
  • LogLevel.VERBOSE: All logs are output
const univer = new Univer({
+  logLevel: LogLevel.VERBOSE,
});

By using the LogLevel.VERBOSE log level, Univer will output all operation log information, including the ID of the command.

It is important to note that the default log level of some browsers may hide VERBOSE level logs, so you may need to manually adjust the log level of the browser.

Adjust the log level of the Edge browser

Read the source code

If you are familiar with the architecture of Univer, you should be able to easily find the ID of a command in the source code.

Commands are usually stored in the commands folder of the plugin directory. You need to find the corresponding file based on the function of the command, and then find the ID of the command in the file.

For example, the command to modify the background color of a Worksheet tab can be found in ./packages/ui/src/commands/commands/set-tab-color.command.ts, and the name of this ID is sheet.command.set-tab-color.


Copyright © 2021-2024 DreamNum Co,Ltd. All Rights Reserved.