Text Entry

Blitz3D Forums/Blitz3D Beginners Area/Text Entry

_PJ_(Posted 2010) [#1]
I had a text entry routine in another project and I have been trying to make it less specific and more 'portable'.

However, Ive broken it somewhere and I can't understand where...
The cursor always moves BACKWARDS on Ascii input or backspace, whilst the cursors etc. and Delete still work correctly.

Can anyone see what's wrong here?

Here's the crucial parts of the code, with comments, placed in a runnable example




BoneStan(Posted 2010) [#2]
The txt_TextString$ begun with the left part of the string.
But now works Delete incorrect.

Function txt_InsertTextAtCursor$(txt_TextString$,txt_sText$="",txt_ModifyPre=0,txt_ModifySuf=0)
	Local txt_sTextPrefix$=Left(txt_TextString,(txt_Current_TextCursor-txt_ModifyPre))
	Local txt_sTextSuffix$=Right(txt_TextString,Len(txt_TextString)-(txt_Current_TextCursor+txt_ModifySuf))

	;The cursor always moves BACKWARDS, Delete still work correctly.
	;txt_TextString$=txt_sTextPrefix+txt_sText+txt_sTextSuffix
	
;The cursor moves forwards but delete begins from the left position.
txt_TextString$=txt_sTextSuffix+txt_sText+txt_sTextPrefix
	
	Return txt_TextString$
End Function



_PJ_(Posted 2010) [#3]
Exchanging True/False should fix that, however it seems like a 'kludge' rather than a fix.

Not that I'm ungrateful, Stan, I do appreciate your help, but I am still interested to know what's wrong with the code and how to fix it properly.


Midimaster(Posted 2010) [#4]
I think it it missing a

txt_Current_TextCursor=txt_Current_TextCursor+1


in the case, when a new real ASCII-character is added to the string, or? The string gets longer and the cursor should be behind the new sign afterwards.


If (txt_ASCII>32) And txt_ASCII<127)
   Local txt_sText$=Chr$(txt_ASCII)
      If (KeyDown(42) Or KeyDown(54))
         If ((txt_ASCII>96 And txt_ASCII<122)) Then
            txt_sText$=Upper$(txt_sText$)
		 End If
         txt_EnteredText$=txt_InsertTextAtCursor(txt_EnteredText$,txt_sText$)
         txt_Current_TextCursor=txt_Current_TextCursor+1
         Return
      End If
....	



But you have a second problem. the BACKSPACE is not working correct in your sample!