Transform Text

Posted by Emmanuel ® , 09/14/2022, 10:36:01 Reply   Forum

What is the best practice when creating an Instant Text entry that transforms text?

To elaborate on this topic, we will create a simple Instant Text entry that uppercases text.

Let us distinguish the cases where the text to transform is:

  • already selected
  • not yet selected

1. Text to Transform Is Already Selected

1.1. Typing a short form is a no go. It destroys the selection!

Typing a short form while the text to transform is already selected is not an option because it overrides the selection. To see it yourself, create an entry using the Upper Case command:

Short Expansion

uc

{UpperCase}{NoSpacing}

Expand that entry to uppercase the selected words united states:

You will see that typing uc; overrides the selection before the UpperCase command has a chance to do its job.

1.2. Creating a hotkey

To circumvent the fact that typing a short form overrides the selection, create a Hotkey Glossary Entry instead:

Short Expansion

Ctrl U

{UpperCase}{NoSpacing}

Typing Ctrl U does not override the selection which allows the UpperCase command to do its job.

2. Text to Transform Is Not Yet Selected

2.1. Add selection commands inside your entry

With no selection yet, we need to insert keyboard commands to establish the selection before the UpperCase command. The following entries are designed to uppercase 1, 2 or 3 words to the left of the cursor:

Short Expansion

uc1

{Ctrl Shift Left 1}{UpperCase}{NoSpacing}

uc2

{Ctrl Shift Left 2}{UpperCase}{NoSpacing}

uc3

{Ctrl Shift Left 3}{UpperCase}{NoSpacing}

The drawback of this approach is that you need different expansions for different selections.

2.2. Stop (to allow selection) & Resume (with transformation)

A subtle trick is to insert a Stop command before the UpperCase command:

Short Expansion

uc

{Stop}{UpperCase}{NoSpacing}

Expanding this entry allows you to uppercase the text in 2 steps.

  1. It stops immediately, letting you the time to select whatever text portion you want to uppercase next.
  2. Once you have made your selection, you resume the expansion by pressing your Resume Hotkey F8. Being a hotkey F8 does not override the selection which allows the UpperCase command to do its job.

3. Best Practice

We consider the expansion using Stop & Resume (see 2.2.) to be the best practice.

  • Only one entry is required regardless of the number of words to transform.
  • You can type a short form to expand and don't need to dedicate a hotkey.

If you do a lot of editing, you will probably create a lot of valuable Instant Text entries that transform text. All these entries can be built on the same model as the entry to uppercase text. A good exercice to test your understanding could be to create an entry that "title cases" text, for example.




Edit | Reply | | | |   | Current page | Author