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
a3f7a584
Commit
a3f7a584
authored
10 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
Don't commit a space before it's actually needed
Bug: 15740318 Change-Id: Idad06cb2c18335a981d5e9dea7eccf5e7ea8f701
parent
53f23234
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+57
-54
57 additions, 54 deletions
.../com/android/inputmethod/latin/inputlogic/InputLogic.java
with
57 additions
and
54 deletions
java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+
57
−
54
View file @
a3f7a584
...
@@ -728,13 +728,13 @@ public final class InputLogic {
...
@@ -728,13 +728,13 @@ public final class InputLogic {
mConnection
.
setComposingText
(
getTextWithUnderline
(
mConnection
.
setComposingText
(
getTextWithUnderline
(
mWordComposer
.
getTypedWord
()),
1
);
mWordComposer
.
getTypedWord
()),
1
);
}
else
{
}
else
{
final
boolean
swapWeakSpace
=
maybe
StripSpace
(
inputTransaction
,
final
boolean
swapWeakSpace
=
try
StripSpace
AndReturnWhetherShouldSwapInstead
(
inputTransaction
.
mEvent
.
isSuggestionStripPress
());
inputTransaction
,
inputTransaction
.
mEvent
.
isSuggestionStripPress
());
sendKeyCodePoint
(
settingsValues
,
codePoint
);
if
(
swapWeakSpace
&&
trySwapSwapperAndSpace
(
inputTransaction
))
{
if
(
swapWeakSpace
&&
swapSwapperAndSpace
(
inputTransaction
))
{
mSpaceState
=
SpaceState
.
WEAK
;
mSpaceState
=
SpaceState
.
WEAK
;
}
else
{
sendKeyCodePoint
(
settingsValues
,
codePoint
);
}
}
// In case the "add to dictionary" hint was still displayed.
// In case the "add to dictionary" hint was still displayed.
mSuggestionStripViewAccessor
.
dismissAddToDictionaryHint
();
mSuggestionStripViewAccessor
.
dismissAddToDictionaryHint
();
...
@@ -779,7 +779,8 @@ public final class InputLogic {
...
@@ -779,7 +779,8 @@ public final class InputLogic {
}
}
}
}
final
boolean
swapWeakSpace
=
maybeStripSpace
(
inputTransaction
,
isFromSuggestionStrip
);
final
boolean
swapWeakSpace
=
tryStripSpaceAndReturnWhetherShouldSwapInstead
(
inputTransaction
,
isFromSuggestionStrip
);
final
boolean
isInsideDoubleQuoteOrAfterDigit
=
Constants
.
CODE_DOUBLE_QUOTE
==
codePoint
final
boolean
isInsideDoubleQuoteOrAfterDigit
=
Constants
.
CODE_DOUBLE_QUOTE
==
codePoint
&&
mConnection
.
isInsideDoubleQuoteOrAfterDigit
();
&&
mConnection
.
isInsideDoubleQuoteOrAfterDigit
();
...
@@ -803,14 +804,14 @@ public final class InputLogic {
...
@@ -803,14 +804,14 @@ public final class InputLogic {
promotePhantomSpace
(
settingsValues
);
promotePhantomSpace
(
settingsValues
);
}
}
if
(
!
shouldAvoidSendingCode
)
{
if
(
tryPerformDoubleSpacePeriod
(
inputTransaction
)
)
{
sendKeyCodePoint
(
settingsValues
,
codePoint
)
;
mSpaceState
=
SpaceState
.
DOUBLE
;
}
inputTransaction
.
setRequiresUpdateSuggestions
();
}
else
if
(
swapWeakSpace
&&
trySwapSwapperAndSpace
(
inputTransaction
))
{
if
(
Constants
.
CODE_SPACE
==
codePoint
)
{
mSpaceState
=
SpaceState
.
SWAP_PUNCTUATION
;
if
(
maybeDoubleSpacePeriod
(
inp
ut
T
ra
nsaction
))
{
mSuggestionStripViewAccessor
.
setNe
utra
lSuggestionStrip
();
mSpaceState
=
SpaceState
.
DOUBLE
;
}
else
if
(
Constants
.
CODE_SPACE
==
codePoint
)
{
}
else
if
(!
mSuggestedWords
.
isPunctuationSuggestions
())
{
if
(!
mSuggestedWords
.
isPunctuationSuggestions
())
{
mSpaceState
=
SpaceState
.
WEAK
;
mSpaceState
=
SpaceState
.
WEAK
;
}
}
...
@@ -818,12 +819,12 @@ public final class InputLogic {
...
@@ -818,12 +819,12 @@ public final class InputLogic {
if
(
wasComposingWord
||
mSuggestedWords
.
isEmpty
())
{
if
(
wasComposingWord
||
mSuggestedWords
.
isEmpty
())
{
inputTransaction
.
setRequiresUpdateSuggestions
();
inputTransaction
.
setRequiresUpdateSuggestions
();
}
}
if
(!
shouldAvoidSendingCode
)
{
sendKeyCodePoint
(
settingsValues
,
codePoint
);
}
}
else
{
}
else
{
if
(
swapWeakSpace
)
{
if
((
SpaceState
.
PHANTOM
==
inputTransaction
.
mSpaceState
if
(
swapSwapperAndSpace
(
inputTransaction
))
{
mSpaceState
=
SpaceState
.
SWAP_PUNCTUATION
;
}
}
else
if
((
SpaceState
.
PHANTOM
==
inputTransaction
.
mSpaceState
&&
settingsValues
.
isUsuallyFollowedBySpace
(
codePoint
))
&&
settingsValues
.
isUsuallyFollowedBySpace
(
codePoint
))
||
(
Constants
.
CODE_DOUBLE_QUOTE
==
codePoint
||
(
Constants
.
CODE_DOUBLE_QUOTE
==
codePoint
&&
isInsideDoubleQuoteOrAfterDigit
))
{
&&
isInsideDoubleQuoteOrAfterDigit
))
{
...
@@ -841,6 +842,8 @@ public final class InputLogic {
...
@@ -841,6 +842,8 @@ public final class InputLogic {
mSpaceState
=
SpaceState
.
PHANTOM
;
mSpaceState
=
SpaceState
.
PHANTOM
;
}
}
sendKeyCodePoint
(
settingsValues
,
codePoint
);
// Set punctuation right away. onUpdateSelection will fire but tests whether it is
// Set punctuation right away. onUpdateSelection will fire but tests whether it is
// already displayed or not, so it's okay.
// already displayed or not, so it's okay.
mSuggestionStripViewAccessor
.
setNeutralSuggestionStrip
();
mSuggestionStripViewAccessor
.
setNeutralSuggestionStrip
();
...
@@ -1008,17 +1011,16 @@ public final class InputLogic {
...
@@ -1008,17 +1011,16 @@ public final class InputLogic {
* @param inputTransaction The transaction in progress.
* @param inputTransaction The transaction in progress.
* @return true if the swap has been performed, false if it was prevented by preliminary checks.
* @return true if the swap has been performed, false if it was prevented by preliminary checks.
*/
*/
private
boolean
swapSwapperAndSpace
(
final
InputTransaction
inputTransaction
)
{
private
boolean
trySwapSwapperAndSpace
(
final
InputTransaction
inputTransaction
)
{
final
CharSequence
lastTwo
=
mConnection
.
getTextBeforeCursor
(
2
,
0
);
final
int
codePointBeforeCursor
=
mConnection
.
getCodePointBeforeCursor
();
// It is guaranteed lastTwo.charAt(1) is a swapper - else this method is not called.
if
(
Constants
.
CODE_SPACE
!=
codePointBeforeCursor
)
{
if
(
lastTwo
!=
null
&&
lastTwo
.
length
()
==
2
&&
lastTwo
.
charAt
(
0
)
==
Constants
.
CODE_SPACE
)
{
return
false
;
mConnection
.
deleteSurroundingText
(
2
,
0
);
final
String
text
=
lastTwo
.
charAt
(
1
)
+
" "
;
mConnection
.
commitText
(
text
,
1
);
inputTransaction
.
requireShiftUpdate
(
InputTransaction
.
SHIFT_UPDATE_NOW
);
return
true
;
}
}
return
false
;
mConnection
.
deleteSurroundingText
(
1
,
0
);
final
String
text
=
inputTransaction
.
mEvent
.
getTextToCommit
()
+
" "
;
mConnection
.
commitText
(
text
,
1
);
inputTransaction
.
requireShiftUpdate
(
InputTransaction
.
SHIFT_UPDATE_NOW
);
return
true
;
}
}
/*
/*
...
@@ -1027,8 +1029,8 @@ public final class InputLogic {
...
@@ -1027,8 +1029,8 @@ public final class InputLogic {
* @param isFromSuggestionStrip Whether this code point is coming from the suggestion strip.
* @param isFromSuggestionStrip Whether this code point is coming from the suggestion strip.
* @return whether we should swap the space instead of removing it.
* @return whether we should swap the space instead of removing it.
*/
*/
private
boolean
maybe
StripSpace
(
final
InputTransaction
inputTransaction
,
private
boolean
try
StripSpace
AndReturnWhetherShouldSwapInstead
(
final
boolean
isFromSuggestionStrip
)
{
final
InputTransaction
inputTransaction
,
final
boolean
isFromSuggestionStrip
)
{
final
int
codePoint
=
inputTransaction
.
mEvent
.
mCodePoint
;
final
int
codePoint
=
inputTransaction
.
mEvent
.
mCodePoint
;
if
(
Constants
.
CODE_ENTER
==
codePoint
&&
if
(
Constants
.
CODE_ENTER
==
codePoint
&&
SpaceState
.
SWAP_PUNCTUATION
==
inputTransaction
.
mSpaceState
)
{
SpaceState
.
SWAP_PUNCTUATION
==
inputTransaction
.
mSpaceState
)
{
...
@@ -1069,36 +1071,37 @@ public final class InputLogic {
...
@@ -1069,36 +1071,37 @@ public final class InputLogic {
* period-space sequence of characters. This typically happens when the user presses space
* period-space sequence of characters. This typically happens when the user presses space
* twice in a row quickly.
* twice in a row quickly.
* This method will check that the double-space-to-period is active in settings, that the
* This method will check that the double-space-to-period is active in settings, that the
* two spaces have been input close enough together,
and
that the
previous
character
allows
* two spaces have been input close enough together, that the
typed
character
is a space
* for the transformation to take place. If all of
these conditions are fulfilled, this
*
and that the previous character allows
for the transformation to take place. If all of
* method applies the transformation and returns true.
Otherwise, it does nothing and
*
these conditions are fulfilled, this
method applies the transformation and returns true.
* returns false.
*
Otherwise, it does nothing and
returns false.
*
*
* @param inputTransaction The transaction in progress.
* @param inputTransaction The transaction in progress.
* @return true if we applied the double-space-to-period transformation, false otherwise.
* @return true if we applied the double-space-to-period transformation, false otherwise.
*/
*/
private
boolean
maybeDoubleSpacePeriod
(
final
InputTransaction
inputTransaction
)
{
private
boolean
tryPerformDoubleSpacePeriod
(
final
InputTransaction
inputTransaction
)
{
if
(!
inputTransaction
.
mSettingsValues
.
mUseDoubleSpacePeriod
)
return
false
;
// Check the setting, the typed character and the countdown. If any of the conditions is
// This can't happen right now because we don't call this method when the code is not space
// not fulfilled, return false.
if
(
Constants
.
CODE_SPACE
!=
inputTransaction
.
mEvent
.
mCodePoint
)
return
false
;
if
(!
inputTransaction
.
mSettingsValues
.
mUseDoubleSpacePeriod
if
(!
isDoubleSpacePeriodCountdownActive
(
inputTransaction
))
return
false
;
||
Constants
.
CODE_SPACE
!=
inputTransaction
.
mEvent
.
mCodePoint
// We only do this when we see two spaces and an accepted code point before the cursor.
||
!
isDoubleSpacePeriodCountdownActive
(
inputTransaction
))
{
// The code point may be a surrogate pair but the two spaces may not, so we need 4 chars.
return
false
;
final
CharSequence
lastThree
=
mConnection
.
getTextBeforeCursor
(
4
,
0
);
}
if
(
null
==
lastThree
)
return
false
;
// We only do this when we see one space and an accepted code point before the cursor.
final
int
length
=
lastThree
.
length
();
// The code point may be a surrogate pair but the space may not, so we need 3 chars.
if
(
length
<
3
)
return
false
;
final
CharSequence
lastTwo
=
mConnection
.
getTextBeforeCursor
(
3
,
0
);
if
(
lastThree
.
charAt
(
length
-
1
)
!=
Constants
.
CODE_SPACE
)
return
false
;
if
(
null
==
lastTwo
)
return
false
;
if
(
lastThree
.
charAt
(
length
-
2
)
!=
Constants
.
CODE_SPACE
)
return
false
;
final
int
length
=
lastTwo
.
length
();
// We know there are spaces in pos -1 and -2, and we have at least three chars.
if
(
length
<
2
)
return
false
;
// If we have only three chars, isSurrogatePairs can't return true as charAt(1) is a space,
if
(
lastTwo
.
charAt
(
length
-
1
)
!=
Constants
.
CODE_SPACE
)
return
false
;
// so this is fine.
// We know there is a space in pos -1, and we have at least two chars. If we have only two
// chars, isSurrogatePairs can't return true as charAt(1) is a space, so this is fine.
final
int
firstCodePoint
=
final
int
firstCodePoint
=
Character
.
isSurrogatePair
(
lastT
hree
.
charAt
(
0
),
lastT
hree
.
charAt
(
1
))
?
Character
.
isSurrogatePair
(
lastT
wo
.
charAt
(
0
),
lastT
wo
.
charAt
(
1
))
?
Character
.
codePointAt
(
lastT
hree
,
0
)
:
lastT
hree
.
charAt
(
length
-
3
);
Character
.
codePointAt
(
lastT
wo
,
length
-
3
)
:
lastT
wo
.
charAt
(
length
-
2
);
if
(
canBeFollowedByDoubleSpacePeriod
(
firstCodePoint
))
{
if
(
canBeFollowedByDoubleSpacePeriod
(
firstCodePoint
))
{
cancelDoubleSpacePeriodCountdown
();
cancelDoubleSpacePeriodCountdown
();
mConnection
.
deleteSurroundingText
(
2
,
0
);
mConnection
.
deleteSurroundingText
(
1
,
0
);
final
String
textToInsert
=
inputTransaction
.
mSettingsValues
.
mSpacingAndPunctuations
final
String
textToInsert
=
inputTransaction
.
mSettingsValues
.
mSpacingAndPunctuations
.
mSentenceSeparatorAndSpace
;
.
mSentenceSeparatorAndSpace
;
mConnection
.
commitText
(
textToInsert
,
1
);
mConnection
.
commitText
(
textToInsert
,
1
);
...
...
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