1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 07:13:15 +00:00

Initial commit

This commit is contained in:
jeremy@jermolene.com 2023-01-22 21:07:51 +00:00
parent 75a399a389
commit 9a4695a4aa
5 changed files with 39 additions and 6 deletions

View File

@ -177,9 +177,11 @@ FramedEngine.prototype.fixHeight = function() {
Focus the engine node
*/
FramedEngine.prototype.focus = function() {
if(this.domNode.focus && this.domNode.select) {
if(this.domNode.focus) {
this.domNode.focus();
this.domNode.select();
}
if(this.domNode.select) {
$tw.utils.setSelectionByKeyword(this.domNode,this.widget.editFocusSelect);
}
};

View File

@ -119,10 +119,12 @@ SimpleEngine.prototype.fixHeight = function() {
/*
Focus the engine node
*/
SimpleEngine.prototype.focus = function() {
if(this.domNode.focus && this.domNode.select) {
SimpleEngine.prototype.focus = function() {
if(this.domNode.focus) {
this.domNode.focus();
this.domNode.select();
}
if(this.domNode.select) {
$tw.utils.setSelectionByKeyword(this.domNode,this.widget.editFocusSelect);
}
};

View File

@ -180,6 +180,7 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
this.editMinHeight = this.getAttribute("minHeight",DEFAULT_MIN_TEXT_AREA_HEIGHT);
this.editFocusPopup = this.getAttribute("focusPopup");
this.editFocus = this.getAttribute("focus");
this.editFocusSelect = this.getAttribute("focusSelect","yes");
this.editTabIndex = this.getAttribute("tabindex");
this.editCancelPopups = this.getAttribute("cancelPopups","") === "yes";
this.editInputActions = this.getAttribute("inputActions");

View File

@ -28,6 +28,33 @@ 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 keyword:
start - place cursor at start of text
end|no - place cursor at end of text
yes - select entire text
*/
exports.setSelectionByKeyword = function(node,selectType) {
if(selectType === "start") {
$tw.utils.setSelectionRangeSafe(node,0,0);
} else if(selectType === "end" || selectType === "no") {
$tw.utils.setSelectionRangeSafe(node,node.value.length,node.value.length);
} else {
node.select();
}
};
exports.removeChildren = function(node) {
while(node.hasChildNodes()) {
node.removeChild(node.firstChild);

View File

@ -1,6 +1,6 @@
caption: edit-text
created: 20131024141900000
modified: 20211104200554064
modified: 20230122210049893
tags: Widgets
title: EditTextWidget
type: text/vnd.tiddlywiki
@ -24,6 +24,7 @@ The content of the `<$edit-text>` widget is ignored.
|placeholder |Placeholder text to be displayed when the edit field is empty |
|focusPopup |Title of a state tiddler for a popup that is displayed when the editing element has focus |
|focus |Set to "yes" or "true" to automatically focus the editor after creation |
|focusSelect |<<.from-version 5.2.26>> If `focus` attribute is enabled, determines how the text is selected: "start" places the cursor at the start of the text, "end" or "no" places the cursor at the end of the text and "yes" (the default) selects the entire text |
|tabindex |Sets the `tabindex` attribute of the input or textarea to the given value |
|autocomplete |<<.from-version 5.1.23>> An optional string to provide a hint to the browser how to handle autocomplete for this input |
|tag |Overrides the generated HTML editing element tag. For a multi-line editor use `tag=textarea`. For a single-line editor use `tag=input` |