跳转到主要内容
该接口支持笔记中的撤销还原操作。该接口修改的是套索的文本框数据,所以必须在套索文本框之后调用, 而且是套索单个文本框。如果套索的不是文本框,或者套索多个文本框,调用会失败。 所以建议在点击套索工具栏按钮后进入的插件界面调用该接口。
static modifyLassoText(textBox: {
  fontSize?: number;
  fontPath?: string;
  textContentFull: string;
  textRect: Rect;
  textDigestData?: string;
  textAlign?: number;
  textBold?: number;
  textItalics?: number;
  textFrameWidthType?: number;
  textFrameWidth?: number;
  textFrameStyle?: number;
  textEditable?: number;
}): Promise<APIResponse<boolean>>;
参数
参数类型说明
textBox.textContentFullstring文本内容(必填,非空)
textBox.textRectRect文本框矩形(必填,需为非零面积)
textBox.fontSizenumber字体大小(可选;需为正数)
textBox.fontPathstring字体路径(可选)
textBox.textDigestDatastring摘要数据(可选)
textBox.textAlignnumber对齐方式(可选)
textBox.textBoldnumber加粗(可选)
textBox.textItalicsnumber斜体(可选)
textBox.textFrameWidthTypenumber边框宽度类型(可选)
textBox.textFrameWidthnumber边框宽度(可选)
textBox.textFrameStylenumber边框样式(可选)
textBox.textEditablenumber是否可编辑(可选)
返回

示例

import { PluginNoteAPI, type TextBox } from 'sn-plugin-lib';

/**
 * 修改套索文本框的示例(读取后更新文本内容)。
 */
export async function exampleModifyLassoText() {
  const listRes = await PluginNoteAPI.getLassoText();
  if (!listRes.success) {
    throw new Error(listRes.error?.message ?? 'getLassoText 调用失败');
  }

  const textBoxes = (listRes.result ?? []) as TextBox[];
  const first = textBoxes[0];
  if (!first) {
    return false;
  }

  const res = await PluginNoteAPI.modifyLassoText({
    ...first,
    textContentFull: 'Updated by plugin',
  });

  if (!res.success) {
    throw new Error(res.error?.message ?? 'modifyLassoText 调用失败');
  }
  return res.result;
}