提交 aa93b19c 编写于 作者: G guojin31

输入法示例代码ArkTs规范整改

Signed-off-by: Nguojin31 <guojin31@huawei.com>
上级 aa86c2ec
...@@ -61,13 +61,13 @@ ...@@ -61,13 +61,13 @@
export default class InputDemoService extends InputMethodExtensionAbility { export default class InputDemoService extends InputMethodExtensionAbility {
onCreate(want: Want) { onCreate(want: Want): void {
keyboardController.onCreate(this.context); // 初始化窗口并注册对输入法框架的事件监听 keyboardController.onCreate(this.context); // 初始化窗口并注册对输入法框架的事件监听
} }
onDestroy() { onDestroy(): void {
console.log("onDestroy."); console.log("onDestroy.");
this.keyboardController.onDestroy(); // 销毁窗口并去注册事件监听 keyboardController.onDestroy(); // 销毁窗口并去注册事件监听
} }
} }
``` ```
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import display from '@ohos.display'; import display from '@ohos.display';
import inputMethodEngine from '@ohos.inputMethodEngine'; import inputMethodEngine from '@ohos.inputMethodEngine';
import InputMethodExtensionContext from '@ohos.inputMethodExtensionContext'; import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
// 调用输入法框架的getInputMethodAbility方法获取实例,并由此实例调用输入法框架功能接口 // 调用输入法框架的getInputMethodAbility方法获取实例,并由此实例调用输入法框架功能接口
const inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility(); const inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility();
...@@ -95,13 +95,13 @@ ...@@ -95,13 +95,13 @@
public onCreate(context: InputMethodExtensionContext): void public onCreate(context: InputMethodExtensionContext): void
{ {
this.mContext = context; this.mContext = context;
this.initWindow(); // 初始化窗口 this.initWindow(); // 初始化窗口
this.registerListener(); // 注册对输入法框架的事件监听 this.registerListener(); // 注册对输入法框架的事件监听
} }
public onDestroy(): void // 应用生命周期销毁 public onDestroy(): void // 应用生命周期销毁
{ {
this.unRegisterListener(); // 去注册事件监听 this.unRegisterListener(); // 去注册事件监听
if(this.panel) { // 销毁窗口 if(this.panel) { // 销毁窗口
this.panel.hide(); this.panel.hide();
inputMethodAbility.destroyPanel(this.panel); inputMethodAbility.destroyPanel(this.panel);
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
} }
} }
private initWindow(): void // 初始化窗口 private initWindow(): void // 初始化窗口
{ {
if(this.mContext === undefined) { if(this.mContext === undefined) {
return; return;
...@@ -150,18 +150,18 @@ ...@@ -150,18 +150,18 @@
private registerListener(): void private registerListener(): void
{ {
this.registerInputListener(); // 注册对输入法框架服务的监听 this.registerInputListener(); // 注册对输入法框架服务的监听
... ...
// 注册隐藏键盘事件监听等 // 注册隐藏键盘事件监听等
} }
private registerInputListener(): void { // 注册对输入法框架服务的开启及停止事件监听 private registerInputListener(): void { // 注册对输入法框架服务的开启及停止事件监听
inputMethodAbility.on('inputStart', (kbController, textInputClient) => { inputMethodAbility.on('inputStart', (kbController, textInputClient) => {
this.textInputClient = textInputClient; // 此为输入法客户端实例,由此调用输入法框架提供给输入法应用的功能接口 this.textInputClient = textInputClient; // 此为输入法客户端实例,由此调用输入法框架提供给输入法应用的功能接口
this.boardController = kbController; this.keyboardController = kbController;
}) })
inputMethodAbility.on('inputStop', () => { inputMethodAbility.on('inputStop', () => {
this.onDestroy(); // 销毁KeyboardController this.onDestroy(); // 销毁KeyboardController
}); });
} }
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
@Component @Component
struct keyItem { struct keyItem {
private keyValue: sourceListType private keyValue: sourceListType = numberSourceListData[0];
@State keyBgc: string = "#fff" @State keyBgc: string = "#fff"
@State keyFontColor: string = "#000" @State keyFontColor: string = "#000"
...@@ -283,9 +283,9 @@ ...@@ -283,9 +283,9 @@
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) {
Flex({ justifyContent: FlexAlign.SpaceBetween }) { Flex({ justifyContent: FlexAlign.SpaceBetween }) {
ForEach(this.numberList, (item: sourceListType) => { // 数字键盘第一行 ForEach(this.numberList, (item: sourceListType) => { // 数字键盘第一行
keyItem({ keyValue: item }) keyItem({ keyValue: item })
}, (item: sourceListType): sourceListType => item.content); }, (item: sourceListType) => item.content);
} }
.padding({ top: "2%" }) .padding({ top: "2%" })
.width("96%") .width("96%")
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
## 导入模块 ## 导入模块
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
``` ```
...@@ -36,9 +36,11 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执 ...@@ -36,9 +36,11 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执
**示例:** **示例:**
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
import Want from '@ohos.app.ability.Want';
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onCreate(want) { onCreate(want: Want): void {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
} }
} }
...@@ -54,9 +56,10 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源 ...@@ -54,9 +56,10 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源
**示例:** **示例:**
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onDestroy() { onDestroy(): void {
console.log('onDestroy'); console.log('onDestroy');
} }
} }
......
...@@ -8,7 +8,7 @@ InputMethodExtensionContext模块是InputMethodExtensionAbility的上下文环 ...@@ -8,7 +8,7 @@ InputMethodExtensionContext模块是InputMethodExtensionAbility的上下文环
## 导入模块 ## 导入模块
``` ```ts
import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext'; import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
``` ```
...@@ -16,10 +16,11 @@ import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext'; ...@@ -16,10 +16,11 @@ import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。 在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
class EntryAbility extends InputMethodExtensionAbility { import Want from '@ohos.app.ability.Want';
onCreate() { class InputMethodExtnAbility extends InputMethodExtensionAbility {
onCreate(want: Want): void {
let context = this.context; let context = this.context;
} }
} }
...@@ -41,8 +42,12 @@ destroy(callback: AsyncCallback\<void>): void ...@@ -41,8 +42,12 @@ destroy(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
this.context.destroy(() => { this.context.destroy((err: Error) => {
if(err) {
console.log('Failed to destroy context.');
return;
}
console.log('Succeeded in destroying context.'); console.log('Succeeded in destroying context.');
}); });
``` ```
...@@ -63,8 +68,10 @@ destroy(): Promise\<void>; ...@@ -63,8 +68,10 @@ destroy(): Promise\<void>;
**示例:** **示例:**
```js ```ts
this.context.destroy().then(() => { this.context.destroy().then(() => {
console.log('Succeed in destroying context.'); console.log('Succeed in destroying context.');
}).catch((err: Error)=>{
console.log('Failed to destroy context.');
}); });
``` ```
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
## 导入模块 ## 导入模块
``` ```ts
import InputMethodSubtype from '@ohos.InputMethodSubtype'; import InputMethodSubtype from '@ohos.InputMethodSubtype';
``` ```
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
## 导入模块 ## 导入模块
```js ```ts
import inputMethod from '@ohos.inputMethod'; import inputMethod from '@ohos.inputMethod';
``` ```
...@@ -65,7 +65,7 @@ getController(): InputMethodController ...@@ -65,7 +65,7 @@ getController(): InputMethodController
**示例:** **示例:**
```js ```ts
let inputMethodController = inputMethod.getController(); let inputMethodController = inputMethod.getController();
``` ```
...@@ -93,7 +93,7 @@ getSetting(): InputMethodSetting ...@@ -93,7 +93,7 @@ getSetting(): InputMethodSetting
**示例:** **示例:**
```js ```ts
let inputMethodSetting = inputMethod.getSetting(); let inputMethodSetting = inputMethod.getSetting();
``` ```
...@@ -125,10 +125,10 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolea ...@@ -125,10 +125,10 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolea
**示例:** **示例:**
```js ```ts
let currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
try{ try{
inputMethod.switchInputMethod(currentIme, (err, result) => { inputMethod.switchInputMethod(currentIme, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
return; return;
...@@ -175,19 +175,19 @@ switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt; ...@@ -175,19 +175,19 @@ switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
try { try {
inputMethod.switchInputMethod(currentIme).then((result) => { inputMethod.switchInputMethod(currentIme).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in switching inputmethod.'); console.log('Succeeded in switching inputmethod.');
} else { } else {
console.error('Failed to switchInputMethod.'); console.error('Failed to switchInputMethod.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch (err) {
console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -208,7 +208,7 @@ getCurrentInputMethod(): InputMethodProperty ...@@ -208,7 +208,7 @@ getCurrentInputMethod(): InputMethodProperty
**示例:** **示例:**
```js ```ts
let currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
``` ```
...@@ -244,8 +244,9 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb ...@@ -244,8 +244,9 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb
**示例:** **示例:**
```js ```ts
try { try {
let extra: Record<string, string> = {}
inputMethod.switchCurrentInputMethodSubtype({ inputMethod.switchCurrentInputMethodSubtype({
id: "ServiceExtAbility", id: "ServiceExtAbility",
label: "", label: "",
...@@ -255,8 +256,8 @@ try { ...@@ -255,8 +256,8 @@ try {
language: "", language: "",
icon: "", icon: "",
iconId: 0, iconId: 0,
extra: {} extra: extra
}, (err, result) => { }, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -309,8 +310,9 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean& ...@@ -309,8 +310,9 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&
**示例:** **示例:**
```js ```ts
try { try {
let extra: Record<string, string> = {}
inputMethod.switchCurrentInputMethodSubtype({ inputMethod.switchCurrentInputMethodSubtype({
id: "ServiceExtAbility", id: "ServiceExtAbility",
label: "", label: "",
...@@ -320,14 +322,14 @@ try { ...@@ -320,14 +322,14 @@ try {
language: "", language: "",
icon: "", icon: "",
iconId: 0, iconId: 0,
extra: {} extra: extra
}).then((result) => { }).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in switching currentInputMethodSubtype.'); console.log('Succeeded in switching currentInputMethodSubtype.');
} else { } else {
console.error('Failed to switchCurrentInputMethodSubtype.'); console.error('Failed to switchCurrentInputMethodSubtype.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -351,7 +353,7 @@ getCurrentInputMethodSubtype(): InputMethodSubtype ...@@ -351,7 +353,7 @@ getCurrentInputMethodSubtype(): InputMethodSubtype
**示例:** **示例:**
```js ```ts
let currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
``` ```
...@@ -384,11 +386,11 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp ...@@ -384,11 +386,11 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp
**示例:** **示例:**
```js ```ts
let currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
let imSubType = inputMethod.getCurrentInputMethodSubtype(); let imSubType = inputMethod.getCurrentInputMethodSubtype();
try { try {
inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err,result) => { inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -438,17 +440,17 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp ...@@ -438,17 +440,17 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp
**示例:** **示例:**
```js ```ts
let currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
let imSubType = inputMethod.getCurrentInputMethodSubtype(); let imSubType = inputMethod.getCurrentInputMethodSubtype();
try { try {
inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result) => { inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in switching currentInputMethodAndSubtype.'); console.log('Succeeded in switching currentInputMethodAndSubtype.');
} else { } else {
console.error('Failed to switchCurrentInputMethodAndSubtype.'); console.error('Failed to switchCurrentInputMethodAndSubtype.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -476,7 +478,7 @@ getInputMethodController(): InputMethodController ...@@ -476,7 +478,7 @@ getInputMethodController(): InputMethodController
**示例:** **示例:**
```js ```ts
let inputMethodController = inputMethod.getInputMethodController(); let inputMethodController = inputMethod.getInputMethodController();
``` ```
...@@ -500,7 +502,7 @@ getInputMethodSetting(): InputMethodSetting ...@@ -500,7 +502,7 @@ getInputMethodSetting(): InputMethodSetting
**示例:** **示例:**
```js ```ts
let inputMethodSetting = inputMethod.getInputMethodSetting(); let inputMethodSetting = inputMethod.getInputMethodSetting();
``` ```
...@@ -694,7 +696,7 @@ attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback&lt ...@@ -694,7 +696,7 @@ attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback&lt
**示例:** **示例:**
```js ```ts
try { try {
let textConfig: inputMethod.TextConfig = { let textConfig: inputMethod.TextConfig = {
inputAttribute: { inputAttribute: {
...@@ -702,7 +704,7 @@ try { ...@@ -702,7 +704,7 @@ try {
enterKeyType: 1 enterKeyType: 1
} }
}; };
inputMethodController.attach(true, textConfig, (err) => { inputMethodController.attach(true, textConfig, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to attach: ${JSON.stringify(err)}`); console.error(`Failed to attach: ${JSON.stringify(err)}`);
return; return;
...@@ -750,7 +752,7 @@ attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt; ...@@ -750,7 +752,7 @@ attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
let textConfig: inputMethod.TextConfig = { let textConfig: inputMethod.TextConfig = {
inputAttribute: { inputAttribute: {
...@@ -760,7 +762,7 @@ try { ...@@ -760,7 +762,7 @@ try {
}; };
inputMethodController.attach(true, textConfig).then(() => { inputMethodController.attach(true, textConfig).then(() => {
console.log('Succeeded in attaching inputMethod.'); console.log('Succeeded in attaching inputMethod.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to attach: ${JSON.stringify(err)}`); console.error(`Failed to attach: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -798,8 +800,8 @@ showTextInput(callback: AsyncCallback&lt;void&gt;): void ...@@ -798,8 +800,8 @@ showTextInput(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.showTextInput((err) => { inputMethodController.showTextInput((err: Error) => {
if (err) { if (err) {
console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
return; return;
...@@ -838,10 +840,10 @@ showTextInput(): Promise&lt;void&gt; ...@@ -838,10 +840,10 @@ showTextInput(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
inputMethodController.showTextInput().then(() => { inputMethodController.showTextInput().then(() => {
console.log('Succeeded in showing text input.'); console.log('Succeeded in showing text input.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -878,8 +880,8 @@ hideTextInput(callback: AsyncCallback&lt;void&gt;): void ...@@ -878,8 +880,8 @@ hideTextInput(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.hideTextInput((err) => { inputMethodController.hideTextInput((err: Error) => {
if (err) { if (err) {
console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
return; return;
...@@ -920,10 +922,10 @@ hideTextInput(): Promise&lt;void&gt; ...@@ -920,10 +922,10 @@ hideTextInput(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
inputMethodController.hideTextInput().then(() => { inputMethodController.hideTextInput().then(() => {
console.log('Succeeded in hiding inputMethod.'); console.log('Succeeded in hiding inputMethod.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
}) })
``` ```
...@@ -953,8 +955,8 @@ detach(callback: AsyncCallback&lt;void&gt;): void ...@@ -953,8 +955,8 @@ detach(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.detach((err) => { inputMethodController.detach((err: Error) => {
if (err) { if (err) {
console.error(`Failed to detach: ${JSON.stringify(err)}`); console.error(`Failed to detach: ${JSON.stringify(err)}`);
return; return;
...@@ -988,10 +990,10 @@ detach(): Promise&lt;void&gt; ...@@ -988,10 +990,10 @@ detach(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
inputMethodController.detach().then(() => { inputMethodController.detach().then(() => {
console.log('Succeeded in detaching inputMethod.'); console.log('Succeeded in detaching inputMethod.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to detach: ${JSON.stringify(err)}`); console.error(`Failed to detach: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1027,10 +1029,10 @@ setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -1027,10 +1029,10 @@ setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
try { try {
let windowId: number = 2000; let windowId: number = 2000;
inputMethodController.setCallingWindow(windowId, (err) => { inputMethodController.setCallingWindow(windowId, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
return; return;
...@@ -1078,12 +1080,12 @@ setCallingWindow(windowId: number): Promise&lt;void&gt; ...@@ -1078,12 +1080,12 @@ setCallingWindow(windowId: number): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
let windowId: number = 2000; let windowId: number = 2000;
inputMethodController.setCallingWindow(windowId).then(() => { inputMethodController.setCallingWindow(windowId).then(() => {
console.log('Succeeded in setting callingWindow.'); console.log('Succeeded in setting callingWindow.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1118,9 +1120,10 @@ updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void ...@@ -1118,9 +1120,10 @@ updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}, (err) => { let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
inputMethodController.updateCursor(cursorInfo, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
return; return;
...@@ -1164,11 +1167,12 @@ updateCursor(cursorInfo: CursorInfo): Promise&lt;void&gt; ...@@ -1164,11 +1167,12 @@ updateCursor(cursorInfo: CursorInfo): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.updateCursor({left: 0, top: 0, width: 600, height: 800}).then(() => { let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
inputMethodController.updateCursor(cursorInfo).then(() => {
console.log('Succeeded in updating cursorInfo.'); console.log('Succeeded in updating cursorInfo.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1205,9 +1209,9 @@ changeSelection(text: string, start: number, end: number, callback: AsyncCallbac ...@@ -1205,9 +1209,9 @@ changeSelection(text: string, start: number, end: number, callback: AsyncCallbac
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.changeSelection('text', 0, 5, (err) => { inputMethodController.changeSelection('text', 0, 5, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
return; return;
...@@ -1253,11 +1257,11 @@ changeSelection(text: string, start: number, end: number): Promise&lt;void&gt; ...@@ -1253,11 +1257,11 @@ changeSelection(text: string, start: number, end: number): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.changeSelection('test', 0, 5).then(() => { inputMethodController.changeSelection('test', 0, 5).then(() => {
console.log('Succeeded in changing selection.'); console.log('Succeeded in changing selection.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1292,9 +1296,10 @@ updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;): ...@@ -1292,9 +1296,10 @@ updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;):
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}, (err) => { let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
inputMethodController.updateAttribute(inputAttribute, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
return; return;
...@@ -1338,11 +1343,12 @@ updateAttribute(attribute: InputAttribute): Promise&lt;void&gt; ...@@ -1338,11 +1343,12 @@ updateAttribute(attribute: InputAttribute): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.updateAttribute({textInputType: 0, enterKeyType: 1}).then(() => { let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
inputMethodController.updateAttribute(inputAttribute).then(() => {
console.log('Succeeded in updating attribute.'); console.log('Succeeded in updating attribute.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1379,9 +1385,9 @@ stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1379,9 +1385,9 @@ stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.stopInputSession((err, result) => { inputMethodController.stopInputSession((err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
return; return;
...@@ -1426,15 +1432,15 @@ stopInputSession(): Promise&lt;boolean&gt; ...@@ -1426,15 +1432,15 @@ stopInputSession(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.stopInputSession().then((result) => { inputMethodController.stopInputSession().then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in stopping inputSession.'); console.log('Succeeded in stopping inputSession.');
} else { } else {
console.error('Failed to stopInputSession.'); console.error('Failed to stopInputSession.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1473,8 +1479,8 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -1473,8 +1479,8 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.showSoftKeyboard((err) => { inputMethodController.showSoftKeyboard((err: Error) => {
if (!err) { if (!err) {
console.log('Succeeded in showing softKeyboard.'); console.log('Succeeded in showing softKeyboard.');
} else { } else {
...@@ -1514,10 +1520,10 @@ showSoftKeyboard(): Promise&lt;void&gt; ...@@ -1514,10 +1520,10 @@ showSoftKeyboard(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
inputMethodController.showSoftKeyboard().then(() => { inputMethodController.showSoftKeyboard().then(() => {
console.log('Succeeded in showing softKeyboard.'); console.log('Succeeded in showing softKeyboard.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1553,8 +1559,8 @@ hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -1553,8 +1559,8 @@ hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.hideSoftKeyboard((err) => { inputMethodController.hideSoftKeyboard((err: Error) => {
if (!err) { if (!err) {
console.log('Succeeded in hiding softKeyboard.'); console.log('Succeeded in hiding softKeyboard.');
} else { } else {
...@@ -1594,10 +1600,10 @@ hideSoftKeyboard(): Promise&lt;void&gt; ...@@ -1594,10 +1600,10 @@ hideSoftKeyboard(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
inputMethodController.hideSoftKeyboard().then(() => { inputMethodController.hideSoftKeyboard().then(() => {
console.log('Succeeded in hiding softKeyboard.'); console.log('Succeeded in hiding softKeyboard.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1624,8 +1630,8 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1624,8 +1630,8 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.stopInput((err, result) => { inputMethodController.stopInput((err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to stopInput: ${JSON.stringify(err)}`); console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
return; return;
...@@ -1660,14 +1666,14 @@ stopInput(): Promise&lt;boolean&gt; ...@@ -1660,14 +1666,14 @@ stopInput(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
inputMethodController.stopInput().then((result) => { inputMethodController.stopInput().then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in stopping input.'); console.log('Succeeded in stopping input.');
} else { } else {
console.error('Failed to stopInput.'); console.error('Failed to stopInput.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to stopInput: ${JSON.stringify(err)}`); console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
}) })
``` ```
...@@ -1697,9 +1703,9 @@ on(type: 'insertText', callback: (text: string) => void): void; ...@@ -1697,9 +1703,9 @@ on(type: 'insertText', callback: (text: string) => void): void;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('insertText', (text) => { inputMethodController.on('insertText', (text: string) => {
console.log(`Succeeded in subscribing insertText: ${text}`); console.log(`Succeeded in subscribing insertText: ${text}`);
}); });
} catch(err) { } catch(err) {
...@@ -1724,7 +1730,7 @@ off(type: 'insertText', callback?: (text: string) => void): void ...@@ -1724,7 +1730,7 @@ off(type: 'insertText', callback?: (text: string) => void): void
**示例:** **示例:**
```js ```ts
let onInsertTextCallback = (text: string) => { let onInsertTextCallback = (text: string) => {
console.log(`Succeeded in subscribing insertText: ${text}`); console.log(`Succeeded in subscribing insertText: ${text}`);
}; };
...@@ -1757,9 +1763,9 @@ on(type: 'deleteLeft', callback: (length: number) => void): void ...@@ -1757,9 +1763,9 @@ on(type: 'deleteLeft', callback: (length: number) => void): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('deleteLeft', (length) => { inputMethodController.on('deleteLeft', (length: number) => {
console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); console.log(`Succeeded in subscribing deleteLeft, length: ${length}`);
}); });
} catch(err) { } catch(err) {
...@@ -1784,7 +1790,7 @@ off(type: 'deleteLeft', callback?: (length: number) => void): void ...@@ -1784,7 +1790,7 @@ off(type: 'deleteLeft', callback?: (length: number) => void): void
**示例:** **示例:**
```js ```ts
let onDeleteLeftCallback = (length: number) => { let onDeleteLeftCallback = (length: number) => {
console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); console.log(`Succeeded in subscribing deleteLeft, length: ${length}`);
}; };
...@@ -1817,9 +1823,9 @@ on(type: 'deleteRight', callback: (length: number) => void): void ...@@ -1817,9 +1823,9 @@ on(type: 'deleteRight', callback: (length: number) => void): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('deleteRight', (length) => { inputMethodController.on('deleteRight', (length: number) => {
console.log(`Succeeded in subscribing deleteRight, length: ${length}`); console.log(`Succeeded in subscribing deleteRight, length: ${length}`);
}); });
} catch(err) { } catch(err) {
...@@ -1844,7 +1850,7 @@ off(type: 'deleteRight', callback?: (length: number) => void): void ...@@ -1844,7 +1850,7 @@ off(type: 'deleteRight', callback?: (length: number) => void): void
**示例:** **示例:**
```js ```ts
let onDeleteRightCallback = (length: number) => { let onDeleteRightCallback = (length: number) => {
console.log(`Succeeded in subscribing deleteRight, length: ${length}`); console.log(`Succeeded in subscribing deleteRight, length: ${length}`);
}; };
...@@ -1877,9 +1883,9 @@ on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => voi ...@@ -1877,9 +1883,9 @@ on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => voi
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('sendKeyboardStatus', (keyboardStatus) => { inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => {
console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
}); });
} catch(err) { } catch(err) {
...@@ -1904,8 +1910,8 @@ off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => v ...@@ -1904,8 +1910,8 @@ off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => v
**示例:** **示例:**
```js ```ts
let onSendKeyboardStatus = (keyboardStatus: KeyboardStatus) => { let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => {
console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
}; };
inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus); inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus);
...@@ -1937,9 +1943,9 @@ on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void ...@@ -1937,9 +1943,9 @@ on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('sendFunctionKey', (functionKey) => { inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => {
console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`); console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`);
}); });
} catch(err) { } catch(err) {
...@@ -1964,8 +1970,8 @@ off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): voi ...@@ -1964,8 +1970,8 @@ off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): voi
**示例:** **示例:**
```js ```ts
let onSendFunctionKey = (functionKey: FunctionKey) => { let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => {
console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`); console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`);
}; };
inputMethodController.off('sendFunctionKey', onSendFunctionKey); inputMethodController.off('sendFunctionKey', onSendFunctionKey);
...@@ -1997,9 +2003,9 @@ on(type: 'moveCursor', callback: (direction: Direction) => void): void ...@@ -1997,9 +2003,9 @@ on(type: 'moveCursor', callback: (direction: Direction) => void): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('moveCursor', (direction) => { inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => {
console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`);
}); });
} catch(err) { } catch(err) {
...@@ -2024,8 +2030,8 @@ off(type: 'moveCursor', callback?: (direction: Direction) => void): void ...@@ -2024,8 +2030,8 @@ off(type: 'moveCursor', callback?: (direction: Direction) => void): void
**示例:** **示例:**
```js ```ts
let onMoveCursorCallback = (direction: Direction) => { let onMoveCursorCallback = (direction: inputMethod.Direction) => {
console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`);
}; };
inputMethodController.off('moveCursor', onMoveCursorCallback); inputMethodController.off('moveCursor', onMoveCursorCallback);
...@@ -2057,9 +2063,9 @@ on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void ...@@ -2057,9 +2063,9 @@ on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('handleExtendAction', (action) => { inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => {
console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`);
}); });
} catch(err) { } catch(err) {
...@@ -2084,8 +2090,8 @@ off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void ...@@ -2084,8 +2090,8 @@ off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void
**示例:** **示例:**
```js ```ts
let onHandleExtendActionCallback = (action: ExtendAction) => { let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => {
console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`);
}; };
inputMethodController.off('handleExtendAction', onHandleExtendActionCallback); inputMethodController.off('handleExtendAction', onHandleExtendActionCallback);
...@@ -2109,8 +2115,8 @@ on(type: 'selectByRange', callback: Callback&lt;Range&gt;): void ...@@ -2109,8 +2115,8 @@ on(type: 'selectByRange', callback: Callback&lt;Range&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.on('selectByRange', (range) => { inputMethodController.on('selectByRange', (range: inputMethod.Range) => {
console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`); console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`);
}); });
``` ```
...@@ -2132,8 +2138,8 @@ off(type: 'selectByRange', callback?: Callback&lt;Range&gt;): void ...@@ -2132,8 +2138,8 @@ off(type: 'selectByRange', callback?: Callback&lt;Range&gt;): void
**示例:** **示例:**
```js ```ts
let onSelectByRangeCallback = (range: Range) => { let onSelectByRangeCallback = (range: inputMethod.Range) => {
console.log(`Succeeded in subscribing selectByRange, range: ${JSON.stringify(range)}`); console.log(`Succeeded in subscribing selectByRange, range: ${JSON.stringify(range)}`);
}; };
inputMethodController.off('selectByRange', onSelectByRangeCallback); inputMethodController.off('selectByRange', onSelectByRangeCallback);
...@@ -2157,8 +2163,8 @@ on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void ...@@ -2157,8 +2163,8 @@ on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodController.on('selectByMovement', (movement) => { inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => {
console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction);
}); });
``` ```
...@@ -2180,8 +2186,8 @@ off(type: 'selectByMovement', callback?: Callback&lt;Movement&gt;): void ...@@ -2180,8 +2186,8 @@ off(type: 'selectByMovement', callback?: Callback&lt;Movement&gt;): void
**示例:** **示例:**
```js ```ts
let onSelectByMovementCallback = (movement: Movement) => { let onSelectByMovementCallback = (movement: inputMethod.Movement) => {
console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`); console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`);
}; };
inputMethodController.off('selectByMovement', onSelectByMovementCallback); inputMethodController.off('selectByMovement', onSelectByMovementCallback);
...@@ -2213,15 +2219,15 @@ on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void; ...@@ -2213,15 +2219,15 @@ on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('getLeftTextOfCursor', (length) => { inputMethodController.on('getLeftTextOfCursor', (length: number) => {
console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`); console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`);
let text:string = ""; let text:string = "";
return text; return text;
}); });
} catch(err) { } catch(err) {
console.error(`Failed to subscribe getLeftTextOfCursor. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to subscribe getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2242,15 +2248,17 @@ off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void; ...@@ -2242,15 +2248,17 @@ off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.off('getLeftTextOfCursor', (length) => { let getLeftTextOfCursorCallback = (length: number) => {
console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`); console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`);
let text:string = ""; let text:string = "";
return text; return text;
}); };
inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback);
inputMethodController.off('getLeftTextOfCursor');
} catch(err) { } catch(err) {
console.error(`Failed to unsubscribing getLeftTextOfCursor. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2279,15 +2287,15 @@ on(type: 'getRightTextOfCursor', callback: (length: number) => string): void; ...@@ -2279,15 +2287,15 @@ on(type: 'getRightTextOfCursor', callback: (length: number) => string): void;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('getRightTextOfCursor', (length) => { inputMethodController.on('getRightTextOfCursor', (length: number) => {
console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`); console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`);
let text:string = ""; let text:string = "";
return text; return text;
}); });
} catch(err) { } catch(err) {
console.error(`Failed to subscribe getRightTextOfCursor. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2308,15 +2316,17 @@ off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void; ...@@ -2308,15 +2316,17 @@ off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.off('getRightTextOfCursor', (length) => { let getRightTextOfCursorCallback = (length: number) => {
console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`); console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`);
let text:string = ""; let text:string = "";
return text; return text;
}); };
inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback);
inputMethodController.off('getRightTextOfCursor');
} catch(err) { } catch(err) {
console.error(`Failed to unsubscribing getRightTextOfCursor. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2345,7 +2355,7 @@ on(type: 'getTextIndexAtCursor', callback: () => number): void; ...@@ -2345,7 +2355,7 @@ on(type: 'getTextIndexAtCursor', callback: () => number): void;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.on('getTextIndexAtCursor', () => { inputMethodController.on('getTextIndexAtCursor', () => {
console.info(`Succeeded in subscribing getTextIndexAtCursor.`); console.info(`Succeeded in subscribing getTextIndexAtCursor.`);
...@@ -2353,7 +2363,7 @@ try { ...@@ -2353,7 +2363,7 @@ try {
return index; return index;
}); });
} catch(err) { } catch(err) {
console.error(`Failed to subscribe getTextIndexAtCursor. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2374,15 +2384,17 @@ off(type: 'getTextIndexAtCursor', callback?: () => number): void; ...@@ -2374,15 +2384,17 @@ off(type: 'getTextIndexAtCursor', callback?: () => number): void;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodController.off('getTextIndexAtCursor', () => { let getTextIndexAtCursorCallback = () => {
console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`); console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`);
let index:number = 0; let index:number = 0;
return index; return index;
}); };
inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback);
inputMethodController.off('getTextIndexAtCursor');
} catch(err) { } catch(err) {
console.error(`Failed to unsubscribing getTextIndexAtCursor. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -2407,8 +2419,9 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input ...@@ -2407,8 +2419,9 @@ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, input
**示例:** **示例:**
```js ```ts
inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { import InputMethodSubtype from '@ohos.InputMethodSubtype';
inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => {
console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
}); });
``` ```
...@@ -2430,7 +2443,7 @@ off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inp ...@@ -2430,7 +2443,7 @@ off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inp
**示例:** **示例:**
```js ```ts
inputMethodSetting.off('imeChange'); inputMethodSetting.off('imeChange');
``` ```
...@@ -2453,8 +2466,8 @@ on(type: 'imeShow', callback: (info: Array\<InputWindowInfo>) => void): void ...@@ -2453,8 +2466,8 @@ on(type: 'imeShow', callback: (info: Array\<InputWindowInfo>) => void): void
**示例:** **示例:**
```js ```ts
inputMethodSetting.on('imeShow', (info) => { inputMethodSetting.on('imeShow', (info: Array<inputMethod.InputWindowInfo>) => {
console.info('Succeeded in subscribing imeShow event.'); console.info('Succeeded in subscribing imeShow event.');
}); });
``` ```
...@@ -2478,8 +2491,8 @@ on(type: 'imeHide', callback: (info: Array\<InputWindowInfo>) => void): void ...@@ -2478,8 +2491,8 @@ on(type: 'imeHide', callback: (info: Array\<InputWindowInfo>) => void): void
**示例:** **示例:**
```js ```ts
inputMethodSetting.on('imeHide', (info) => { inputMethodSetting.on('imeHide', (info: Array<inputMethod.InputWindowInfo>) => {
console.info('Succeeded in subscribing imeHide event.'); console.info('Succeeded in subscribing imeHide event.');
}); });
``` ```
...@@ -2503,7 +2516,7 @@ off(type: 'imeShow', callback?: (info: Array\<InputWindowInfo>) => void): void ...@@ -2503,7 +2516,7 @@ off(type: 'imeShow', callback?: (info: Array\<InputWindowInfo>) => void): void
**示例:** **示例:**
```js ```ts
inputMethodSetting.off('imeShow'); inputMethodSetting.off('imeShow');
``` ```
...@@ -2526,7 +2539,7 @@ off(type: 'imeHide', callback?: (info: Array\<InputWindowInfo>) => void): void ...@@ -2526,7 +2539,7 @@ off(type: 'imeHide', callback?: (info: Array\<InputWindowInfo>) => void): void
**示例:** **示例:**
```js ```ts
inputMethodSetting.off('imeHide'); inputMethodSetting.off('imeHide');
``` ```
...@@ -2556,13 +2569,15 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: Async ...@@ -2556,13 +2569,15 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: Async
**示例:** **示例:**
```js ```ts
let inputMethodProperty = { let inputMethodProperty: inputMethod.InputMethodProperty = {
name: 'com.example.kikakeyboard', packageName: 'com.example.kikakeyboard',
name: 'InputMethodExAbility',
methodId: '',
id: 'propertyId', id: 'propertyId',
} }
try { try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: Error, data: Array<InputMethodSubtype>) => {
if (err) { if (err) {
console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -2605,15 +2620,17 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Arr ...@@ -2605,15 +2620,17 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Arr
**示例:** **示例:**
```js ```ts
let inputMethodProperty = { let inputMethodProperty: inputMethod.InputMethodProperty = {
name: 'com.example.kikakeyboard', packageName: 'com.example.kikakeyboard',
name: 'InputMethodExAbility',
methodId: '',
id: 'propertyId', id: 'propertyId',
} }
try { try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array<InputMethodSubtype>) => {
console.log('Succeeded in listing inputMethodSubtype.'); console.log('Succeeded in listing inputMethodSubtype.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -2646,9 +2663,9 @@ listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSub ...@@ -2646,9 +2663,9 @@ listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSub
**示例:** **示例:**
```js ```ts
try { try {
inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { inputMethodSetting.listCurrentInputMethodSubtype((err: Error, data: Array<InputMethodSubtype>) => {
if (err) { if (err) {
console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -2685,11 +2702,11 @@ listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt; ...@@ -2685,11 +2702,11 @@ listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array<InputMethodSubtype>) => {
console.log('Succeeded in listing currentInputMethodSubtype.'); console.log('Succeeded in listing currentInputMethodSubtype.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -2729,9 +2746,9 @@ getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethod ...@@ -2729,9 +2746,9 @@ getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethod
**示例:** **示例:**
```js ```ts
try { try {
inputMethodSetting.getInputMethods(true, (err, data) => { inputMethodSetting.getInputMethods(true, (err: Error, data: Array<inputMethod.InputMethodProperty>) => {
if (err) { if (err) {
console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
return; return;
...@@ -2780,11 +2797,11 @@ getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt ...@@ -2780,11 +2797,11 @@ getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt
**示例:** **示例:**
```js ```ts
try { try {
inputMethodSetting.getInputMethods(true).then((data) => { inputMethodSetting.getInputMethods(true).then((data: Array<inputMethod.InputMethodProperty>) => {
console.log('Succeeded in getting inputMethods.'); console.log('Succeeded in getting inputMethods.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -2816,9 +2833,9 @@ showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2816,9 +2833,9 @@ showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
try { try {
inputMethodSetting.showOptionalInputMethods((err, data) => { inputMethodSetting.showOptionalInputMethods((err: Error, data: boolean) => {
if (err) { if (err) {
console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
return; return;
...@@ -2854,10 +2871,10 @@ showOptionalInputMethods(): Promise&lt;boolean&gt; ...@@ -2854,10 +2871,10 @@ showOptionalInputMethods(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
inputMethodSetting.showOptionalInputMethods().then((data) => { inputMethodSetting.showOptionalInputMethods().then((data: boolean) => {
console.log('Succeeded in showing optionalInputMethods.'); console.log('Succeeded in showing optionalInputMethods.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
}) })
``` ```
...@@ -2882,8 +2899,8 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;) ...@@ -2882,8 +2899,8 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;)
**示例:** **示例:**
```js ```ts
inputMethodSetting.listInputMethod((err, data) => { inputMethodSetting.listInputMethod((err: Error, data: Array<inputMethod.InputMethodProperty>) => {
if (err) { if (err) {
console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
return; return;
...@@ -2912,10 +2929,10 @@ listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt; ...@@ -2912,10 +2929,10 @@ listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
**示例:** **示例:**
```js ```ts
inputMethodSetting.listInputMethod().then((data) => { inputMethodSetting.listInputMethod().then((data: Array<inputMethod.InputMethodProperty>) => {
console.log('Succeeded in listing inputMethod.'); console.log('Succeeded in listing inputMethod.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
}) })
``` ```
...@@ -2940,8 +2957,8 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -2940,8 +2957,8 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
inputMethodSetting.displayOptionalInputMethod((err) => { inputMethodSetting.displayOptionalInputMethod((err: Error) => {
if (err) { if (err) {
console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
return; return;
...@@ -2970,10 +2987,10 @@ displayOptionalInputMethod(): Promise&lt;void&gt; ...@@ -2970,10 +2987,10 @@ displayOptionalInputMethod(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
inputMethodSetting.displayOptionalInputMethod().then(() => { inputMethodSetting.displayOptionalInputMethod().then(() => {
console.log('Succeeded in displaying optionalInputMethod.'); console.log('Succeeded in displaying optionalInputMethod.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
}) })
``` ```
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
## 导入模块 ## 导入模块
``` ```ts
import inputMethodEngine from '@ohos.inputMethodEngine'; import inputMethodEngine from '@ohos.inputMethodEngine';
``` ```
...@@ -68,7 +68,7 @@ getInputMethodAbility(): InputMethodAbility ...@@ -68,7 +68,7 @@ getInputMethodAbility(): InputMethodAbility
**示例:** **示例:**
```js ```ts
let InputMethodAbility = inputMethodEngine.getInputMethodAbility(); let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
``` ```
...@@ -88,7 +88,7 @@ getKeyboardDelegate(): KeyboardDelegate ...@@ -88,7 +88,7 @@ getKeyboardDelegate(): KeyboardDelegate
**示例:** **示例:**
```js ```ts
let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate(); let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
``` ```
...@@ -112,7 +112,7 @@ getInputMethodEngine(): InputMethodEngine ...@@ -112,7 +112,7 @@ getInputMethodEngine(): InputMethodEngine
**示例:** **示例:**
```js ```ts
let InputMethodEngine = inputMethodEngine.getInputMethodEngine(); let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
``` ```
...@@ -136,7 +136,7 @@ createKeyboardDelegate(): KeyboardDelegate ...@@ -136,7 +136,7 @@ createKeyboardDelegate(): KeyboardDelegate
**示例:** **示例:**
```js ```ts
let keyboardDelegate = inputMethodEngine.createKeyboardDelegate(); let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
``` ```
...@@ -161,10 +161,11 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli ...@@ -161,10 +161,11 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => { inputMethodEngine.getInputMethodEngine()
let keyboardController = kbController; .on('inputStart', (kbController: inputMethodEngine.KeyboardController, textClient: inputMethodEngine.TextInputClient) => {
let textInputClient = textClient; let keyboardController = kbController;
let textInputClient = textClient;
}); });
``` ```
...@@ -185,9 +186,10 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC ...@@ -185,9 +186,10 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => { inputMethodEngine.getInputMethodEngine()
console.log('delete inputStart notification.'); .off('inputStart', (kbController: inputMethodEngine.KeyboardController, textClient: inputMethodEngine.TextInputClient) => {
console.log('delete inputStart notification.');
}); });
``` ```
...@@ -208,7 +210,7 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ...@@ -208,7 +210,7 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => { inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
console.log('inputMethodEngine keyboardShow.'); console.log('inputMethodEngine keyboardShow.');
}); });
...@@ -234,7 +236,7 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ...@@ -234,7 +236,7 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodEngine().off('keyboardShow'); inputMethodEngine.getInputMethodEngine().off('keyboardShow');
inputMethodEngine.getInputMethodEngine().off('keyboardHide'); inputMethodEngine.getInputMethodEngine().off('keyboardHide');
``` ```
...@@ -260,10 +262,11 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: ...@@ -260,10 +262,11 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient:
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => { inputMethodEngine.getInputMethodAbility()
let keyboardController = kbController; .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
let inputClient = client; let keyboardController = kbController;
let inputClient = client;
}); });
``` ```
...@@ -284,7 +287,7 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClien ...@@ -284,7 +287,7 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClien
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().off('inputStart'); inputMethodEngine.getInputMethodAbility().off('inputStart');
``` ```
...@@ -305,7 +308,7 @@ on(type: 'inputStop', callback: () => void): void ...@@ -305,7 +308,7 @@ on(type: 'inputStop', callback: () => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().on('inputStop', () => { inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
console.log('inputMethodAbility inputStop'); console.log('inputMethodAbility inputStop');
}); });
...@@ -328,7 +331,7 @@ off(type: 'inputStop', callback: () => void): void ...@@ -328,7 +331,7 @@ off(type: 'inputStop', callback: () => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().off('inputStop', () => { inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
console.log('inputMethodAbility delete inputStop notification.'); console.log('inputMethodAbility delete inputStop notification.');
}); });
...@@ -351,8 +354,8 @@ on(type: 'setCallingWindow', callback: (wid: number) => void): void ...@@ -351,8 +354,8 @@ on(type: 'setCallingWindow', callback: (wid: number) => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => { inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid: number) => {
console.log('inputMethodAbility setCallingWindow'); console.log('inputMethodAbility setCallingWindow');
}); });
``` ```
...@@ -374,8 +377,8 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void ...@@ -374,8 +377,8 @@ off(type: 'setCallingWindow', callback: (wid:number) => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().off('setCallingWindow', (wid) => { inputMethodEngine.getInputMethodAbility().off('setCallingWindow', (wid: number) => {
console.log('inputMethodAbility delete setCallingWindow notification.'); console.log('inputMethodAbility delete setCallingWindow notification.');
}); });
``` ```
...@@ -397,7 +400,7 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ...@@ -397,7 +400,7 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => { inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
console.log('InputMethodAbility keyboardShow.'); console.log('InputMethodAbility keyboardShow.');
}); });
...@@ -423,7 +426,7 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ...@@ -423,7 +426,7 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => { inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
console.log('InputMethodAbility delete keyboardShow notification.'); console.log('InputMethodAbility delete keyboardShow notification.');
}); });
...@@ -449,8 +452,8 @@ on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => voi ...@@ -449,8 +452,8 @@ on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => voi
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => { inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype: InputMethodSubtype) => {
console.log('InputMethodAbility setSubtype.'); console.log('InputMethodAbility setSubtype.');
}); });
``` ```
...@@ -472,7 +475,7 @@ off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => v ...@@ -472,7 +475,7 @@ off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => v
**示例:** **示例:**
```js ```ts
inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
console.log('InputMethodAbility delete setSubtype notification.'); console.log('InputMethodAbility delete setSubtype notification.');
}); });
...@@ -502,20 +505,21 @@ createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>): ...@@ -502,20 +505,21 @@ createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>):
**示例:** **示例:**
```js ```ts
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED flag: inputMethodEngine.PanelFlag.FLG_FIXED
} }
try { try {
inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { inputMethodEngine.getInputMethodAbility()
if (err) { .createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => {
console.error(`Failed to createPanel: ${JSON.stringify(err)}`); if (err) {
return; console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
} return;
console.log('Succeed in creating panel.'); }
}) console.log('Succeed in creating panel.');
} catch(err) { })
} catch (err) {
console.error(`Failed to createPanel: ${JSON.stringify(err)}`); console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -548,16 +552,17 @@ createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel> ...@@ -548,16 +552,17 @@ createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel>
**示例:** **示例:**
```js ```ts
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED flag: inputMethodEngine.PanelFlag.FLG_FIXED
} }
inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo).then((panel) => { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo)
console.log('Succeed in creating panel.'); .then((panel: inputMethodEngine.Panel) => {
}).catch((err) => { console.log('Succeed in creating panel.');
console.error(`Failed to create panel: ${JSON.stringify(err)}`); }).catch((err: Error) => {
}) console.error(`Failed to create panel: ${JSON.stringify(err)}`);
})
``` ```
### destroyPanel<sup>10+</sup> ### destroyPanel<sup>10+</sup>
...@@ -577,33 +582,36 @@ destroyPanel(panel: Panel, callback: AsyncCallback\<void>): void; ...@@ -577,33 +582,36 @@ destroyPanel(panel: Panel, callback: AsyncCallback\<void>): void;
**示例:** **示例:**
```js ```ts
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED flag: inputMethodEngine.PanelFlag.FLG_FIXED
} }
let inputPanel: inputMethodEngine.Panel | undefined = undefined;
try { try {
inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { inputMethodEngine.getInputMethodAbility()
if (err) { .createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); if (err) {
return; console.error(`Failed to create panel: ${JSON.stringify(err)}`);
} return;
globalThis.inputMethodPanel = panel; }
console.log('Succeed in creating panel.'); inputPanel = panel;
}) console.log('Succeed in creating panel.');
} catch(err) { })
} catch (err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
} }
try { try {
inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel, (err) => { if (inputPanel) {
if(err !== undefined) { inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel, (err: Error) => {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); if (err !== undefined) {
return; console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
} return;
console.log('Succeed in destroying panel.'); }
}) console.log('Succeed in destroying panel.');
} catch(err) { })
}
} catch (err) {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -629,30 +637,34 @@ destroyPanel(panel: Panel): Promise\<void>; ...@@ -629,30 +637,34 @@ destroyPanel(panel: Panel): Promise\<void>;
**示例:** **示例:**
```js ```ts
let panelInfo: inputMethodEngine.PanelInfo = { let panelInfo: inputMethodEngine.PanelInfo = {
type: inputMethodEngine.PanelType.SOFT_KEYBOARD, type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
flag: inputMethodEngine.PanelFlag.FLG_FIXED flag: inputMethodEngine.PanelFlag.FLG_FIXED
} }
let inputPanel: inputMethodEngine.Panel | undefined = undefined;
try { try {
inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => { inputMethodEngine.getInputMethodAbility()
if (err) { .createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); if (err) {
return; console.error(`Failed to create panel: ${JSON.stringify(err)}`);
} return;
globalThis.inputMethodPanel = panel; }
console.log('Succeed in creating panel.'); inputPanel = panel;
}) console.log('Succeed in creating panel.');
} catch(err) { })
} catch (err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
} }
try { try {
inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel).then(() => { if (inputPanel) {
console.log('Succeed in destroying panel.'); inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel).then(() => {
}).catch((err) => { console.log('Succeed in destroying panel.');
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); }).catch((err: Error) => {
}); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
});
}
} catch (err) { } catch (err) {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
} }
...@@ -679,13 +691,13 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void ...@@ -679,13 +691,13 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent: inputMethodEngine.KeyEvent) => {
console.log('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); console.log('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode));
console.log('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); console.log('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction));
return true; return true;
}); });
inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent: inputMethodEngine.KeyEvent) => {
console.log('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); console.log('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode));
console.log('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); console.log('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction));
return true; return true;
...@@ -709,12 +721,12 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void ...@@ -709,12 +721,12 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent: inputMethodEngine.KeyEvent) => {
console.log('delete keyUp notification.'); console.log('delete keyUp notification.');
return true; return true;
}); });
inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent: inputMethodEngine.KeyEvent) => {
console.log('delete keyDown notification.'); console.log('delete keyDown notification.');
return true; return true;
}); });
...@@ -737,8 +749,8 @@ on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void ...@@ -737,8 +749,8 @@ on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().on('keyEvent', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().on('keyEvent', (keyEvent: InputKeyEvent) => {
console.log('inputMethodEngine keyEvent.action:' + JSON.stringify(keyEvent.action)); console.log('inputMethodEngine keyEvent.action:' + JSON.stringify(keyEvent.action));
console.log('inputMethodEngine keyEvent.key.code:' + JSON.stringify(keyEvent.key.code)); console.log('inputMethodEngine keyEvent.key.code:' + JSON.stringify(keyEvent.key.code));
console.log('inputMethodEngine keyEvent.ctrlKey:' + JSON.stringify(keyEvent.ctrlKey)); console.log('inputMethodEngine keyEvent.ctrlKey:' + JSON.stringify(keyEvent.ctrlKey));
...@@ -763,8 +775,8 @@ off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void ...@@ -763,8 +775,8 @@ off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent) => { inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent: InputKeyEvent) => {
console.log('This is a callback function which will be deregistered.'); console.log('This is a callback function which will be deregistered.');
return true; return true;
}); });
...@@ -788,8 +800,8 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) = ...@@ -788,8 +800,8 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) =
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => { inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x: number, y: number, height: number) => {
console.log('inputMethodEngine cursorContextChange x:' + x); console.log('inputMethodEngine cursorContextChange x:' + x);
console.log('inputMethodEngine cursorContextChange y:' + y); console.log('inputMethodEngine cursorContextChange y:' + y);
console.log('inputMethodEngine cursorContextChange height:' + height); console.log('inputMethodEngine cursorContextChange height:' + height);
...@@ -814,8 +826,8 @@ off(type: 'cursorContextChange', callback?: (x: number, y: number, height: numbe ...@@ -814,8 +826,8 @@ off(type: 'cursorContextChange', callback?: (x: number, y: number, height: numbe
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => { inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x: number, y: number, height: number) => {
console.log('delete cursorContextChange notification.'); console.log('delete cursorContextChange notification.');
}); });
``` ```
...@@ -836,13 +848,14 @@ on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegi ...@@ -836,13 +848,14 @@ on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegi
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { inputMethodEngine.getKeyboardDelegate()
console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin); .on('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => {
console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd); console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin);
console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin); console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd);
console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd); console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin);
}); console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd);
});
``` ```
### off('selectionChange') ### off('selectionChange')
...@@ -862,10 +875,11 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe ...@@ -862,10 +875,11 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { inputMethodEngine.getKeyboardDelegate()
console.log('delete selectionChange notification.'); .off('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => {
}); console.log('delete selectionChange notification.');
});
``` ```
...@@ -886,8 +900,8 @@ on(type: 'textChange', callback: (text: string) => void): void ...@@ -886,8 +900,8 @@ on(type: 'textChange', callback: (text: string) => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => { inputMethodEngine.getKeyboardDelegate().on('textChange', (text: string) => {
console.log('inputMethodEngine textChange. text:' + text); console.log('inputMethodEngine textChange. text:' + text);
}); });
``` ```
...@@ -909,8 +923,8 @@ off(type: 'textChange', callback?: (text: string) => void): void ...@@ -909,8 +923,8 @@ off(type: 'textChange', callback?: (text: string) => void): void
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => { inputMethodEngine.getKeyboardDelegate().off('textChange', (text: string) => {
console.log('delete textChange notification. text:' + text); console.log('delete textChange notification. text:' + text);
}); });
``` ```
...@@ -932,8 +946,8 @@ on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): v ...@@ -932,8 +946,8 @@ on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): v
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().on('editorAttributeChanged', (attr) => { inputMethodEngine.getKeyboardDelegate().on('editorAttributeChanged', (attr: inputMethodEngine.EditorAttribute) => {
console.log(`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`); console.log(`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`);
}); });
``` ```
...@@ -955,7 +969,7 @@ off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void): ...@@ -955,7 +969,7 @@ off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void):
**示例:** **示例:**
```js ```ts
inputMethodEngine.getKeyboardDelegate().off('editorAttributeChanged'); inputMethodEngine.getKeyboardDelegate().off('editorAttributeChanged');
``` ```
...@@ -980,9 +994,9 @@ setUiContent(path: string, callback: AsyncCallback\<void>): void ...@@ -980,9 +994,9 @@ setUiContent(path: string, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
try { try {
panel.setUiContent('pages/page2/page2', (err) => { panel.setUiContent('pages/page2/page2', (err: Error) => {
if (err) { if (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
return; return;
...@@ -1016,12 +1030,11 @@ setUiContent(path: string): Promise\<void> ...@@ -1016,12 +1030,11 @@ setUiContent(path: string): Promise\<void>
**示例:** **示例:**
```js ```ts
try { try {
let promise = panel.setUiContent('pages/page2/page2'); panel.setUiContent('pages/page2/page2').then(() => {
promise.then(() => {
console.log('Succeeded in setting the content.'); console.log('Succeeded in setting the content.');
}).catch((err) =>{ }).catch((err: Error) => {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1047,11 +1060,11 @@ setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void> ...@@ -1047,11 +1060,11 @@ setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>
**示例:** **示例:**
```js ```ts
let storage = new LocalStorage(); let storage = new LocalStorage();
storage.setOrCreate('storageSimpleProp',121); storage.setOrCreate('storageSimpleProp',121);
try { try {
panel.setUiContent('pages/page2/page2', storage, (err) => { panel.setUiContent('pages/page2/page2', storage, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
return; return;
...@@ -1086,14 +1099,13 @@ setUiContent(path: string, storage: LocalStorage): Promise\<void> ...@@ -1086,14 +1099,13 @@ setUiContent(path: string, storage: LocalStorage): Promise\<void>
**示例:** **示例:**
```js ```ts
let storage = new LocalStorage(); let storage = new LocalStorage();
storage.setOrCreate('storageSimpleProp',121); storage.setOrCreate('storageSimpleProp',121);
try { try {
let promise = panel.setUiContent('pages/page2/page2'); panel.setUiContent('pages/page2/page2')then(() => {
promise.then(() => {
console.log('Succeeded in setting the content.'); console.log('Succeeded in setting the content.');
}).catch((err) =>{ }).catch((err: Error) => {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1123,9 +1135,9 @@ resize(width: number, height: number, callback: AsyncCallback\<void>): void ...@@ -1123,9 +1135,9 @@ resize(width: number, height: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
try { try {
panel.resize(500, 1000, (err) => { panel.resize(500, 1000, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to resize panel: ${JSON.stringify(err)}`); console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1164,12 +1176,11 @@ resize(width: number, height: number): Promise\<void>; ...@@ -1164,12 +1176,11 @@ resize(width: number, height: number): Promise\<void>;
**示例:** **示例:**
```js ```ts
try { try {
let promise = panel.resize(500, 1000); panel.resize(500, 1000).then(() => {
promise.then(() => {
console.log('Succeeded in changing the panel size.'); console.log('Succeeded in changing the panel size.');
}).catch((err) =>{ }).catch((err: Error) => {
console.error(`Failed to resize panel: ${JSON.stringify(err)}`); console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1195,9 +1206,9 @@ moveTo(x: number, y: number, callback: AsyncCallback\<void>): void ...@@ -1195,9 +1206,9 @@ moveTo(x: number, y: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
try { try {
panel.moveTo(300, 300, (err) =>{ panel.moveTo(300, 300, (err: Error) =>{
if (err) { if (err) {
console.error(`Failed to move panel: ${JSON.stringify(err)}`); console.error(`Failed to move panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1232,12 +1243,11 @@ moveTo(x: number, y: number): Promise\<void> ...@@ -1232,12 +1243,11 @@ moveTo(x: number, y: number): Promise\<void>
**示例:** **示例:**
```js ```ts
try { try {
let promise = panel.moveTo(300, 300); panel.moveTo(300, 300).then(() => {
promise.then(() => {
console.log('Succeeded in moving the panel.'); console.log('Succeeded in moving the panel.');
}).catch((err) =>{ }).catch((err: Error) => {
console.error(`Failed to move panel: ${JSON.stringify(err)}`); console.error(`Failed to move panel: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1261,8 +1271,8 @@ show(callback: AsyncCallback\<void>): void ...@@ -1261,8 +1271,8 @@ show(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
panel.show((err) => { panel.show((err: Error) => {
if (err) { if (err) {
console.error(`Failed to show panel: ${JSON.stringify(err)}`); console.error(`Failed to show panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1287,11 +1297,10 @@ show(): Promise\<void> ...@@ -1287,11 +1297,10 @@ show(): Promise\<void>
**示例:** **示例:**
```js ```ts
let promise = panel.show(); panel.show().then(() => {
promise.then(() => {
console.log('Succeeded in showing the panel.'); console.log('Succeeded in showing the panel.');
}).catch((err) =>{ }).catch((err: Error) => {
console.error(`Failed to show panel: ${JSON.stringify(err)}`); console.error(`Failed to show panel: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1312,8 +1321,8 @@ hide(callback: AsyncCallback\<void>): void ...@@ -1312,8 +1321,8 @@ hide(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
panel.hide((err) => { panel.hide((err: Error) => {
if (err) { if (err) {
console.error(`Failed to hide panel: ${JSON.stringify(err)}`); console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1338,11 +1347,10 @@ hide(): Promise\<void> ...@@ -1338,11 +1347,10 @@ hide(): Promise\<void>
**示例:** **示例:**
```js ```ts
let promise = panel.hide(); panel.hide().then(() => {
promise.then(() => {
console.log('Succeeded in hiding the panel.'); console.log('Succeeded in hiding the panel.');
}).catch((err) =>{ }).catch((err: Error) => {
console.error(`Failed to hide panel: ${JSON.stringify(err)}`); console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1364,7 +1372,7 @@ on(type: 'show', callback: () => void): void ...@@ -1364,7 +1372,7 @@ on(type: 'show', callback: () => void): void
**示例:** **示例:**
```js ```ts
panel.on('show', () => { panel.on('show', () => {
console.log('Panel is showing.'); console.log('Panel is showing.');
}); });
...@@ -1387,7 +1395,7 @@ on(type: 'hide', callback: () => void): void ...@@ -1387,7 +1395,7 @@ on(type: 'hide', callback: () => void): void
**示例:** **示例:**
```js ```ts
panel.on('hide', () => { panel.on('hide', () => {
console.log('Panel is hiding.'); console.log('Panel is hiding.');
}); });
...@@ -1410,7 +1418,7 @@ off(type: 'show', callback?: () => void): void ...@@ -1410,7 +1418,7 @@ off(type: 'show', callback?: () => void): void
**示例:** **示例:**
```js ```ts
panel.off('show'); panel.off('show');
``` ```
...@@ -1431,7 +1439,7 @@ off(type: 'hide', callback?: () => void): void ...@@ -1431,7 +1439,7 @@ off(type: 'hide', callback?: () => void): void
**示例:** **示例:**
```js ```ts
panel.off('hide'); panel.off('hide');
``` ```
...@@ -1451,7 +1459,7 @@ changeFlag(flag: PanelFlag): void ...@@ -1451,7 +1459,7 @@ changeFlag(flag: PanelFlag): void
**示例:** **示例:**
```js ```ts
let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED; let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
panel.changeFlag(panelFlag); panel.changeFlag(panelFlag);
``` ```
...@@ -1484,8 +1492,8 @@ hide(callback: AsyncCallback&lt;void&gt;): void ...@@ -1484,8 +1492,8 @@ hide(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
keyboardController.hide((err) => { keyboardController.hide((err: Error) => {
if (err) { if (err) {
console.error(`Failed to hide: ${JSON.stringify(err)}`); console.error(`Failed to hide: ${JSON.stringify(err)}`);
return; return;
...@@ -1518,10 +1526,10 @@ hide(): Promise&lt;void&gt; ...@@ -1518,10 +1526,10 @@ hide(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
keyboardController.hide().then(() => { keyboardController.hide().then(() => {
console.log('Succeeded in hiding keyboard.'); console.log('Succeeded in hiding keyboard.');
}).catch((err) => { }).catch((err: Error) => {
console.log(`Failed to hide: ${JSON.stringify(err)}`); console.log(`Failed to hide: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1546,8 +1554,8 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -1546,8 +1554,8 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
keyboardController.hideKeyboard((err) => { keyboardController.hideKeyboard((err: Error) => {
if (err) { if (err) {
console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
return; return;
...@@ -1576,10 +1584,10 @@ hideKeyboard(): Promise&lt;void&gt; ...@@ -1576,10 +1584,10 @@ hideKeyboard(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
keyboardController.hideKeyboard().then(() => { keyboardController.hideKeyboard().then(() => {
console.log('Succeeded in hiding keyboard.'); console.log('Succeeded in hiding keyboard.');
}).catch((err) => { }).catch((err: Error) => {
console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1660,10 +1668,10 @@ sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1660,10 +1668,10 @@ sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
let action = 1; let action = 1;
try { try {
inputClient.sendKeyFunction(action, (err, result) => { inputClient.sendKeyFunction(action, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
return; return;
...@@ -1709,16 +1717,16 @@ sendKeyFunction(action: number): Promise&lt;boolean&gt; ...@@ -1709,16 +1717,16 @@ sendKeyFunction(action: number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let action = 1; let action = 1;
try { try {
inputClient.sendKeyFunction(action).then((result) => { inputClient.sendKeyFunction(action).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in sending key function.'); console.log('Succeeded in sending key function.');
} else { } else {
console.error('Failed to sendKeyFunction.'); console.error('Failed to sendKeyFunction.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1752,10 +1760,10 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -1752,10 +1760,10 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.getForward(length, (err, text) => { inputClient.getForward(length, (err: Error, text: string) => {
if (err) { if (err) {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
return; return;
...@@ -1798,12 +1806,12 @@ getForward(length:number): Promise&lt;string&gt; ...@@ -1798,12 +1806,12 @@ getForward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.getForward(length).then((text) => { inputClient.getForward(length).then((text: string) => {
console.log('Succeeded in getting forward, text: ' + text); console.log('Succeeded in getting forward, text: ' + text);
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1842,10 +1850,10 @@ getForwardSync(length:number): string ...@@ -1842,10 +1850,10 @@ getForwardSync(length:number): string
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
let text = inputClient.getForwardSync(length); let text: string = inputClient.getForwardSync(length);
console.log(`Succeeded in getting forward, text: ${text}`); console.log(`Succeeded in getting forward, text: ${text}`);
} catch (err) { } catch (err) {
console.error(`Failed to getForwardSync: ${JSON.stringify(err)}`); console.error(`Failed to getForwardSync: ${JSON.stringify(err)}`);
...@@ -1878,10 +1886,10 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -1878,10 +1886,10 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.getBackward(length, (err, text) => { inputClient.getBackward(length, (err: Error, text: string) => {
if (err) { if (err) {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -1924,12 +1932,12 @@ getBackward(length:number): Promise&lt;string&gt; ...@@ -1924,12 +1932,12 @@ getBackward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.getBackward(length).then((text) => { inputClient.getBackward(length).then((text: string) => {
console.log('Succeeded in getting backward, text: ' + text); console.log('Succeeded in getting backward, text: ' + text);
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1968,10 +1976,10 @@ getBackwardSync(length:number): string ...@@ -1968,10 +1976,10 @@ getBackwardSync(length:number): string
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
let text = inputClient.getBackwardSync(length); let text: string = inputClient.getBackwardSync(length);
console.log(`Succeeded in getting backward, text: ${text}`); console.log(`Succeeded in getting backward, text: ${text}`);
} catch (err) { } catch (err) {
console.error(`Failed to getBackwardSync: ${JSON.stringify(err)}`); console.error(`Failed to getBackwardSync: ${JSON.stringify(err)}`);
...@@ -2004,10 +2012,10 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2004,10 +2012,10 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.deleteForward(length, (err, result) => { inputClient.deleteForward(length, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
return; return;
...@@ -2054,16 +2062,16 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -2054,16 +2062,16 @@ deleteForward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.deleteForward(length).then((result) => { inputClient.deleteForward(length).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in deleting forward.'); console.log('Succeeded in deleting forward.');
} else { } else {
console.error('Failed to delete Forward.'); console.error('Failed to delete Forward.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2096,7 +2104,7 @@ deleteForwardSync(length:number): void ...@@ -2096,7 +2104,7 @@ deleteForwardSync(length:number): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.deleteForwardSync(length); inputClient.deleteForwardSync(length);
...@@ -2132,10 +2140,10 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2132,10 +2140,10 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.deleteBackward(length, (err, result) => { inputClient.deleteBackward(length, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -2182,15 +2190,15 @@ deleteBackward(length:number): Promise&lt;boolean&gt; ...@@ -2182,15 +2190,15 @@ deleteBackward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
inputClient.deleteBackward(length).then((result) => { inputClient.deleteBackward(length).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in deleting backward.'); console.log('Succeeded in deleting backward.');
} else { } else {
console.error('Failed to deleteBackward.'); console.error('Failed to deleteBackward.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -2220,7 +2228,7 @@ deleteBackwardSync(length:number): void ...@@ -2220,7 +2228,7 @@ deleteBackwardSync(length:number): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
try { try {
inputClient.deleteBackwardSync(length); inputClient.deleteBackwardSync(length);
...@@ -2256,8 +2264,8 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2256,8 +2264,8 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
inputClient.insertText('test', (err, result) => { inputClient.insertText('test', (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
return; return;
...@@ -2301,15 +2309,15 @@ insertText(text:string): Promise&lt;boolean&gt; ...@@ -2301,15 +2309,15 @@ insertText(text:string): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputClient.insertText('test').then((result) => { inputClient.insertText('test').then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in inserting text.'); console.log('Succeeded in inserting text.');
} else { } else {
console.error('Failed to insertText.'); console.error('Failed to insertText.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2342,7 +2350,7 @@ insertTextSync(text: string): void ...@@ -2342,7 +2350,7 @@ insertTextSync(text: string): void
**示例:** **示例:**
```js ```ts
try { try {
inputClient.insertTextSync('test'); inputClient.insertTextSync('test');
console.log('Succeeded in inserting text.'); console.log('Succeeded in inserting text.');
...@@ -2375,8 +2383,8 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void ...@@ -2375,8 +2383,8 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
**示例:** **示例:**
```js ```ts
inputClient.getEditorAttribute((err, editorAttribute) => { inputClient.getEditorAttribute((err: Error, editorAttribute: inputMethodEngine.EditorAttribute) => {
if (err) { if (err) {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
return; return;
...@@ -2410,11 +2418,11 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt; ...@@ -2410,11 +2418,11 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt;
**示例:** **示例:**
```js ```ts
inputClient.getEditorAttribute().then((editorAttribute) => { inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -2443,9 +2451,9 @@ getEditorAttributeSync(): EditorAttribute ...@@ -2443,9 +2451,9 @@ getEditorAttributeSync(): EditorAttribute
**示例:** **示例:**
```js ```ts
try { try {
let editorAttribute = inputClient.getEditorAttributeSync(); let editorAttribute: inputMethodEngine.EditorAttribute = inputClient.getEditorAttributeSync();
console.log(`Succeeded in getEditorAttributeSync, editorAttribute = ${JSON.stringify(editorAttribute)}`); console.log(`Succeeded in getEditorAttributeSync, editorAttribute = ${JSON.stringify(editorAttribute)}`);
} catch (err) { } catch (err) {
console.error(`Failed to getEditorAttributeSync: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttributeSync: ${JSON.stringify(err)}`);
...@@ -2477,9 +2485,9 @@ moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -2477,9 +2485,9 @@ moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
try { try {
inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
return; return;
...@@ -2521,11 +2529,11 @@ moveCursor(direction: number): Promise&lt;void&gt; ...@@ -2521,11 +2529,11 @@ moveCursor(direction: number): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => {
console.log('Succeeded in moving cursor.'); console.log('Succeeded in moving cursor.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2557,7 +2565,7 @@ moveCursorSync(direction: number): void ...@@ -2557,7 +2565,7 @@ moveCursorSync(direction: number): void
**示例:** **示例:**
```js ```ts
try { try {
inputClient.moveCursorSync(inputMethodEngine.Direction.CURSOR_UP); inputClient.moveCursorSync(inputMethodEngine.Direction.CURSOR_UP);
console.log('Succeeded in moving cursor.'); console.log('Succeeded in moving cursor.');
...@@ -2592,9 +2600,10 @@ selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void ...@@ -2592,9 +2600,10 @@ selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
try { try {
inputClient.selectByRange({start: 0, end: 1}, (err) => { let range: inputMethodEngine.Range = { start: 0, end: 1 };
inputClient.selectByRange(range, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
return; return;
...@@ -2637,11 +2646,12 @@ selectByRange(range: Range): Promise&lt;void&gt; ...@@ -2637,11 +2646,12 @@ selectByRange(range: Range): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputClient.selectByRange({start: 0, end:1}).then(() => { let range: inputMethodEngine.Range = { start: 0, end: 1 };
inputClient.selectByRange(range).then(() => {
console.log('Succeeded in selecting by range.'); console.log('Succeeded in selecting by range.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2674,9 +2684,10 @@ selectByRangeSync(range: Range): void ...@@ -2674,9 +2684,10 @@ selectByRangeSync(range: Range): void
**示例:** **示例:**
```js ```ts
try { try {
inputClient.selectByRangeSync({start: 0, end: 1}); let range: inputMethodEngine.Range = { start: 0, end: 1 };
inputClient.selectByRangeSync(range);
console.log('Succeeded in selecting by range.'); console.log('Succeeded in selecting by range.');
} catch (err) { } catch (err) {
console.error(`Failed to selectByRangeSync: ${JSON.stringify(err)}`); console.error(`Failed to selectByRangeSync: ${JSON.stringify(err)}`);
...@@ -2709,9 +2720,10 @@ selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void ...@@ -2709,9 +2720,10 @@ selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
try { try {
inputClient.selectByMovement({direction: 1}, (err) => { let movement: inputMethodEngine.Movement = { direction: 1 };
inputClient.selectByMovement(movement, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
return; return;
...@@ -2754,11 +2766,12 @@ selectByMovement(movement: Movement): Promise&lt;void&gt; ...@@ -2754,11 +2766,12 @@ selectByMovement(movement: Movement): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputClient.selectByMovement({direction: 1}).then(() => { let movement: inputMethodEngine.Movement = { direction: 1 };
inputClient.selectByMovement(movement).then(() => {
console.log('Succeeded in selecting by movement.'); console.log('Succeeded in selecting by movement.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2791,9 +2804,10 @@ selectByMovementSync(movement: Movement): void ...@@ -2791,9 +2804,10 @@ selectByMovementSync(movement: Movement): void
**示例:** **示例:**
```js ```ts
try { try {
inputClient.selectByMovementSync({direction: 1}); let movement: inputMethodEngine.Movement = { direction: 1 };
inputClient.selectByMovementSync(movement);
console.log('Succeeded in selecting by movement.'); console.log('Succeeded in selecting by movement.');
} catch (err) { } catch (err) {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
...@@ -2825,8 +2839,8 @@ getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void ...@@ -2825,8 +2839,8 @@ getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void
**示例:** **示例:**
```js ```ts
inputClient.getTextIndexAtCursor((err, index) => { inputClient.getTextIndexAtCursor((err: Error, index: number) => {
if (err) { if (err) {
console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
return; return;
...@@ -2860,10 +2874,10 @@ getTextIndexAtCursor(): Promise&lt;number&gt; ...@@ -2860,10 +2874,10 @@ getTextIndexAtCursor(): Promise&lt;number&gt;
**示例:** **示例:**
```js ```ts
inputClient.getTextIndexAtCursor().then((index) => { inputClient.getTextIndexAtCursor().then((index: number) => {
console.log('Succeeded in getTextIndexAtCursor: ' + index); console.log('Succeeded in getTextIndexAtCursor: ' + index);
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -2893,9 +2907,9 @@ getTextIndexAtCursorSync(): number ...@@ -2893,9 +2907,9 @@ getTextIndexAtCursorSync(): number
**示例:** **示例:**
```js ```ts
try{ try{
let index = inputClient.getTextIndexAtCursorSync(); let index: number = inputClient.getTextIndexAtCursorSync();
console.log(`Succeeded in getTextIndexAtCursorSync, index: ${index}`); console.log(`Succeeded in getTextIndexAtCursorSync, index: ${index}`);
} catch (err) { } catch (err) {
console.error(`Failed to getTextIndexAtCursorSync: ${JSON.stringify(err)}`); console.error(`Failed to getTextIndexAtCursorSync: ${JSON.stringify(err)}`);
...@@ -2932,9 +2946,9 @@ sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): voi ...@@ -2932,9 +2946,9 @@ sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): voi
**示例:** **示例:**
```js ```ts
try { try {
inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err) => { inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: Error) => {
if (err) { if (err) {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
return; return;
...@@ -2981,11 +2995,11 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt; ...@@ -2981,11 +2995,11 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
try { try {
inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => { inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => {
console.log('Succeeded in sending extend action.'); console.log('Succeeded in sending extend action.');
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
}); });
} catch(err) { } catch(err) {
...@@ -3077,9 +3091,9 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -3077,9 +3091,9 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.getForward(length, (err, text) => { textInputClient.getForward(length, (err: Error, text: string) => {
if (err) { if (err) {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
return; return;
...@@ -3114,11 +3128,11 @@ getForward(length:number): Promise&lt;string&gt; ...@@ -3114,11 +3128,11 @@ getForward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.getForward(length).then((text) => { textInputClient.getForward(length).then((text: string) => {
console.log('Succeeded in getting forward, text: ' + text); console.log('Succeeded in getting forward, text: ' + text);
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3144,9 +3158,9 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -3144,9 +3158,9 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.getBackward(length, (err, text) => { textInputClient.getBackward(length, (err: Error, text: string) => {
if (err) { if (err) {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -3181,11 +3195,11 @@ getBackward(length:number): Promise&lt;string&gt; ...@@ -3181,11 +3195,11 @@ getBackward(length:number): Promise&lt;string&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.getBackward(length).then((text) => { textInputClient.getBackward(length).then((text: string) => {
console.log('Succeeded in getting backward: ' + JSON.stringify(text)); console.log('Succeeded in getting backward: ' + JSON.stringify(text));
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3211,9 +3225,9 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3211,9 +3225,9 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.deleteForward(length, (err, result) => { textInputClient.deleteForward(length, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
return; return;
...@@ -3252,15 +3266,15 @@ deleteForward(length:number): Promise&lt;boolean&gt; ...@@ -3252,15 +3266,15 @@ deleteForward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.deleteForward(length).then((result) => { textInputClient.deleteForward(length).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in deleting forward.'); console.log('Succeeded in deleting forward.');
} else { } else {
console.error('Failed to delete forward.'); console.error('Failed to delete forward.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3286,9 +3300,9 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3286,9 +3300,9 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.deleteBackward(length, (err, result) => { textInputClient.deleteBackward(length, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -3327,15 +3341,15 @@ deleteBackward(length:number): Promise&lt;boolean&gt; ...@@ -3327,15 +3341,15 @@ deleteBackward(length:number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let length = 1; let length = 1;
textInputClient.deleteBackward(length).then((result) => { textInputClient.deleteBackward(length).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in deleting backward.'); console.log('Succeeded in deleting backward.');
} else { } else {
console.error('Failed to deleteBackward.'); console.error('Failed to deleteBackward.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3360,9 +3374,9 @@ sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3360,9 +3374,9 @@ sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
let action = 1; let action = 1;
textInputClient.sendKeyFunction(action, (err, result) => { textInputClient.sendKeyFunction(action, (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
return; return;
...@@ -3401,15 +3415,15 @@ sendKeyFunction(action: number): Promise&lt;boolean&gt; ...@@ -3401,15 +3415,15 @@ sendKeyFunction(action: number): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let action = 1; let action = 1;
textInputClient.sendKeyFunction(action).then((result) => { textInputClient.sendKeyFunction(action).then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in sending key function.'); console.log('Succeeded in sending key function.');
} else { } else {
console.error('Failed to sendKeyFunction.'); console.error('Failed to sendKeyFunction.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3435,8 +3449,8 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3435,8 +3449,8 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
textInputClient.insertText('test', (err, result) => { textInputClient.insertText('test', (err: Error, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
return; return;
...@@ -3475,14 +3489,14 @@ insertText(text:string): Promise&lt;boolean&gt; ...@@ -3475,14 +3489,14 @@ insertText(text:string): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
textInputClient.insertText('test').then((result) => { textInputClient.insertText('test').then((result: boolean) => {
if (result) { if (result) {
console.log('Succeeded in inserting text.'); console.log('Succeeded in inserting text.');
} else { } else {
console.error('Failed to insertText.'); console.error('Failed to insertText.');
} }
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3507,8 +3521,8 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void ...@@ -3507,8 +3521,8 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
**示例:** **示例:**
```js ```ts
textInputClient.getEditorAttribute((err, editorAttribute) => { textInputClient.getEditorAttribute((err: Error, editorAttribute: inputMethodEngine.EditorAttribute) => {
if (err) { if (err) {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
return; return;
...@@ -3538,11 +3552,11 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt; ...@@ -3538,11 +3552,11 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt;
**示例:** **示例:**
```js ```ts
textInputClient.getEditorAttribute().then((editorAttribute) => { textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
}).catch((err) => { }).catch((err: Error) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册