fix bug with suggestions differing only by first letter

This commit is contained in:
nightwing 2013-03-10 19:26:28 +04:00
commit d24c853f88
2 changed files with 18 additions and 9 deletions

View file

@ -1,5 +1,6 @@
define(function(require, exports, module) {
"use strict";
var event = require("../lib/event");
exports.contextMenuHandler = function(e){
var host = e.target;
@ -18,17 +19,26 @@ exports.contextMenuHandler = function(e){
text.value = value;
text.setSelectionRange(w.length + 1, w.length + 1);
text.setSelectionRange(0, 0);
var afterKeydown = false;
event.addListener(text, "keydown", function onKeydown() {
event.removeListener(text, "keydown", onKeydown);
afterKeydown = true;
});
host.textInput.setInputHandler(function(newVal) {
console.log(newVal , value, text.selectionStart, text.selectionEnd)
if (newVal == value)
return '';
if (newVal.lastIndexOf(value) == newVal.length - value.length)
return newVal.slice(0, -value.length);
if (newVal.indexOf(value) === 0)
if (newVal.lastIndexOf(value, 0) === 0)
return newVal.slice(value.length);
if (newVal.substr(text.selectionEnd) == value)
return newVal.slice(0, -value.length);
if (newVal.slice(-2) == PLACEHOLDER) {
var val = newVal.slice(0, -2);
if (val.slice(-1) == " ") {
if (afterKeydown)
return val.substring(0, text.selectionEnd);
val = val.slice(0, -1);
host.session.replace(r, val);
return "";

View file

@ -97,8 +97,8 @@ var TextInput = function(parentNode, host) {
if (inCompostion)
return;
if (inputHandler) {
selectionStart = 0
selectionEnd = isEmpty == false ? text.value.length - 1 : 0;
selectionStart = 0;
selectionEnd = isEmpty ? 0 : text.value.length - 1;
} else {
var selectionStart = isEmpty ? 2 : 1;
var selectionEnd = 2;
@ -191,12 +191,12 @@ var TextInput = function(parentNode, host) {
host.selectAll();
resetSelection();
} else if (inputHandler) {
resetSelection();
resetSelection(host.selection.isEmpty());
}
};
var inputHandler = null;
this.setInputHandler = function(onInput) {inputHandler = onInput};
this.setInputHandler = function(cb) {inputHandler = cb};
this.getInputHandler = function() {return inputHandler};
var sendText = function(data) {
@ -231,9 +231,8 @@ var TextInput = function(parentNode, host) {
if (inCompostion)
return;
var data = text.value;
resetValue();
sendText(data);
resetValue();
};
var onCut = function(e) {