Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
7a5df94c
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7a5df94c
编写于
2月 23, 2021
作者:
L
LongCatIsLooong
提交者:
GitHub
2月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Passthrough movement keys when theres no selection (#24581)
上级
90618237
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
106 addition
and
55 deletion
+106
-55
shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java
...ter/embedding/engine/systemchannels/TextInputChannel.java
+6
-0
shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java
...oid/io/flutter/plugin/editing/InputConnectionAdaptor.java
+67
-54
shell/platform/android/io/flutter/plugin/editing/ListenableEditingState.java
...oid/io/flutter/plugin/editing/ListenableEditingState.java
+1
-1
shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java
...io/flutter/plugin/editing/InputConnectionAdaptorTest.java
+32
-0
未找到文件。
shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java
浏览文件 @
7a5df94c
...
...
@@ -735,5 +735,11 @@ public class TextInputChannel {
this
.
composingStart
=
composingStart
;
this
.
composingEnd
=
composingEnd
;
}
public
boolean
hasSelection
()
{
// When selectionStart == -1, it's guaranteed that selectionEnd will also
// be -1.
return
selectionStart
>=
0
;
}
}
}
shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java
浏览文件 @
7a5df94c
...
...
@@ -306,57 +306,13 @@ class InputConnectionAdaptor extends BaseInputConnection
if
(
event
.
getAction
()
==
KeyEvent
.
ACTION_DOWN
)
{
if
(
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_DPAD_LEFT
)
{
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
if
(
selStart
==
selEnd
&&
!
event
.
isShiftPressed
())
{
int
newSel
=
Math
.
max
(
flutterTextUtils
.
getOffsetBefore
(
mEditable
,
selStart
),
0
);
setSelection
(
newSel
,
newSel
);
}
else
{
int
newSelEnd
=
Math
.
max
(
flutterTextUtils
.
getOffsetBefore
(
mEditable
,
selEnd
),
0
);
setSelection
(
selStart
,
newSelEnd
);
}
return
true
;
return
handleHorizontalMovement
(
true
,
event
.
isShiftPressed
());
}
else
if
(
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_DPAD_RIGHT
)
{
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
if
(
selStart
==
selEnd
&&
!
event
.
isShiftPressed
())
{
int
newSel
=
Math
.
min
(
flutterTextUtils
.
getOffsetAfter
(
mEditable
,
selStart
),
mEditable
.
length
());
setSelection
(
newSel
,
newSel
);
}
else
{
int
newSelEnd
=
Math
.
min
(
flutterTextUtils
.
getOffsetAfter
(
mEditable
,
selEnd
),
mEditable
.
length
());
setSelection
(
selStart
,
newSelEnd
);
}
return
true
;
return
handleHorizontalMovement
(
false
,
event
.
isShiftPressed
());
}
else
if
(
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_DPAD_UP
)
{
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
if
(
selStart
==
selEnd
&&
!
event
.
isShiftPressed
())
{
Selection
.
moveUp
(
mEditable
,
mLayout
);
int
newSelStart
=
Selection
.
getSelectionStart
(
mEditable
);
setSelection
(
newSelStart
,
newSelStart
);
}
else
{
Selection
.
extendUp
(
mEditable
,
mLayout
);
int
newSelStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
newSelEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
setSelection
(
newSelStart
,
newSelEnd
);
}
return
true
;
return
handleVerticalMovement
(
true
,
event
.
isShiftPressed
());
}
else
if
(
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_DPAD_DOWN
)
{
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
if
(
selStart
==
selEnd
&&
!
event
.
isShiftPressed
())
{
Selection
.
moveDown
(
mEditable
,
mLayout
);
int
newSelStart
=
Selection
.
getSelectionStart
(
mEditable
);
setSelection
(
newSelStart
,
newSelStart
);
}
else
{
Selection
.
extendDown
(
mEditable
,
mLayout
);
int
newSelStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
newSelEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
setSelection
(
newSelStart
,
newSelEnd
);
}
return
true
;
return
handleVerticalMovement
(
false
,
event
.
isShiftPressed
());
// When the enter key is pressed on a non-multiline field, consider it a
// submit instead of a newline.
}
else
if
((
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_ENTER
...
...
@@ -366,17 +322,20 @@ class InputConnectionAdaptor extends BaseInputConnection
return
true
;
}
else
{
// Enter a character.
int
character
=
event
.
getUnicodeChar
();
if
(
character
==
0
)
{
final
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
final
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
final
int
character
=
event
.
getUnicodeChar
();
if
(
selStart
<
0
||
selEnd
<
0
||
character
==
0
)
{
return
false
;
}
int
selStart
=
Math
.
max
(
0
,
Selection
.
getSelectionStart
(
mEditable
));
int
selEnd
=
Math
.
max
(
0
,
Selection
.
getSelectionEnd
(
mEditable
)
);
int
selMin
=
Math
.
min
(
selStart
,
selEnd
);
int
selMax
=
Math
.
max
(
selStart
,
selEnd
);
final
int
selMin
=
Math
.
min
(
selStart
,
selEnd
);
final
int
selMax
=
Math
.
max
(
selStart
,
selEnd
);
beginBatchEdit
(
);
if
(
selMin
!=
selMax
)
mEditable
.
delete
(
selMin
,
selMax
);
mEditable
.
insert
(
selMin
,
String
.
valueOf
((
char
)
character
));
setSelection
(
selMin
+
1
,
selMin
+
1
);
endBatchEdit
();
return
true
;
}
}
...
...
@@ -390,6 +349,60 @@ class InputConnectionAdaptor extends BaseInputConnection
return
false
;
}
private
boolean
handleHorizontalMovement
(
boolean
isLeft
,
boolean
isShiftPressed
)
{
final
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
final
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
if
(
selStart
<
0
||
selEnd
<
0
)
{
return
false
;
}
final
int
newSelectionEnd
=
isLeft
?
Math
.
max
(
flutterTextUtils
.
getOffsetBefore
(
mEditable
,
selEnd
),
0
)
:
Math
.
min
(
flutterTextUtils
.
getOffsetAfter
(
mEditable
,
selEnd
),
mEditable
.
length
());
final
boolean
shouldCollapse
=
selStart
==
selEnd
&&
!
isShiftPressed
;
if
(
shouldCollapse
)
{
setSelection
(
newSelectionEnd
,
newSelectionEnd
);
}
else
{
setSelection
(
selStart
,
newSelectionEnd
);
}
return
true
;
};
private
boolean
handleVerticalMovement
(
boolean
isUp
,
boolean
isShiftPressed
)
{
final
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
final
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
if
(
selStart
<
0
||
selEnd
<
0
)
{
return
false
;
}
final
boolean
shouldCollapse
=
selStart
==
selEnd
&&
!
isShiftPressed
;
beginBatchEdit
();
if
(
shouldCollapse
)
{
if
(
isUp
)
{
Selection
.
moveUp
(
mEditable
,
mLayout
);
}
else
{
Selection
.
moveDown
(
mEditable
,
mLayout
);
}
final
int
newSelection
=
Selection
.
getSelectionStart
(
mEditable
);
setSelection
(
newSelection
,
newSelection
);
}
else
{
if
(
isUp
)
{
Selection
.
extendUp
(
mEditable
,
mLayout
);
}
else
{
Selection
.
extendDown
(
mEditable
,
mLayout
);
}
setSelection
(
Selection
.
getSelectionStart
(
mEditable
),
Selection
.
getSelectionEnd
(
mEditable
));
}
endBatchEdit
();
return
true
;
}
@Override
public
boolean
performContextMenuAction
(
int
id
)
{
beginBatchEdit
();
...
...
shell/platform/android/io/flutter/plugin/editing/ListenableEditingState.java
浏览文件 @
7a5df94c
...
...
@@ -137,7 +137,7 @@ class ListenableEditingState extends SpannableStringBuilder {
beginBatchEdit
();
replace
(
0
,
length
(),
newState
.
text
);
if
(
newState
.
selectionStart
>=
0
)
{
if
(
newState
.
hasSelection
()
)
{
Selection
.
setSelection
(
this
,
newState
.
selectionStart
,
newState
.
selectionEnd
);
}
else
{
Selection
.
removeSelection
(
this
);
...
...
shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java
浏览文件 @
7a5df94c
...
...
@@ -84,6 +84,7 @@ public class InputConnectionAdaptorTest {
TextInputChannel
textInputChannel
=
new
TextInputChannel
(
dartExecutor
);
AndroidKeyProcessor
mockKeyProcessor
=
mock
(
AndroidKeyProcessor
.
class
);
ListenableEditingState
mEditable
=
new
ListenableEditingState
(
null
,
testView
);
Selection
.
setSelection
(
mEditable
,
0
,
0
);
ListenableEditingState
spyEditable
=
spy
(
mEditable
);
EditorInfo
outAttrs
=
new
EditorInfo
();
outAttrs
.
inputType
=
InputType
.
TYPE_CLASS_TEXT
|
InputType
.
TYPE_TEXT_FLAG_MULTI_LINE
;
...
...
@@ -911,6 +912,37 @@ public class InputConnectionAdaptorTest {
assertTrue
(
Selection
.
getSelectionStart
(
editable
)
>
selStart
);
}
@Test
public
void
testSendKeyEvent_MovementKeysAreNopWhenNoSelection
()
{
// Regression test for https://github.com/flutter/flutter/issues/76283.
ListenableEditingState
editable
=
sampleEditable
(-
1
,
-
1
);
InputConnectionAdaptor
adaptor
=
sampleInputConnectionAdaptor
(
editable
);
KeyEvent
keyEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
KeyEvent
.
KEYCODE_DPAD_DOWN
);
boolean
didConsume
=
adaptor
.
sendKeyEvent
(
keyEvent
);
assertFalse
(
didConsume
);
assertEquals
(
Selection
.
getSelectionStart
(
editable
),
-
1
);
assertEquals
(
Selection
.
getSelectionEnd
(
editable
),
-
1
);
keyEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
KeyEvent
.
KEYCODE_DPAD_UP
);
didConsume
=
adaptor
.
sendKeyEvent
(
keyEvent
);
assertFalse
(
didConsume
);
assertEquals
(
Selection
.
getSelectionStart
(
editable
),
-
1
);
assertEquals
(
Selection
.
getSelectionEnd
(
editable
),
-
1
);
keyEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
KeyEvent
.
KEYCODE_DPAD_LEFT
);
didConsume
=
adaptor
.
sendKeyEvent
(
keyEvent
);
assertFalse
(
didConsume
);
assertEquals
(
Selection
.
getSelectionStart
(
editable
),
-
1
);
assertEquals
(
Selection
.
getSelectionEnd
(
editable
),
-
1
);
keyEvent
=
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
KeyEvent
.
KEYCODE_DPAD_RIGHT
);
didConsume
=
adaptor
.
sendKeyEvent
(
keyEvent
);
assertFalse
(
didConsume
);
assertEquals
(
Selection
.
getSelectionStart
(
editable
),
-
1
);
assertEquals
(
Selection
.
getSelectionEnd
(
editable
),
-
1
);
}
@Test
public
void
testMethod_getExtractedText
()
{
int
selStart
=
5
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录