Add Select All context menu command support
This commit is contained in:
parent
0604b75310
commit
473ddfd353
1 changed files with 25 additions and 4 deletions
|
|
@ -53,7 +53,7 @@ var TextInput = function(parentNode, host) {
|
|||
text.style.top = "-2em";
|
||||
parentNode.insertBefore(text, parentNode.firstChild);
|
||||
|
||||
var PLACEHOLDER = useragent.isIE || useragent.isOpera ? "\x01" : "\x00";
|
||||
var PLACEHOLDER = useragent.isIE || useragent.isOpera ? "\x01\x01" : "\x00\x00";
|
||||
|
||||
resetValue();
|
||||
|
||||
|
|
@ -67,6 +67,8 @@ var TextInput = function(parentNode, host) {
|
|||
setTimeout(resetSelection);
|
||||
}
|
||||
|
||||
var cut = false
|
||||
var copied = false;
|
||||
var pasted = false;
|
||||
|
||||
var inCompostion = false;
|
||||
|
|
@ -86,8 +88,8 @@ var TextInput = function(parentNode, host) {
|
|||
};
|
||||
|
||||
function resetSelection() {
|
||||
var selectionStart = isSelectionEmpty ? 1 : 0;
|
||||
var selectionEnd = 1;
|
||||
var selectionStart = isSelectionEmpty ? 2 : 1;
|
||||
var selectionEnd = 2;
|
||||
|
||||
if (text.setSelectionRange) {
|
||||
text.setSelectionRange(selectionStart, selectionEnd);
|
||||
|
|
@ -102,6 +104,21 @@ var TextInput = function(parentNode, host) {
|
|||
}
|
||||
};
|
||||
|
||||
var onSelect = function(e) {
|
||||
if (cut) {
|
||||
cut = false;
|
||||
return;
|
||||
}
|
||||
if (copied) {
|
||||
copied = false;
|
||||
return;
|
||||
}
|
||||
if (text.selectionStart === 0 && text.selectionEnd === text.value.length) {
|
||||
host.selectAll();
|
||||
resetSelection();
|
||||
}
|
||||
};
|
||||
|
||||
var onInput = function(e) {
|
||||
if (inCompostion)
|
||||
return;
|
||||
|
|
@ -115,7 +132,7 @@ var TextInput = function(parentNode, host) {
|
|||
return;
|
||||
}
|
||||
|
||||
var data = text.value.substring(isSelectionEmpty ? 1 : 0);
|
||||
var data = text.value.substring(isSelectionEmpty ? 2 : 1);
|
||||
resetValue();
|
||||
if (data)
|
||||
host.onTextInput(data);
|
||||
|
|
@ -160,6 +177,7 @@ var TextInput = function(parentNode, host) {
|
|||
if (!supported) {
|
||||
text.value = data;
|
||||
text.select();
|
||||
cut = true;
|
||||
setTimeout(function(){ host.onCut() });
|
||||
}
|
||||
};
|
||||
|
|
@ -184,6 +202,7 @@ var TextInput = function(parentNode, host) {
|
|||
if (!supported) {
|
||||
text.value = data;
|
||||
text.select();
|
||||
copided = true;
|
||||
setTimeout(function(){ host.onCopy() });
|
||||
}
|
||||
|
||||
|
|
@ -207,6 +226,8 @@ var TextInput = function(parentNode, host) {
|
|||
|
||||
event.addCommandKeyListener(text, host.onCommandKey.bind(host));
|
||||
|
||||
event.addListener(text, "select", onSelect);
|
||||
|
||||
event.addListener(text, "input", onInput);
|
||||
|
||||
event.addListener(text, "cut", onCut);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue