From a59ae69e079a603811296abc591270070ce9ce28 Mon Sep 17 00:00:00 2001 From: asklie <760956257@qq.com> Date: Fri, 25 Oct 2024 16:25:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=A1=86=E6=97=A0=E6=B3=95=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: asklie <760956257@qq.com> --- .../systemchannels/TextInputChannel.ets | 96 ++++++++++++++----- .../ets/plugin/editing/TextInputPlugin.ets | 4 + 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index eb6eb64f59..4e116d44bb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -23,6 +23,8 @@ import inputMethod from '@ohos.inputMethod'; import ArrayList from '@ohos.util.ArrayList'; import { TextEditingDelta, TextEditingDeltaJson } from '../../../plugin/editing/TextEditingDelta'; import Any from '../../../plugin/common/Any'; +import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; const TAG = "TextInputChannel"; /// 规避换行标识无法显示问题,api修改后再删除 @@ -47,10 +49,10 @@ export default class TextInputChannel { } createEditingStateJSON(text: string, - selectionStart: number, - selectionEnd: number, - composingStart: number, - composingEnd: number): EditingState { + selectionStart: number, + selectionEnd: number, + composingStart: number, + composingEnd: number): EditingState { let state: EditingState = { text: text, selectionBase: selectionStart, @@ -77,11 +79,11 @@ export default class TextInputChannel { * Instructs Flutter to update its text input editing state to reflect the given configuration. */ updateEditingState(inputClientId: number, - text: string, - selectionStart: number, - selectionEnd: number, - composingStart: number, - composingEnd: number): void { + text: string, + selectionStart: number, + selectionEnd: number, + composingStart: number, + composingEnd: number): void { Log.d(TAG, "updateEditingState:" + "Text: " + text + " Selection start: " + selectionStart + " Selection end: " + selectionEnd + " Composing start: " + composingStart + " Composing end: " + composingEnd); @@ -178,6 +180,8 @@ export interface TextInputMethodHandler { setEditableSizeAndTransform(width: number, height: number, transform: number[]): void; + setCursorSizeAndPosition(cursorInfo: inputMethod.CursorInfo): void; + setEditingState(editingState: TextEditState): void; clearClient(): void; @@ -201,17 +205,17 @@ export class Configuration { fields: Configuration[] = []; constructor(obscureText: boolean, - autocorrect: boolean, - enableSuggestions: boolean, - enableIMEPersonalizedLearning: boolean, - enableDeltaModel: boolean, - textCapitalization: TextCapitalization, - inputType: InputType, - inputAction: Number, - actionLabel: String, - autofill: boolean, - contentListString: [], - fields: Configuration[] + autocorrect: boolean, + enableSuggestions: boolean, + enableIMEPersonalizedLearning: boolean, + enableDeltaModel: boolean, + textCapitalization: TextCapitalization, + inputType: InputType, + inputAction: Number, + actionLabel: String, + autofill: boolean, + contentListString: [], + fields: Configuration[] ) { this.obscureText = obscureText; this.autocorrect = autocorrect; @@ -358,10 +362,10 @@ export class TextEditState { composingEnd: number; constructor(text: string, - selectionStart: number, - selectionEnd: number, - composingStart: number, - composingEnd: number) { + selectionStart: number, + selectionEnd: number, + composingStart: number, + composingEnd: number) { if ((selectionStart != -1 || selectionEnd != -1) && (selectionStart < 0 || selectionEnd < 0)) { throw new Error("invalid selection: (" + selectionStart + ", " + selectionEnd + ")"); @@ -422,11 +426,49 @@ export class TextEditState { } } +export interface offsetRect { + left: number; + top: number; + width: number; + height: number; +} + class TextInputCallback implements MethodCallHandler { textInputMethodHandler: TextInputMethodHandler; + windowPosition: offsetRect = { + left: 0, + top: 0, + width: 0, + height: 0, + }; + cursorPosition: offsetRect = { + left: 0, + top: 0, + width: 0, + height: 0, + } constructor(handler: TextInputMethodHandler) { this.textInputMethodHandler = handler; + const context = getContext(this) as Context + window.getLastWindow(context, (err: BusinessError, data) => { + this.windowPosition = data.getWindowProperties().windowRect; + data.on('windowRectChange', (rect) => { + this.windowPosition = rect.rect; + this.setCursorPosition(); + }) + }) + } + + setCursorPosition() { + const left = (this.windowPosition.left as number) + this.cursorPosition.left; + const top = (this.windowPosition.top as number) + this.cursorPosition.top; + this.textInputMethodHandler.setCursorSizeAndPosition({ + left: left, + top: top, + width: 100, + height: 50, + }) } onMethodCall(call: MethodCall, result: MethodResult) { @@ -482,6 +524,12 @@ class TextInputCallback implements MethodCallHandler { //TODO: result.notImplemented(); break; + case "TextInput.setCursorPotion": + let cursorPosition: offsetRect = args[0]; + this.cursorPosition = cursorPosition; + this.setCursorPosition(); + result.success(null); + break; default: result.notImplemented(); break; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 8c75488d7a..e120dfeedb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -131,6 +131,10 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } + setCursorSizeAndPosition(cursorInfo: inputMethod.CursorInfo) { + this.inputMethodController.updateCursor(cursorInfo) + } + setEditingState(editingState: TextEditState): void { Log.d(TextInputMethodHandlerImpl.TAG, "text:" + editingState.text + " selectionStart:" + editingState.selectionStart + " selectionEnd:" -- Gitee From 7efe5926821f2b97b257a78905c2250e688e64b1 Mon Sep 17 00:00:00 2001 From: asklie <760956257@qq.com> Date: Fri, 25 Oct 2024 19:51:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: asklie <760956257@qq.com> --- .../engine/systemchannels/TextInputChannel.ets | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index 4e116d44bb..04458a1334 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -24,7 +24,8 @@ import ArrayList from '@ohos.util.ArrayList'; import { TextEditingDelta, TextEditingDeltaJson } from '../../../plugin/editing/TextEditingDelta'; import Any from '../../../plugin/common/Any'; import { window } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; +import { BusinessError, print } from '@kit.BasicServicesKit'; +import { Rect } from '@kit.ArkGraphics3D'; const TAG = "TextInputChannel"; /// 规避换行标识无法显示问题,api修改后再删除 @@ -186,8 +187,6 @@ export interface TextInputMethodHandler { clearClient(): void; - handleChangeFocus(focusState: boolean): void; - } export class Configuration { @@ -451,9 +450,9 @@ class TextInputCallback implements MethodCallHandler { constructor(handler: TextInputMethodHandler) { this.textInputMethodHandler = handler; const context = getContext(this) as Context - window.getLastWindow(context, (err: BusinessError, data) => { + window.getLastWindow(context, (err: BusinessError, data: window.Window) => { this.windowPosition = data.getWindowProperties().windowRect; - data.on('windowRectChange', (rect) => { + data.on('windowRectChange', (rect: window.RectChangeOptions) => { this.windowPosition = rect.rect; this.setCursorPosition(); }) @@ -521,7 +520,6 @@ class TextInputCallback implements MethodCallHandler { result.notImplemented(); break; case "TextInput.finishAutofillContext": - //TODO: result.notImplemented(); break; case "TextInput.setCursorPotion": -- Gitee From 8fd9ea592a13b89835587f3e60824d385c9434d5 Mon Sep 17 00:00:00 2001 From: asklie <760956257@qq.com> Date: Sat, 26 Oct 2024 09:32:02 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: asklie <760956257@qq.com> --- .../ets/embedding/engine/systemchannels/TextInputChannel.ets | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index 04458a1334..ceacf9c596 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -187,6 +187,8 @@ export interface TextInputMethodHandler { clearClient(): void; + handleChangeFocus(focusState: boolean): void; + } export class Configuration { @@ -520,6 +522,7 @@ class TextInputCallback implements MethodCallHandler { result.notImplemented(); break; case "TextInput.finishAutofillContext": + //TODO: result.notImplemented(); break; case "TextInput.setCursorPotion": -- Gitee From 75e70872a7257249e3d1ff0c6e9bc11d223b6cdd Mon Sep 17 00:00:00 2001 From: asklie <760956257@qq.com> Date: Sat, 26 Oct 2024 11:08:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: asklie <760956257@qq.com> --- .../engine/systemchannels/TextInputChannel.ets | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index ceacf9c596..454a589053 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -427,22 +427,15 @@ export class TextEditState { } } -export interface offsetRect { - left: number; - top: number; - width: number; - height: number; -} - class TextInputCallback implements MethodCallHandler { textInputMethodHandler: TextInputMethodHandler; - windowPosition: offsetRect = { + windowPosition: window.Rect = { left: 0, top: 0, width: 0, height: 0, }; - cursorPosition: offsetRect = { + cursorPosition: window.Rect = { left: 0, top: 0, width: 0, @@ -453,9 +446,9 @@ class TextInputCallback implements MethodCallHandler { this.textInputMethodHandler = handler; const context = getContext(this) as Context window.getLastWindow(context, (err: BusinessError, data: window.Window) => { - this.windowPosition = data.getWindowProperties().windowRect; + this.windowPosition = data.getWindowProperties().windowRect as window.Rect; data.on('windowRectChange', (rect: window.RectChangeOptions) => { - this.windowPosition = rect.rect; + this.windowPosition = rect.rect as window.Rect; this.setCursorPosition(); }) }) @@ -526,7 +519,7 @@ class TextInputCallback implements MethodCallHandler { result.notImplemented(); break; case "TextInput.setCursorPotion": - let cursorPosition: offsetRect = args[0]; + let cursorPosition: window.Rect = args[0]; this.cursorPosition = cursorPosition; this.setCursorPosition(); result.success(null); -- Gitee