diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md new file mode 100644 index 0000000000000000000000000000000000000000..0ca983f04d6a480f3e6664dade122ae125a19074 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-InputMethodCommon.md @@ -0,0 +1,40 @@ +# InputMethodCommon + +> **说明:** +> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +输入法框架接口定义的公共属性信息。 + +## MediaType8+ + +光标移动方向类型枚举。 + +**系统能力:**SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 值 | 说明 | +| ------------ | ---- | ---------- | +| CURSOR_UP | 1 | 光标上移。 | +| CURSOR_DOWN | 2 | 光标下移。 | +| CURSOR_LEFT | 3 | 光标左移。 | +| CURSOR_RIGHT | 4 | 光标右移。 | + +## Range + +描述选中文本的范围 + + **系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ----- | ------ | ---- | ---- | ---------------------------------- | +| start | string | 是 | 是 | 选中文本的首字符在编辑框的索引值。 | +| end | string | 是 | 是 | 选中文本的末字符在编辑框的索引值。 | + +## Movement + +描述进行选中文本动作时光标移动的方向。 + + **系统能力:** SystemCapability.MiscServices.InputMethodFramework + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------- | --------- | ---- | ---- | ---------------------------------- | +| direction | Direction | 是 | 是 | 进行选中文本动作时光标移动的方向。 | diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index 25bc2f7229a365c222303352657433ca22f2b65c..e16ae0b52c4b8d45c4494ca338a86e907c0a676e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -839,6 +839,92 @@ inputMethodController.stopInput().then((result) => { }) ``` +### on('selectByRange')10+ + +on(type: 'selectByRange', callback: Callback<Range>): void + +订阅输入法应用按范围选中文本事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘selectByRange’时表示订阅输入法应用按范围选中文本事件监听。 | +| callback | Callback<Range> | 是 | 回调函数,返回需要选中的文本的范围。
开发者需要在回调函数中根据传入的范围选中编辑框中相应文本。 | + +**示例:** + +```js +inputMethodController.on('selectByRange', (range) => { + console.info('Succeeded in subscribing selectByRange: start: ' + range.start + " , end: " + range.end); +}); +``` + +### off('selectByRange')10+ + +off(type: 'selectByRange'): void + +取消订阅输入法应用按范围选中文本事件。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘selectByRange’时表示取消订阅输入法应用按范围选中文本事件监听。 | + +**示例:** + +```js +inputMethodController.off('selectByRange'); +``` + +### on('selectByMovement')10+ + +on(type: 'selectByMovement', callback: Callback<Range>): void + +订阅输入法应用按光标动作选中文本事件。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘selectByMovement’时表示订阅输入法应用按光标移动动作选中文本事件监听。 | +| callback | Callback<Movement> | 是 | 回调函数,返回需要选中的文本的范围。
开发者需要在回调函数中根据传入的光标动作选中编辑框中相应文本。 | + +**示例:** + +```js +inputMethodController.on('selectByMovement', (movement) => { + console.info('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); +}); +``` + +### off('selectByMovement')10+ + +off(type: 'selectByMovement'): void + +取消订阅输入法应用按光标动作选中文本事件。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 设置监听类型。
-type为‘selectByMovement’时表示取消订阅输入法应用按范围选中文本事件监听。 | + +**示例:** + +```js +inputMethodController.off('selectByMovement'); +``` + ## InputMethodSetting8+ 下列API示例中都需使用[getSetting](#inputmethodgetsetting9)获取到InputMethodSetting实例,再通过此实例调用对应方法。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md index 72f116c900e3921315385e2dab0d54dd277e6bec..aa8433bf1a2bab3d387edb37d30a7d162fcba2a5 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -1495,6 +1495,172 @@ try { } ``` +### selectByRange10+ + +selectByRange(range: Range, callback: AsyncCallback<void>): void + +根据索引范围选中文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------- | ---- | ------------------------------------------------------------ | +| range | Range | 是 | 选中文本的范围。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------- | +| 401 | parameter error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +try { + inputClient.selectByRange({start: 0, end: 1}, (err) => { + if (err !== undefined) { + console.error('Failed to selectByRange: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in selecting by range.'); + }); +} catch (err) { + console.error('Failed to selectByRange: ' + JSON.stringify(err)); +} +``` + +### selectByRange10+ + +selectByRange(range: Range): Promise<void> + +根据索引范围选中文本。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ----- | ---- | ---------------- | +| range | Range | 是 | 选中文本的范围。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------- | +| 401 | parameter error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +try { + inputClient.selectByRange({start: 0, end:1}).then(() => { + console.log('Succeeded in selecting by range.'); + }).catch((err) => { + console.error('Failed to selectByRange: ' + JSON.stringify(err)); + }); +} catch (err) { + console.log('Failed to selectByRange: ' + JSON.stringify(err)); +} +``` + +### selectByMovement10+ + +selectByMovement(movement: Movement, callback: AsyncCallback<void>): void + +根据光标移动方向选中文本。使用callback异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------- | ---- | ------------------------------------------------------------ | +| movement | Movement | 是 | 选中时光标移动的方向。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当成功发送选中事件后,err为undefined,否则为错误对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------- | +| 401 | parameter error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +try { + inputClient.selectByMovement({direction: 1}, (err) => { + if (err !== undefined) { + console.error('Failed to selectByMovement: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in selecting by movement.'); + }); +} catch (err) { + console.error('Failed to selectByMovement: ' + JSON.stringify(err)); +} +``` + +### selectByMovement10+ + +selectByMovement(range: Range): Promise<void> + +根据索引范围选中文本。使用promise异步回调。 + +**系统能力:** SystemCapability.MiscServices.InputMethodFramework + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | ---- | ---------------------- | +| movement | Movement | 是 | 选中时光标移动的方向。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[输入法框架错误码](../errorcodes/errorcode-inputmethod-framework.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------- | +| 401 | parameter error. | +| 12800003 | Input method client error. | + +**示例:** + +```js +try { + inputClient.selectByMovement({direction: 1}).then(() => { + console.log('Succeeded in selecting by movement.'); + }).catch((err) => { + console.error('Failed to selectByMovement: ' + JSON.stringify(err)); + }); +} catch (err) { + console.log('Failed to selectByMovement: ' + JSON.stringify(err)); +} +``` + ## EditorAttribute 编辑框属性值。