TextSelection in a TextField issue - dart

After selecting the whole text in a TextField using TextSelection() it does indeed select the whole text but after pressing a key on the keyboard, it starts adding pressed letters/numbers to the start of the text as opposed to deleting the old one and replacing it with the newly typed letters/numbers.
Is this expected behavior? If so, is there any way I can programatically select the text and then replace it upon pressing a key on the keyboard?
This is how I select the text:
manualEditorNode.addListener(() {
if (manualEditorNode.hasFocus) {
manualInputController.selection = TextSelection(
baseOffset: 0, extentOffset: manualInputController.text.length);
}
});

The following works for me in my program. Maybe you can try something like this?
var cursorPos = textInputController.selection;
setState(() {
textInputController.text = newInput;
if (cursorPos.start > newInput.length) {
cursorPos = new TextSelection.fromPosition(
new TextPosition(offset: newInput.length));
}
textInputController.selection = cursorPos;
});

Related

Highlight row in ag grid on button click

I have a button outside the grid, on clicking of this button i am iterating the row nodes and doing a check whether the data is empty or not. If it is empty i want to highlight that row. Did not found anything which can give me any option to highlight the row in ag grid on button click.
Kindly help
I found the answer for above:
In Component: may be in constructor
this.rowClassRules = {
'invalid-row': (params) => {
if (this.inValidRowNode && this.inValidRowNode.data.name === params.data.name) {
return true;
}
}
};
On button click (in validation method), while iterating the node we need to set the data. I am setting in this way.
node.setDataValue('name', ' ');
In Html:
<ag-grid-angular #agGrid rowSelection="multiple" [gridOptions]="gridOptions" [columnDefs]="gridColumnDefs" (gridReady)="onGridReady($event)"
[rowClassRules]="rowClassRules">

How to programmatically enter text in UITextView at the current cursor position

