Case Sensitivity in AutoText
Friday, August 26, 2005
WebEdit's IntelliSense-like AutoText feature, provided by the Gregor.Editing project, supports case sensitivity in several different ways. In short, we need to distinguish:
- Allowing or disallowing tokens that differ in case only.
- Turning up matches against text typed with or without regard to case.
- Possibly pre-selecting a token in the popup list whose begin best matches the case of the text typed.
- When completing a word, correcting the case of the text typed.
The first attribute is handled by the CTokenList.IgnoreCase property, which by default is True. The actual filtering happings in the token list's associated IComparer, which by default is of type CTokenComparer, which chats back with the token list, evaluating its IgnoreCase property.
Providing matches works a little differently than it does in most IDEs. The auto-text object filters out any tokens that do not start with the text typed, so the list shrinks as the user types. Furthermore, if the CTokenList.IgnoreCaseWhenMatching property is False - its default value is True - tokens that differ in case are filtered out as well. The actual matching happens in the token list's associated IMatcher, which defaults to a CTokenMatcher, which again backreferences the token list. Having both IgnoreCase and IgnoreCaseWhenMatching as different properties allows for a number of options already. Note that setting IgnoreCase to False will increase the quantity of tokens generally available, whereas setting IgnoreCaseWhenMatching to False will decrease the number of tokens that are matched up against text typed.
The third aspect is not a configurable property, but at least in part a consequence of the aforesaid. Since tokens that don't match at all are filtered out, until now auto-text was content to always select the first token in the popup list. But from now on, when two or more tokens (with or without regard to case, depending) start with the text typed so far - in other words, if the popup list has more than one choice left - the case of the text typed is considered when setting the selection in the list. The logic is in the private CAutoText.UpdateList() method. For example, if the list contains the strings "fAlways" and "FavoritesDialog" (in that order), and the user has typed "F" (and popped up the list with say, Ctrl+Space), the second item will be selected - because setting the selection always tries to regard case. This feature typically saves a few keystrokes for those who prudently mind case when typing.
Finally, when the user chooses to complete a token, for example, by typing a separator character, the case of the text typed so far is corrected to the case of the whatever token is selected for whatever reason in the popup list - if the CAutoText.CorrectCase property is True (it's False by default).
The default values discussed so far are library defaults (that is, of the classes in Gregor.Editing). WebEdit.NET, on the other hand, sets the IgnoreCase properties of all its token lists to False by default (you can change that with a setting - see the "Editing" settings group), leaves the IgnoreCaseWhenMatching property of all token lists True, and sets CAutoText.CorrectCase to True (you can change on a per-editor-window basis with a toolbar button).