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
8c6537ed
Commit
8c6537ed
authored
11 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
Use cached data for getTextBeforeCursor.
Bug: 8864306 Change-Id: Ia146f711f1de4336d7e3363208ab92eba856f5e1
parent
38e98026
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/RichInputConnection.java
+33
-20
33 additions, 20 deletions
...rc/com/android/inputmethod/latin/RichInputConnection.java
with
33 additions
and
20 deletions
java/src/com/android/inputmethod/latin/RichInputConnection.java
+
33
−
20
View file @
8c6537ed
...
@@ -246,22 +246,35 @@ public final class RichInputConnection {
...
@@ -246,22 +246,35 @@ public final class RichInputConnection {
mCommittedTextBeforeComposingText
.
length
());
mCommittedTextBeforeComposingText
.
length
());
}
}
public
CharSequence
getTextBeforeCursor
(
final
int
i
,
final
int
j
)
{
public
CharSequence
getTextBeforeCursor
(
final
int
n
,
final
int
flags
)
{
// TODO: use mCommittedTextBeforeComposingText if possible to improve performance
final
int
cachedLength
=
mCommittedTextBeforeComposingText
.
length
()
+
mComposingText
.
length
();
// If we have enough characters to satisfy the request, or if we have all characters in
// the text field, then we can return the cached version right away.
if
(
cachedLength
>=
n
||
cachedLength
>=
mCurrentCursorPosition
)
{
final
StringBuilder
s
=
new
StringBuilder
(
mCommittedTextBeforeComposingText
);
s
.
append
(
mComposingText
);
if
(
s
.
length
()
>
n
)
{
s
.
delete
(
0
,
s
.
length
()
-
n
);
}
return
s
;
}
mIC
=
mParent
.
getCurrentInputConnection
();
mIC
=
mParent
.
getCurrentInputConnection
();
if
(
null
!=
mIC
)
return
mIC
.
getTextBeforeCursor
(
i
,
j
);
if
(
null
!=
mIC
)
{
return
mIC
.
getTextBeforeCursor
(
n
,
flags
);
}
return
null
;
return
null
;
}
}
public
CharSequence
getTextAfterCursor
(
final
int
i
,
final
int
j
)
{
public
CharSequence
getTextAfterCursor
(
final
int
n
,
final
int
flags
)
{
mIC
=
mParent
.
getCurrentInputConnection
();
mIC
=
mParent
.
getCurrentInputConnection
();
if
(
null
!=
mIC
)
return
mIC
.
getTextAfterCursor
(
i
,
j
);
if
(
null
!=
mIC
)
return
mIC
.
getTextAfterCursor
(
n
,
flags
);
return
null
;
return
null
;
}
}
public
void
deleteSurroundingText
(
final
int
i
,
final
int
j
)
{
public
void
deleteSurroundingText
(
final
int
beforeLength
,
final
int
afterLength
)
{
if
(
DEBUG_BATCH_NESTING
)
checkBatchEdit
();
if
(
DEBUG_BATCH_NESTING
)
checkBatchEdit
();
final
int
remainingChars
=
mComposingText
.
length
()
-
i
;
final
int
remainingChars
=
mComposingText
.
length
()
-
beforeLength
;
if
(
remainingChars
>=
0
)
{
if
(
remainingChars
>=
0
)
{
mComposingText
.
setLength
(
remainingChars
);
mComposingText
.
setLength
(
remainingChars
);
}
else
{
}
else
{
...
@@ -271,15 +284,15 @@ public final class RichInputConnection {
...
@@ -271,15 +284,15 @@ public final class RichInputConnection {
+
remainingChars
,
0
);
+
remainingChars
,
0
);
mCommittedTextBeforeComposingText
.
setLength
(
len
);
mCommittedTextBeforeComposingText
.
setLength
(
len
);
}
}
if
(
mCurrentCursorPosition
>
i
)
{
if
(
mCurrentCursorPosition
>
beforeLength
)
{
mCurrentCursorPosition
-=
i
;
mCurrentCursorPosition
-=
beforeLength
;
}
else
{
}
else
{
mCurrentCursorPosition
=
0
;
mCurrentCursorPosition
=
0
;
}
}
if
(
null
!=
mIC
)
{
if
(
null
!=
mIC
)
{
mIC
.
deleteSurroundingText
(
i
,
j
);
mIC
.
deleteSurroundingText
(
beforeLength
,
afterLength
);
if
(
ProductionFlag
.
USES_DEVELOPMENT_ONLY_DIAGNOSTICS
)
{
if
(
ProductionFlag
.
USES_DEVELOPMENT_ONLY_DIAGNOSTICS
)
{
ResearchLogger
.
richInputConnection_deleteSurroundingText
(
i
,
j
);
ResearchLogger
.
richInputConnection_deleteSurroundingText
(
beforeLength
,
afterLength
);
}
}
}
}
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
...
@@ -362,7 +375,7 @@ public final class RichInputConnection {
...
@@ -362,7 +375,7 @@ public final class RichInputConnection {
}
}
}
}
public
void
setComposingText
(
final
CharSequence
text
,
final
int
i
)
{
public
void
setComposingText
(
final
CharSequence
text
,
final
int
newCursorPosition
)
{
if
(
DEBUG_BATCH_NESTING
)
checkBatchEdit
();
if
(
DEBUG_BATCH_NESTING
)
checkBatchEdit
();
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
mCurrentCursorPosition
+=
text
.
length
()
-
mComposingText
.
length
();
mCurrentCursorPosition
+=
text
.
length
()
-
mComposingText
.
length
();
...
@@ -370,24 +383,24 @@ public final class RichInputConnection {
...
@@ -370,24 +383,24 @@ public final class RichInputConnection {
mComposingText
.
append
(
text
);
mComposingText
.
append
(
text
);
// TODO: support values of i != 1. At this time, this is never called with i != 1.
// TODO: support values of i != 1. At this time, this is never called with i != 1.
if
(
null
!=
mIC
)
{
if
(
null
!=
mIC
)
{
mIC
.
setComposingText
(
text
,
i
);
mIC
.
setComposingText
(
text
,
newCursorPosition
);
if
(
ProductionFlag
.
USES_DEVELOPMENT_ONLY_DIAGNOSTICS
)
{
if
(
ProductionFlag
.
USES_DEVELOPMENT_ONLY_DIAGNOSTICS
)
{
ResearchLogger
.
richInputConnection_setComposingText
(
text
,
i
);
ResearchLogger
.
richInputConnection_setComposingText
(
text
,
newCursorPosition
);
}
}
}
}
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
}
}
public
void
setSelection
(
final
int
from
,
final
int
to
)
{
public
void
setSelection
(
final
int
start
,
final
int
end
)
{
if
(
DEBUG_BATCH_NESTING
)
checkBatchEdit
();
if
(
DEBUG_BATCH_NESTING
)
checkBatchEdit
();
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
if
(
DEBUG_PREVIOUS_TEXT
)
checkConsistencyForDebug
();
if
(
null
!=
mIC
)
{
if
(
null
!=
mIC
)
{
mIC
.
setSelection
(
from
,
to
);
mIC
.
setSelection
(
start
,
end
);
if
(
ProductionFlag
.
USES_DEVELOPMENT_ONLY_DIAGNOSTICS
)
{
if
(
ProductionFlag
.
USES_DEVELOPMENT_ONLY_DIAGNOSTICS
)
{
ResearchLogger
.
richInputConnection_setSelection
(
from
,
to
);
ResearchLogger
.
richInputConnection_setSelection
(
start
,
end
);
}
}
}
}
mCurrentCursorPosition
=
from
;
mCurrentCursorPosition
=
start
;
mCommittedTextBeforeComposingText
.
setLength
(
0
);
mCommittedTextBeforeComposingText
.
setLength
(
0
);
mCommittedTextBeforeComposingText
.
append
(
getTextBeforeCursor
(
DEFAULT_TEXT_CACHE_SIZE
,
0
));
mCommittedTextBeforeComposingText
.
append
(
getTextBeforeCursor
(
DEFAULT_TEXT_CACHE_SIZE
,
0
));
}
}
...
@@ -425,7 +438,7 @@ public final class RichInputConnection {
...
@@ -425,7 +438,7 @@ public final class RichInputConnection {
public
String
getNthPreviousWord
(
final
String
sentenceSeperators
,
final
int
n
)
{
public
String
getNthPreviousWord
(
final
String
sentenceSeperators
,
final
int
n
)
{
mIC
=
mParent
.
getCurrentInputConnection
();
mIC
=
mParent
.
getCurrentInputConnection
();
if
(
null
==
mIC
)
return
null
;
if
(
null
==
mIC
)
return
null
;
final
CharSequence
prev
=
mIC
.
getTextBeforeCursor
(
LOOKBACK_CHARACTER_NUM
,
0
);
final
CharSequence
prev
=
getTextBeforeCursor
(
LOOKBACK_CHARACTER_NUM
,
0
);
if
(
DEBUG_PREVIOUS_TEXT
&&
null
!=
prev
)
{
if
(
DEBUG_PREVIOUS_TEXT
&&
null
!=
prev
)
{
final
int
checkLength
=
LOOKBACK_CHARACTER_NUM
-
1
;
final
int
checkLength
=
LOOKBACK_CHARACTER_NUM
-
1
;
final
String
reference
=
prev
.
length
()
<=
checkLength
?
prev
.
toString
()
final
String
reference
=
prev
.
length
()
<=
checkLength
?
prev
.
toString
()
...
@@ -630,7 +643,7 @@ public final class RichInputConnection {
...
@@ -630,7 +643,7 @@ public final class RichInputConnection {
// be needed, but it's there just in case something went wrong.
// be needed, but it's there just in case something went wrong.
final
CharSequence
textBeforeCursor
=
getTextBeforeCursor
(
2
,
0
);
final
CharSequence
textBeforeCursor
=
getTextBeforeCursor
(
2
,
0
);
final
String
periodSpace
=
". "
;
final
String
periodSpace
=
". "
;
if
(!
periodSpace
.
equals
(
textBeforeCursor
))
{
if
(!
TextUtils
.
equals
(
periodSpace
,
textBeforeCursor
))
{
// Theoretically we should not be coming here if there isn't ". " before the
// Theoretically we should not be coming here if there isn't ". " before the
// cursor, but the application may be changing the text while we are typing, so
// cursor, but the application may be changing the text while we are typing, so
// anything goes. We should not crash.
// anything goes. We should not crash.
...
...
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