I have a virtual keyboard created in RealBasic.
When I press letters, numbers I append it to a textfield all its ok but, how do I delete characters from that textfield from current cursor position when I press "Delete" button from virtual keyboard?
To append letters or numbers to the textfields I use:
TextField1.Text = TextField1.text + me.Caption //to append caption
TextField1.SelStart = Len(TextField1.text) // to move cursor at the end of string
Paul's solution works if you only plan to delete the last typed character.
But beware: If you let the user also move the cursor left and right, you have to delete the text at the position of the cursor, of course. And if you also allow the user to select text, then it's even more complicated.
I suggest that your virtual keyboard simply send the typed key to the system as if the user had pressed the key. That way, the TextEdit field will do everything for you.
To make this work, however, you need custom solutions for each OS platform you want to support.
Let me know which platforms you plan to support and I'll see what I can find. I have some code for OSX but not for Windows, yet.
Doing what Thomas said means:
dim n as String = TextField1.Text
n = newText.left(TextField1.selStart) + n.right(n.len - textField1.selStart - 1)
textField1.text = n
Just lop off the last character:
TextField1.Text = TextField1.Text.Left(TextField1.Len-1)
Related
In my Sublime Text (v3), there seems to be some issue suddenly with selection. So assume I have the following code;
const testvar = '123';
Earlier, if I double clicked on either const Or testvar, it just selected that. However for some reason, it is now selecting both const & testvar
Earlier, if I had my cursor at the start of line and did Ctrl + Right arrow, it would take me to start of next word i.e. testvar. But now, it seems to be hoppinh over 2 words and cursor goes to =
Not sure if some setting got changed unintentionally.
I am hiding the character * by inserting GlyphProperty.null then calling setGlyphs(_:properties:characterIndexes:font:forGlyphRange:) inside layoutManager(_:shouldGenerateGlyphs:properties:characterIndexes:font:forGlyphRange:) as described in the answer in https://stackoverflow.com/a/57697139/9568961, it works but after a certain sequence of text editing, the cursor starts to misplace, as shown in the gif https://github.com/dzAtZJU/Demos/blob/master/cursor_misplace.GIF?raw=true
GIF Description: When the second line becomes qq, I try to move the cursor to the end of first line, but it move directly to the beginning. I then try to delete characters, then the cursor move to the end correctly.
The sample project is here https://github.com/dzAtZJU/HideText.
Is it a bug? Have anyone run into this? How can I work around this?
This is a year-old question, but for anyone struggling with the same problem, here's a solution.
My Markdown-like parser knows the ranges for both the line on which the cursor is now, and where it was previously. I'm calling hideAndShowMarkup whenever text view selection changes.
You need to invalidate current glyphs for both of the ranges, and then redraw them synchronously before updating insertion point. The most crucial step is invalidating layout for the range where you want to show Markdown symbols. Without that, your caret gets drawn into the wrong position.
Code is in Objective C, but should be easy to implement in Swift, too.
-(void)hideAndShowMarkup {
// Just for reference
Line* line = currentLine;
Line* prevLine = previouslySelectedLine;
[self.layoutManager invalidateGlyphsForCharacterRange:line.range changeInLength:0 actualCharacterRange:nil];
[self.layoutManager invalidateGlyphsForCharacterRange:prevLine.range changeInLength:0 actualCharacterRange:nil];
[self.layoutManager invalidateLayoutForCharacterRange:line.range actualCharacterRange:nil];
if (NSGraphicsContext.currentContext) {
[self.layoutManager drawGlyphsForGlyphRange:line.range atPoint:self.frame.origin];
[self.layoutManager drawGlyphsForGlyphRange:prevLine.range atPoint:self.frame.origin];
}
[self updateInsertionPointStateAndRestartTimer:NO];
}
I am implementing a simple MFC text editor and I have run into trouble with my find function. Specfically in my 'find box' dialog class I have the following code:
FINDTEXTEX ft;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = _T("wallaby");
long n = pmyRichEditCtrl->FindText(FR_MATCHCASE|FR_WHOLEWORD, &ft);
if (n != -1)
pmyRichEditCtrl->SetSel(ft.chrgText);
However, n is always -1 even when the word wallaby is typed into the control. Any help would be greatly appreciated.
It all depends where your current cursor selection is. If you typed the word then most likely your cursor will be positioned directly after the typed word. If you do not care about the position of the cursor then you can set the position to the beginning and start finding the text from the beginning:
pmyRichEditCtrl->SetSel( 0, 0 );
long n = pmyRichEditCtrl->FindText(FR_DOWN|FR_MATCHCASE|FR_WHOLEWORD, &ft);
Also, do not forget to set FR_DOWN parameter to search forward. If this parameter is not set it will search backward from FINDTEXTEX.chrg.cpMin:
Microsoft Rich Edit 2.0 and later: If set, the search is forward from
FINDTEXTEX.chrg.cpMin; if not set, the search is backward from
FINDTEXTEX.chrg.cpMin.
Microsoft Rich Edit 1.0: The FR_DOWN flag is ignored. The search is
always forward.
Basically,
It's inspired by Vim I want to use a key(e.g Alt, F1) combination(+I J K L) to map to Arrow Keys
What is already done in Autohotkey
Ralt & j::send{Left}
Ralt & k::send{Right}
...
Now I take Alt+I as up etc,which is pretty fine for me But the problem comes when you press
Ralt+Shift+j (Suppose to select the last charater)
Ralt+Ctrl+j (Suppose to move a caramel text)
These kind of combination would not work and it just get overrided to basic move cursor to left
Even if I use if/while statement with GetKeyState, it doesn't gonna work
if GetKeyState("Shift","P")
Ralt+j::send +{Left}
This kind of stuff didn't work
Any Ideas on that ?It would make coding very efficient without having to move the right hand.
Thanks in advance.
You are missing 2 things:
Must use a # symbol when doing a context sensitive hotkey
The bottom section of code is using a + instead of the & you used previously.
See the below modification:
RAlt & j:: Send {Left}
RAlt & k:: Send {Right}
#If GetKeyState("Shift","P")
RAlt & j:: Send +{Left}
RAlt & k:: Send +{Right}
; Close with #If to remove the context or simply start another '#If GetKeystate ....'
HRESULT hr;
TF_SELECTION tfSelection;
ULONG uFetched;
//Obtain the default selection.
hr = _pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &uFetched);
UINT ar=(UINT)uFetched;
if(SUCCEEDED(hr) && (uFetched > 0))
{
UINT ar=(UINT)uFetched;
//Work with the selection.
//Release the selection range object.
tfSelection.range->Release();
}
Hi all. I am implementing this code in the DoEditSession method. When I try to get the selection, I always get a value of 1 for uFetched. But the cursor position is not coming?
I am developing a text service for windows RT using Tsf interface. I
have integrated libraries that suggests words based on letters we type
in the candidate window. Now I need to get the letters before and
after the Cursor Position in the Document. So here I have
used GetSelection to retrieve the selected text. The problem is I am
not able to retrieve the caret position in the document (notepad). Is there any specific way in which i can get the letter/text around the caret/cursor position?
You can shift the start/end of the selection range without actually modifying the selection.