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