Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add a tag to characters not yet typed

Status
Not open for further replies.

papageno

Technical User
Dec 25, 2004
24
0
0
ES
e.g. when the cursor is at the beginning of an empty line and you want to apply a tag to what you are going to type next.
 
Well, you would have to know something like the coordinates of the text you want to tag, whether or not the text is there yet. You would use the tag add function:
pathName tag add tagName index1 ?index2 index1 index2 ...?
Associate the tag tagName with all of the characters starting with index1 and ending just before index2 (the character at index2 isn't tagged). A single command may contain any number of index1-index2 pairs. If the last index2 is omitted then the single character at index1 is tagged. If there are no characters in the specified range (e.g. index1 is past the end of the file or index2 is less than or equal to index1) then the command has no effect.
probably using the line.char mode of index definition:
line.char
Indicates char'th character on line line. Lines are numbered from 1 for consistency with other UNIX programs that use this numbering scheme. Within a line, characters are numbered from 0. If char is end then it refers to the newline character that ends the line.

_________________
Bob Rashkin
 
Yes, but the problem is that the tag must be applied to the character before and the character after the cursor. And that's not possible at index 0.0.
 
That's 1.0 but I take your point.

_________________
Bob Rashkin
 
OK. Apparently the tags don't take when the text isn't there yet. I tried this:
Code:
% pack [text .t]
() 2 % .t tag add t1 1.0 1.8 [b];# now type 4 lines of text[/b]
() 3 % .t tag add t2 2.4 2.6
() 4 % .t tag configure t2 -foreground red[b];#<--this works[/b]
() 5 % .t tag configure t1 -foreground red[b];#<--this doesn't[/b]

Maybe it's time to examine what you're trying to do and whether it's necessary to tag the text a priori to do it.

_________________
Bob Rashkin
 
So, there's a button you push to apply format to characters in a text widget. No problem if the characters are already there, you select them and apply the tag to them. But if the cursor is at N.0 of a new (blank) line and you push the button to apply the tag to the text you are about to write, then the tag must "bridge over" the cursor.

The only solution I found was to insert an elided character at N.0 and then delete it once the tag has been applied.
 
Is there some reason you can only set the tags based on cursor position? Could you identify some other characteristic of the text you wish to tag?

_________________
Bob Rashkin
 
It's for a quite simple text editor with buttons for bold/italics/etc. I mention the cursor (insert) position because it's the text entered after that position that must be tagged. (Or that's my guess? Dunno.) But how would I go about it if, for example, no text at all has been typed yet but the user wants the text to be e.g. in bold or italics? I mean without having to first write the text and then select it.
 
Well, maybe the text editor you envision is not as simple as you think, at least not in Tcl. Changing the font characteristics for highlighted (i.e., selected) text is simple. Setting the mode for future text while not changing text entered before is not so simple. I can imagine doing something like this:
when the button is pressed, tag the text from the last tag to the cursor; set the font of the tagged text to whatever the previous state was; set the font of the text widget itself to what was pressed; carry on.

It doesn't seem worth the trouble to me, there being so many editors around already.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top