read text at cursor position in JFace TextViewer - eclipse

I have an editor that extends a TextEditor class. I would like to know if it is possible to read the text at the cursor position within the editor.
Using ITextSelection is not useful since it expects that some text string is selected. I require to read text when the cursor is at some point and no text is selected.
Thanks.

ITextViewer.getSelectedRange(). It will return the offset and the size of the selection. Offset is the caret position and size may be 0. To read the text, use ITextViewer.getDocument().get() and analyze the contents at the respective offset.

Related

How to set position label text in TextFormField in outlineborder?

How to set position label in TextFormField in outlineborder?
i want set text position. Because, label prefer to bottom not center in border
According to the documentation for the label
Text that describes the input field.
When the input field is empty and unfocused, the label is displayed on
top of the input field (i.e., at the same location on the screen where
text may be entered in the input field). When the input field receives
focus (or if the field is non-empty), the label moves above (i.e.,
vertically adjacent to) the input field.
So, basically this is the behavior for the label. If you want something else you have to make it on your own ( using a Stack widget with a TextField and a Text ). But with this solution you have to treat the focus properties as well on your own.
You can use this post as a reference
https://stackoverflow.com/a/58039585/10143503

TextField's current focus position in flutter

Hey I have a TextField and a controller for it through which I access its current text value and add some text like (Some Special Asterix or text with angular brackets just like hashnode's text editor) to it when needed, adding text at the end is easy.
controller.text += "Something";
The above code will add Something to the end. But I need to know the current TextFields Cursor position and add text according to it.
I really love to know how we can do it in flutter efficiently
Try this to get the cursor position
print(controller.selection.baseOffset);
print(controller.selection.extentOffset);
if they are the same, it is current cursor position.
if not, it means that some of text is selected, baseOffset is start position and extentOffset is end positon.

Word 2010: expand a control to fill its table cell

I have a table cell of fixed large size, and in it is nothing but a Plain Text Content Control, whose default placeholder text "Click here to enter text" takes up only a small portion of that table cell.
The problem is that if the user clicks anywhere in the cell but outside of the control's placeholder text, then starts typing, the entered text will not be part of the control and will not be subject to the control's style or any other control properties.
So - other than adding a lot of dummy characters to the placeholder text, which doesn't seem to be predictable in its word-wrap behavior, is there a way to make the control's placeholder text (or, in general, its click-boundary) fill the entire table cell?
UPDATE actually there were some carriage returns after the control that I was not aware of; after deleting those, clicking anywhere in the cell as long as the x coordinate if the click is greater than or equal to the leftmost x coordinate of the control will edit the control text value as desired. If you click leftward of the control, you will end up editing whatever fixed text exists to the left of the control, i.e. a fixed text label. Still strange. The workaround here was to split cells for all multi line text entry areas, such that the label is on its own cell, and the control is now at the leftmost edge of its cell.
Content controls do not support something like expanding to the surrounding container. They will always use only the space that is required to render their content.
If you want to prevent users from clicking and typing text outside of the control, you could use the following approach:
Put a rich text content control around your table/table row/cell
Put the plain text content control as a nested content control in the table cell (the plain text content control must be non-vanishing for this to work)
Make the outer content control read-only
Now the only thing the user is allowed to edit is the inner plain text content control. The downside of this approach is that your document now contains areas that are locked. This has an impact on usability, first, because, it may not be obvious to the user why certain areas cannot be modified, and second, because a lot of standard actions do no longer work if part of the selection is locked (e.g. Select All > Update ToC).

Moving cursor position by offset value

$text->SetCursor( position );
This is used to move cursor at the given position.
Is there any way that I can move the cursor by a given offset value?
Thanks,
You just have to use the correct position descriptor; they support a little language of their own. For example, the string insert + 1 char describes the location one character further on than the insertion point (insert is a special kind of mark that represents where text will be inserted and is where the caret is located when focus is in the text widget).

How to figure out the current caret position in a UITextField?

I want to programmatically paste a string into a text field or text view at the current caret position.
Is there an easy way to do this? I would need to know the current caret position, but there's no method to retrieve it, right? Don't want to call private API. Is there any legal way to do it?
Use UITextView's selectedRange method. If the range has a non-zero length (in the case of the user having selected some text), just take the location (or NSMaxRange(), or replace the entire range...)
Instead of pasting option. Get the string from textfield or textview insert the string which you want to paste it by providing the index and then clear the textfield then pass the string which you inserted.