I would like to add (some predefined) text at the current cursor position in a UITextView using Swift. So if I have a UITextField named txtField that has some text in it already such as "this is a beautiful valley" and I tap in the area between "a" and "beautiful" so that the cursor is now in the space between "a" and "beautiful" and then click a Button on my user interface a string of text such as "very" will get typed at the cursor position, so that the text in the UITextView will now become "this is a very beautiful valley". At the end of this operation (after button click event) I would the cursor to be just after the word "very". Many thanks for your help. I can see some question on the forum with similar themes, but the answers are in Objective C. I suicidal like help using Swift.
Try this... Inside your button's IBAction use this (please do not use forced optional unwrapping) or else if the textView has no selection or cursor, the app might crash:
let txt = "whatever you want"
if let range = handleToYourTextView.selectedTextRange {
// From your question I assume that you do not want to replace a selection, only insert some text where the cursor is.
if range.start == range.end {
handleToYourTextView.replaceRange(range, withText: txt)
}
}
try this
textView.replaceRange(textView.selectedTextRange!, withText: "your text")
update:
Swift 5.2
let txt = "whatever you want"
if let range = myTextView.selectedTextRange {
if range.start == range.end {
myTextView.replace(range, withText: txt)
}

Remain Cursor postion inside EditText android

I have one backspace image button to delete one character after cursor inside an Editext field
<ImageButton
android:id="#+id/backspace"/>
<EditText
android:id="#+id/result"/>
And this is code
EditText resultEditText = (EditText) getActivity().findViewById(R.id.result);
int curPostion;
curPostion = resultEditText.getSelectionEnd();
//getting the selected Text
SpannableStringBuilder selectedStr = new SpannableStringBuilder(resultEditText.getText());
//replacing the selected text with empty String
selectedStr.replace(curPostion - 1, curPostion, "");
resultEditText.setSelection(curPostion);
//Set new string
resultEditText.setText(selectedStr);
My problem is when I press the backspace button, one character is deleted successfully, but the cursor immediately come back to the first postion of the EditText.
How to remain cursor to the position after deleting a character?.
I'm really appreciate your help. Thank you very much.
I just figured out the solution, just delcare a new variable to store the new cursor postion then setSelection().
In detail
EditText resultEditText = (EditText) getActivity().findViewById(R.id.result);
int curPostion;
curPostion = resultEditText.getSelectionEnd();
//getting the selected Text
SpannableStringBuilder selectedStr = new SpannableStringBuilder(resultEditText.getText());
//replacing the selected text with empty String
selectedStr.replace(curPostion - 1, curPostion, "");
//Store postition
int afterDelPosition = curPostion - 1;
//Set new string
resultEditText.setText(selectedStr);
//This will remain the cursor position
resultEditText.setSelection(afterDelPosition);
I hope this will be helpfull.

Xamarin.iOS: Try to move bottom toolbar(text field) above keyboard when editing like chat window

I tried to put the toolbar(with text field) above the keyboard. Initially, the toolbar was at the bottom.
I tried to use "inputAccessaryView" on the text field. The toolbar just disappear after I clicked inside the text field. I know this will work if I created a new toolbar for it. But like in the chat window, I want the same textfield/toolbar.
Here is the code
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
NavigationItem.Title = "Name";
ChatInput = new UITextField (new RectangleF(0,0,View.Bounds.Width - 104f,30f));
Toolbar = new UIToolbar (new RectangleF(0, View.Bounds.Height - 44.0f, View.Bounds.Width, 44f));
ChatInput.BorderStyle = UITextBorderStyle.RoundedRect;
Toolbar.SetItems( new UIBarButtonItem[] {
new UIBarButtonItem(UIBarButtonSystemItem.Refresh, (s,e) => {
Console.WriteLine("Refresh clicked");
})
, new UIBarButtonItem (ChatInput){Style = UIBarButtonItemStyle.Bordered,Width = View.Bounds.Width - 104f}
, new UIBarButtonItem(UIBarButtonSystemItem.Reply, (s,e) => {
Console.WriteLine ("Reply clicked");
})
}, false);
ChatInput.ReturnKeyType = UIReturnKeyType.Send;
ChatInput.ShouldBeginEditing = delegate {
ChatInput.InputAccessoryView = Toolbar;
return true;
};
ChatInput.ShouldReturn = delegate {
ChatInput.ResignFirstResponder();
return true;
};
View.AddSubview (Toolbar);
}
I don't know if there's a way to pin the toolbar on top of the keyboard, but what you could do it create some kind of method to move the toolbar (edit its .Frame property) when the keyboard pops up. I use this method to move an entire UIScrollView up. You can find the method I used here: (http://www.gooorack.com/2013/08/28/xamarin-moving-the-view-on-keyboard-show/).
This may not be the most "clean" solution, but if implemented correctly, it does its job. Another advantage is, is if you put the entire "moving of the keyboard" in a separate class-file, you can re-use it in other views.
Hope this helps. Good luck!
Love and regards,
Björn

Why is the leftButton (or rightButton) inside Titanium textField not showing?

I grappled with this for a while. Seems to be a semi bug.
If you add a leftButton or a rightButton to a textField like so:
var leftButton = Ti.UI.createButton({
image: 'someImage.png'
})
var textField = Ti.UI.createTextField({
leftButton: leftButton,
leftButtonMode: Ti.UI.INPUT_BUTTONMODE_ALWAYS,
leftButtonPadding: 100
})
...then you won't get to see your button. Why?
There might be 2 issues with this code.
1- Check image path you assigning to button .. ? (Height,width)
for test purpose try use any system button and see if its appear or not .?
var leftButton = Titanium.UI.createButton({
style:Titanium.UI.iPhone.SystemButton.DISCLOSURE
});
2- second issue might be with padding of left button
try to use it without padding and then see what happens.
var win = Titanium.UI.createWindow({
title:"Configuring text field and text area keyboard types",
backgroundColor:"#347AA9",
exitOnClose:true
});
//These buttons will appear within the text field
var clearButton = Titanium.UI.createButton({
title:"Clear",
height:24,
width:52
});
var submitButton = Titanium.UI.createButton({
title:"Submit",
height:24,
width:60
});
var textField = Titanium.UI.createTextField({
top:"25%",
height:35,
width:600,
backgroundColor:"#ffffff",
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
hintText:"Type something",
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
leftButton:clearButton,
rightButton:submitButton
});
clearButton.addEventListener("click", function(e){
//Clear the value of the text field
textField.value = "";
});
submitButton.addEventListener("click", function(e){
//Pretend to submit the value of the text field
//Be sure that you've typed something in!
if(textField.value != ""){
alert(textField.value);
}else{
alert("Enter some text");
}
});
//Add an event listener to the window that allows for the keyboard or input keys to be hidden if the user taps outside a text field
//Note: each text field to be blurred would be added below
win.addEventListener("click", function(e){
textField.blur(); // Cause the text field to lose focus, thereby hiding the keyboard (if visible)
});
win.add(textField);
win.open();
The problem is in the leftButtonMode property. Give it any value at all, and the button won't show. If you don't use this property, the button will show just fine.
The padding property is not a problem for leftButton. But if you use it on a rightButton, it will likely throw your button outside the screen. I've tried a negative value too, without success.
Be aware too that the leftButton and rightButton options don't work on Android.

Resources