| Index: third_party/google_input_tools/src/chrome/os/inputview/util.js
|
| diff --git a/third_party/google_input_tools/src/chrome/os/inputview/util.js b/third_party/google_input_tools/src/chrome/os/inputview/util.js
|
| index e29accd99d1675a1275a76d64ba44733727176fc..009f54e2e5e47cfee408b36a7c8b04ba1e80c6cc 100644
|
| --- a/third_party/google_input_tools/src/chrome/os/inputview/util.js
|
| +++ b/third_party/google_input_tools/src/chrome/os/inputview/util.js
|
| @@ -329,4 +329,62 @@ util.getConfigName = function(keyboardCode) {
|
| return keyboardCode.replace(/\..*$/, '');
|
| };
|
|
|
| +
|
| +/**
|
| + * Checks that the word is a valid delete from the old to new context.
|
| + *
|
| + * @param {string} oldContext The old context.
|
| + * @param {string} newContext The new context.
|
| + * @param {string} deletionCandidate A possible word deletion.
|
| + *
|
| + * @return {boolean} Whether the deletion was valid.
|
| + */
|
| +util.isPossibleDelete = function(
|
| + oldContext, newContext, deletionCandidate) {
|
| + // Check that deletionCandidate exists in oldContext. We don't check if it's a
|
| + // tail since our heuristic may have trimmed whitespace.
|
| + var rootEnd = oldContext.lastIndexOf(deletionCandidate);
|
| + if (rootEnd != -1) {
|
| + // Check that remaining text in root persisted in newContext.
|
| + var root = oldContext.slice(0, rootEnd);
|
| + return root == newContext.slice(-rootEnd);
|
| + }
|
| + return false;
|
| +};
|
| +
|
| +
|
| +/**
|
| + * Checks whether a letter deletion would cause the observed context transform.
|
| + *
|
| + * @param {string} oldContext The old context.
|
| + * @param {string} newContext The new context.
|
| + *
|
| + * @return {boolean} Whether the transform is valid.
|
| + */
|
| +util.isLetterDelete = function(oldContext, newContext) {
|
| + if (oldContext == '') {
|
| + return false;
|
| + }
|
| + // Handle buffer overflow.
|
| + if (oldContext.length == newContext.length) {
|
| + return util.isLetterDelete(oldContext, newContext.slice(1));
|
| + }
|
| + return oldContext.length == newContext.length + 1 &&
|
| + oldContext.indexOf(newContext) == 0;
|
| +};
|
| +
|
| +
|
| +/**
|
| + * Checks whether a letter restoration would cause the observed context
|
| + * transform.
|
| + *
|
| + * @param {string} oldContext The old context.
|
| + * @param {string} newContext The new context.
|
| + *
|
| + * @return {boolean} Whether the transform is valid.
|
| + */
|
| +util.isLetterRestore = function(oldContext, newContext) {
|
| + return util.isLetterDelete(newContext, oldContext);
|
| +};
|
| +
|
| }); // goog.scope
|
|
|