mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-28 21:15:15 +00:00
Add focusSelectFromStart/focusSelectFromEnd attributes to <$edit-text> widget (#7222)
* Initial commit
* WIP
* Align implementation with @yaisog's suggestion
See https://github.com/Jermolene/TiddlyWiki5/pull/7222#issuecomment-1410194593
* Commit missing from 3262b8d77d
Thanks @pmario
* Fix version number
Thanks @yaisog
* Add two examples for text selection (#7286)
---------
Co-authored-by: yaisog <m@rcuswinter.de>
This commit is contained in:
@@ -28,6 +28,24 @@ exports.domMatchesSelector = function(node,selector) {
|
||||
return node.matches ? node.matches(selector) : node.msMatchesSelector(selector);
|
||||
};
|
||||
|
||||
/*
|
||||
Select text in a an input or textarea (setSelectionRange crashes on certain input types)
|
||||
*/
|
||||
exports.setSelectionRangeSafe = function(node,start,end,direction) {
|
||||
try {
|
||||
node.setSelectionRange(start,end,direction);
|
||||
} catch(e) {
|
||||
node.select();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Select the text in an input or textarea by position
|
||||
*/
|
||||
exports.setSelectionByPosition = function(node,selectFromStart,selectFromEnd) {
|
||||
$tw.utils.setSelectionRangeSafe(node,selectFromStart,node.value.length - selectFromEnd);
|
||||
};
|
||||
|
||||
exports.removeChildren = function(node) {
|
||||
while(node.hasChildNodes()) {
|
||||
node.removeChild(node.firstChild);
|
||||
|
||||
Reference in New Issue
Block a user