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) { define(function(require, exports, module) {
"use strict"; "use strict";
var event = require("../lib/event");
exports.contextMenuHandler = function(e){ exports.contextMenuHandler = function(e){
var host = e.target; var host = e.target;
@ -19,16 +20,25 @@ exports.contextMenuHandler = function(e){
text.setSelectionRange(w.length + 1, w.length + 1); text.setSelectionRange(w.length + 1, w.length + 1);
text.setSelectionRange(0, 0); 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) { host.textInput.setInputHandler(function(newVal) {
console.log(newVal , value, text.selectionStart, text.selectionEnd)
if (newVal == value) if (newVal == value)
return ''; return '';
if (newVal.lastIndexOf(value) == newVal.length - value.length) if (newVal.lastIndexOf(value, 0) === 0)
return newVal.slice(0, -value.length);
if (newVal.indexOf(value) === 0)
return newVal.slice(value.length); return newVal.slice(value.length);
if (newVal.substr(text.selectionEnd) == value)
return newVal.slice(0, -value.length);
if (newVal.slice(-2) == PLACEHOLDER) { if (newVal.slice(-2) == PLACEHOLDER) {
var val = newVal.slice(0, -2); var val = newVal.slice(0, -2);
if (val.slice(-1) == " ") { if (val.slice(-1) == " ") {
if (afterKeydown)
return val.substring(0, text.selectionEnd);
val = val.slice(0, -1); val = val.slice(0, -1);
host.session.replace(r, val); host.session.replace(r, val);
return ""; return "";

View file

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