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