Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
9159b995
Commit
9159b995
authored
13 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
Fix the auto-composer to support supplementary chars
Change-Id: I61ff218ae2ca4eb443a370e581b677755258670a
parent
8174373a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/latin/WordComposer.java
+22
-13
22 additions, 13 deletions
java/src/com/android/inputmethod/latin/WordComposer.java
tests/src/com/android/inputmethod/latin/InputLogicTests.java
+19
-2
19 additions, 2 deletions
tests/src/com/android/inputmethod/latin/InputLogicTests.java
with
41 additions
and
15 deletions
java/src/com/android/inputmethod/latin/WordComposer.java
+
22
−
13
View file @
9159b995
...
...
@@ -90,11 +90,11 @@ public class WordComposer {
* @return the number of keystrokes
*/
public
final
int
size
()
{
return
m
TypedWord
.
length
();
return
m
Codes
.
size
();
}
public
final
boolean
isComposingWord
()
{
return
size
()
>
0
;
return
mCodes
.
size
()
>
0
;
}
/**
...
...
@@ -125,8 +125,8 @@ public class WordComposer {
* @param codes the array of unicode values
*/
public
void
add
(
int
primaryCode
,
int
[]
codes
,
int
x
,
int
y
)
{
final
int
newIndex
=
size
();
mTypedWord
.
append
((
char
)
primaryCode
);
final
int
newIndex
=
mCodes
.
size
();
mTypedWord
.
append
CodePoint
(
primaryCode
);
correctPrimaryJuxtapos
(
primaryCode
,
codes
);
mCodes
.
add
(
codes
);
if
(
newIndex
<
BinaryDictionary
.
MAX_WORD_LENGTH
)
{
...
...
@@ -171,8 +171,8 @@ public class WordComposer {
final
KeyDetector
keyDetector
)
{
reset
();
final
int
length
=
word
.
length
();
for
(
int
i
=
0
;
i
<
length
;
++
i
)
{
int
codePoint
=
word
.
charAt
(
i
);
for
(
int
i
=
0
;
i
<
length
;
i
=
Character
.
offsetByCodePoints
(
word
,
i
,
1
)
)
{
int
codePoint
=
Character
.
codePointAt
(
word
,
i
);
addKeyInfo
(
codePoint
,
keyboard
,
keyDetector
);
}
}
...
...
@@ -207,16 +207,25 @@ public class WordComposer {
* Delete the last keystroke as a result of hitting backspace.
*/
public
void
deleteLast
()
{
final
int
size
=
size
();
final
int
size
=
mCodes
.
size
();
if
(
size
>
0
)
{
final
int
lastPos
=
size
-
1
;
char
lastChar
=
mTypedWord
.
charAt
(
lastPos
);
mCodes
.
remove
(
lastPos
);
// TODO: This crashes and catches fire if the code point doesn't fit a char
mTypedWord
.
deleteCharAt
(
lastPos
);
mCodes
.
remove
(
size
-
1
);
// Note: mTypedWord.length() and mCodes.length differ when there are surrogate pairs
final
int
stringBuilderLength
=
mTypedWord
.
length
();
if
(
stringBuilderLength
<
size
)
{
throw
new
RuntimeException
(
"In WordComposer: mCodes and mTypedWords have non-matching lengths"
);
}
final
int
lastChar
=
mTypedWord
.
codePointBefore
(
stringBuilderLength
);
if
(
Character
.
isSupplementaryCodePoint
(
lastChar
))
{
mTypedWord
.
delete
(
stringBuilderLength
-
2
,
stringBuilderLength
);
}
else
{
mTypedWord
.
deleteCharAt
(
stringBuilderLength
-
1
);
}
if
(
Character
.
isUpperCase
(
lastChar
))
mCapsCount
--;
}
if
(
size
()
==
0
)
{
// We may have deleted the last one.
if
(
0
==
mCodes
.
size
())
{
mIsFirstCharCapitalized
=
false
;
}
if
(
mTrailingSingleQuotesCount
>
0
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/src/com/android/inputmethod/latin/InputLogicTests.java
+
19
−
2
View file @
9159b995
...
...
@@ -159,11 +159,26 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
}
public
void
testPickSuggestionThenBackspace
()
{
final
String
WORD_TO_TYPE
=
"tgis"
;
final
String
WORD_TO_TYPE
=
"this"
;
final
String
EXPECTED_RESULT
=
"this"
;
type
(
WORD_TO_TYPE
);
mLatinIME
.
pickSuggestionManually
(
0
,
WORD_TO_TYPE
);
mLatinIME
.
onUpdateSelection
(
0
,
0
,
WORD_TO_TYPE
.
length
(),
WORD_TO_TYPE
.
length
(),
-
1
,
-
1
);
type
(
Keyboard
.
CODE_DELETE
);
assertEquals
(
"press suggestion then backspace"
,
WORD_TO_TYPE
,
assertEquals
(
"press suggestion then backspace"
,
EXPECTED_RESULT
,
mTextView
.
getText
().
toString
());
}
public
void
testPickTypedWordOverAutoCorrectionThenBackspace
()
{
final
String
WORD_TO_TYPE
=
"tgis"
;
final
String
EXPECTED_RESULT
=
"tgis"
;
type
(
WORD_TO_TYPE
);
// Choose the typed word, which should be in position 1 (because position 0 should
// be occupied by the "this" auto-correction, as checked by testAutoCorrect())
mLatinIME
.
pickSuggestionManually
(
1
,
WORD_TO_TYPE
);
mLatinIME
.
onUpdateSelection
(
0
,
0
,
WORD_TO_TYPE
.
length
(),
WORD_TO_TYPE
.
length
(),
-
1
,
-
1
);
type
(
Keyboard
.
CODE_DELETE
);
assertEquals
(
"pick typed word over auto-correction then backspace"
,
EXPECTED_RESULT
,
mTextView
.
getText
().
toString
());
}
...
...
@@ -379,4 +394,6 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
assertEquals
(
"type word type dot then press the .com key"
,
EXPECTED_RESULT
,
mTextView
.
getText
().
toString
());
}
// TODO: Add some tests for non-BMP characters
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment