diff --git a/core/modules/editor/engines/framed.js b/core/modules/editor/engines/framed.js index c856ad50b..77cb15629 100644 --- a/core/modules/editor/engines/framed.js +++ b/core/modules/editor/engines/framed.js @@ -181,7 +181,7 @@ FramedEngine.prototype.focus = function() { this.domNode.focus(); } if(this.domNode.select) { - $tw.utils.setSelectionByKeyword(this.domNode,this.widget.editFocusSelect); + $tw.utils.setSelectionByKeyword(this.domNode,this.widget.editFocusSelectFromStart,this.widget.editFocusSelectFromEnd); } }; diff --git a/core/modules/editor/engines/simple.js b/core/modules/editor/engines/simple.js index 507a156f7..fbbe295c5 100644 --- a/core/modules/editor/engines/simple.js +++ b/core/modules/editor/engines/simple.js @@ -124,7 +124,7 @@ SimpleEngine.prototype.focus = function() { this.domNode.focus(); } if(this.domNode.select) { - $tw.utils.setSelectionByKeyword(this.domNode,this.widget.editFocusSelect); + $tw.utils.setSelectionByKeyword(this.domNode,this.widget.editFocusSelectFromStart,this.widget.editFocusSelectFromEnd); } }; diff --git a/core/modules/editor/factory.js b/core/modules/editor/factory.js index 19e647572..6157ec67f 100644 --- a/core/modules/editor/factory.js +++ b/core/modules/editor/factory.js @@ -180,7 +180,8 @@ 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.editFocusSelectFromStart = $tw.utils.parseNumber(this.getAttribute("focusSelectFromStart","0")); + this.editFocusSelectFromEnd = $tw.utils.parseNumber(this.getAttribute("focusSelectFromEnd","0")); this.editTabIndex = this.getAttribute("tabindex"); this.editCancelPopups = this.getAttribute("cancelPopups","") === "yes"; this.editInputActions = this.getAttribute("inputActions"); diff --git a/core/modules/utils/dom/dom.js b/core/modules/utils/dom/dom.js index 4cdc46a9c..6d8f2a76d 100644 --- a/core/modules/utils/dom/dom.js +++ b/core/modules/utils/dom/dom.js @@ -40,19 +40,10 @@ exports.setSelectionRangeSafe = function(node,start,end,direction) { }; /* -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 +Select the text in an input or textarea by position */ -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.setSelectionByPosition = function(node,selectFromStart,selectFromEnd) { + $tw.utils.setSelectionRangeSafe(node,selectFromStart,node.value.length - selectFromEnd); }; exports.removeChildren = function(node) { diff --git a/editions/tw5.com/tiddlers/widgets/EditTextWidget.tid b/editions/tw5.com/tiddlers/widgets/EditTextWidget.tid index 31fef0989..5775d9356 100644 --- a/editions/tw5.com/tiddlers/widgets/EditTextWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/EditTextWidget.tid @@ -24,7 +24,8 @@ 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 | +|focusSelectFromStart |<<.from-version 5.2.26>> If the `focus` attribute is enabled, determines the position of the start of the selection: 0 (the default) places the start of the selection at the beginning of the text, 1 places the start of the selection after the first character etc | +|focusSelectFromEnd |<<.from-version 5.2.26>> If the `focus` attribute is enabled, determines the position of the end of the selection: 0 (the default) places the end of the selection at the end of the text, 1 places the start of the selection before the final character etc | |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` | @@ -39,7 +40,6 @@ The content of the `<$edit-text>` widget is ignored. |disabled|<<.from-version "5.1.23">> Optional, disables the text input if set to "yes". Defaults to "no"| |fileDrop|<<.from-version "5.2.0">> Optional. When set to "yes" allows dropping or pasting images into the editor to import them. Defaults to "no"| - ! Example If you wanted to change the field //myconfig// of the tiddler //AppSettings//, you could use an EditTextWidget to edit the field, and then show the result anywhere else by using `{{AppSettings!!myconfig}}`. Note that this will create tiddler AppSettings if it doesn't already exist.