What is an easy way to switch back to normal style?
User inserted a hyperlink. Then he enters some new text exactly behind the last Char of the hyperlink. In this case the hyperlink style is extended for the new input. If the link was the last text in editor window unfortunately he is unable to go back to standard style but for copying and pasting some 0-style-text from somewhere else.
How do you recommend to switch automatically back to standard style (e.g. 0) if the one enters something as space or new line?
Thank you
Automatically switch back behind hyperlink
Seems to be a lot easyer then I thougt?
works with fixed styles:
But how can I detect the hyperlink style with variable styles?
works with fixed styles:
Code: Select all
procedure TfMain.rvKeyPress(Sender: TObject; var Key: Char);
begin
if (rv.GetItemStyle(rv.CurItemNo) = 19) and (not(Key in ['-'..'9', 'A'..'Z', 'a'..'z', '_',]) or (Ord(Key) = 13)) then
rv.ApplyTextStyle(0);
end;
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
The idea is correct - a hyperlink should be terminated when the user typed a character at the end of a hyperlink (but not in the middle).
This code may work in conjunction with URL detection on typing.
Demo:
Demos\DelphiUnicode\Assorted\Hyperlink\CreateHyperlink\
Terminates hyperlink when the user presses space, tab or enter. See TerminateHyperlink procedure. The demo implements GetNonHypertextStyleNo returning a non-hypertext text style by the given hypertext style (the same properties but black, not underlined, Jump=False)
Demo:
Demos\DelphiUnicode\Assorted\Hyperlink\URLs\
This demo has a ready-to use ScanURLs.pas unit, you can include and use it in your applications.
Among other useful functions, it has TerminateHyperlink. Like in this demo, you should provide a function returning a non-hypertext text style by the given hypertext style.
This demo has more interesting functions:
- DetectURL detects URL on typing
- processing OnItemTextEdit (rveItemTextEdit procedure); it updates the text tag when URL is modified, and remove hyperlink if the current text is not hyperlink any more (for example, if you press a character inside 'http://'.
In this demo, TerminateHyperlink can terminate it even when a character is pressed in the middle of a link. It works good because it works with conjunction with URL detection and OnItemTextEdit.
RichViewActions:
TrvActionInsertHyperlink has the methods DetectURL and TerminateHyperlink.
Advantages of RichViewActions:
- ready-to-use, you do not need to write code converting hypertext style to non-hypertext and vice verse
- the actions support UseStyleTemplates mode, where converting to and from hypertext is completely different ("hyperlink" style template must be either applied or removed)
- URL bounds are determined in more smart way
This code may work in conjunction with URL detection on typing.
Demo:
Demos\DelphiUnicode\Assorted\Hyperlink\CreateHyperlink\
Terminates hyperlink when the user presses space, tab or enter. See TerminateHyperlink procedure. The demo implements GetNonHypertextStyleNo returning a non-hypertext text style by the given hypertext style (the same properties but black, not underlined, Jump=False)
Demo:
Demos\DelphiUnicode\Assorted\Hyperlink\URLs\
This demo has a ready-to use ScanURLs.pas unit, you can include and use it in your applications.
Among other useful functions, it has TerminateHyperlink. Like in this demo, you should provide a function returning a non-hypertext text style by the given hypertext style.
This demo has more interesting functions:
- DetectURL detects URL on typing
- processing OnItemTextEdit (rveItemTextEdit procedure); it updates the text tag when URL is modified, and remove hyperlink if the current text is not hyperlink any more (for example, if you press a character inside 'http://'.
In this demo, TerminateHyperlink can terminate it even when a character is pressed in the middle of a link. It works good because it works with conjunction with URL detection and OnItemTextEdit.
RichViewActions:
TrvActionInsertHyperlink has the methods DetectURL and TerminateHyperlink.
Advantages of RichViewActions:
- ready-to-use, you do not need to write code converting hypertext style to non-hypertext and vice verse
- the actions support UseStyleTemplates mode, where converting to and from hypertext is completely different ("hyperlink" style template must be either applied or removed)
- URL bounds are determined in more smart way